From c212f39d9a82c6c09f4a1447d9d2ff09843827c5 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 16 Feb 2022 17:41:23 +0000 Subject: ld: Support customized output section type bfd/ PR ld/28841 * bfd-in2.h (struct bfd_section): Add type. (discarded_section): Add field. * elf.c (elf_fake_sections): Handle bfd_section::type. * section.c (BFD_FAKE_SECTION): Add field. * mri.c (mri_draw_tree): Update function call. ld/ PR ld/28841 * ld.texi: Document new output section type. * ldlex.l: Add new token TYPE. * ldgram.y: Handle TYPE=exp. * ldlang.h: Add type_section to list of section types. * ldlang.c (lang_add_section): Handle type_section. (map_input_to_output_sections): Handle type_section. * testsuite/ld-scripts/output-section-types.t: Add tests. * testsuite/ld-scripts/output-section-types.d: Update. --- ld/ldgram.y | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ld/ldgram.y') diff --git a/ld/ldgram.y b/ld/ldgram.y index 11c2f21..3a904e3 100644 --- a/ld/ldgram.y +++ b/ld/ldgram.y @@ -47,6 +47,7 @@ #endif static enum section_type sectype; +static etree_type *sectype_value; static lang_memory_region_type *region; static bool ldgram_had_keep = false; @@ -139,6 +140,7 @@ static int error_index; %token LD_FEATURE %token NOLOAD DSECT COPY INFO OVERLAY %token READONLY +%token TYPE %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY %token NEXT %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K @@ -1058,9 +1060,8 @@ section: NAME { ldlex_popstate (); ldlex_wild (); - lang_enter_output_section_statement($1, $3, sectype, - $5, $7, $4, - $8, $6); + lang_enter_output_section_statement ($1, $3, sectype, + sectype_value, $5, $7, $4, $8, $6); } '{' statement_list_opt @@ -1130,8 +1131,10 @@ type: | COPY { sectype = noalloc_section; } | INFO { sectype = noalloc_section; } | OVERLAY { sectype = noalloc_section; } + | READONLY '(' TYPE '=' exp ')' { sectype = typed_readonly_section; sectype_value = $5; } | READONLY { sectype = readonly_section; } - ; + | TYPE '=' exp { sectype = type_section; sectype_value = $3; } + ; atype: '(' type ')' -- cgit v1.1