diff options
author | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-07-21 14:32:03 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2021-07-21 14:36:02 +0100 |
commit | 6b86da53d5ee2022b9065f445d23356190380746 (patch) | |
tree | 30672413b66483f04b1d54399cae642ae651eccc /ld | |
parent | 8f5d31b8d1f80fd9fff4cef4acc4491a0d83fbed (diff) | |
download | gdb-6b86da53d5ee2022b9065f445d23356190380746.zip gdb-6b86da53d5ee2022b9065f445d23356190380746.tar.gz gdb-6b86da53d5ee2022b9065f445d23356190380746.tar.bz2 |
Allows linker scripts to set the SEC_READONLY flag.
* ld.texi: Document new output section type.
* ldgram.y: Add new token.
* ldlang.c: Handle the new flag.
* ldlang.h: Add readonly_section to list of section types.
* ldlex.l: Add a new identifier.
* testsuite/ld-scripts/output-section-types.t: New example linker script.
* testsuite/ld-scripts/output-section-types.d: Test driver.
* testsyute/ld-scripts/script.exp: Run the new test.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ld.texi | 2 | ||||
-rw-r--r-- | ld/ldgram.y | 2 | ||||
-rw-r--r-- | ld/ldlang.c | 6 | ||||
-rw-r--r-- | ld/ldlang.h | 3 | ||||
-rw-r--r-- | ld/ldlex.l | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/output-section-types.d | 13 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/output-section-types.t | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/script.exp | 1 |
8 files changed, 34 insertions, 1 deletions
@@ -5474,6 +5474,8 @@ parentheses. The following types are defined: @item NOLOAD The section should be marked as not loadable, so that it will not be loaded into memory when the program is run. +@item READONLY +The section should be marked as read-only. @item DSECT @itemx COPY @itemx INFO diff --git a/ld/ldgram.y b/ld/ldgram.y index dd911f4..31e0071 100644 --- a/ld/ldgram.y +++ b/ld/ldgram.y @@ -139,6 +139,7 @@ static int error_index; %token REGION_ALIAS %token LD_FEATURE %token NOLOAD DSECT COPY INFO OVERLAY +%token READONLY %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY %token <integer> NEXT %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K @@ -1123,6 +1124,7 @@ type: | COPY { sectype = noalloc_section; } | INFO { sectype = noalloc_section; } | OVERLAY { sectype = noalloc_section; } + | READONLY { sectype = readonly_section; } ; atype: diff --git a/ld/ldlang.c b/ld/ldlang.c index 37b64c8..2610be9 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -2639,6 +2639,9 @@ lang_add_section (lang_statement_list_type *ptr, case noalloc_section: flags &= ~SEC_ALLOC; break; + case readonly_section: + flags |= SEC_READONLY; + break; case noload_section: flags &= ~SEC_LOAD; flags |= SEC_NEVER_LOAD; @@ -4232,6 +4235,9 @@ map_input_to_output_sections case noalloc_section: flags = SEC_HAS_CONTENTS; break; + case readonly_section: + flags |= SEC_READONLY; + break; case noload_section: if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour) diff --git a/ld/ldlang.h b/ld/ldlang.h index 6fbe16d..f68ae27 100644 --- a/ld/ldlang.h +++ b/ld/ldlang.h @@ -121,7 +121,8 @@ enum section_type first_overlay_section, overlay_section, noload_section, - noalloc_section + noalloc_section, + readonly_section }; /* This structure holds a list of program headers describing @@ -294,6 +294,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)* <BOTH,SCRIPT>"SORT_BY_INIT_PRIORITY" { RTOKEN(SORT_BY_INIT_PRIORITY); } <BOTH,SCRIPT>"SORT_NONE" { RTOKEN(SORT_NONE); } <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);} +<EXPRESSION,BOTH,SCRIPT>"READONLY" { RTOKEN(READONLY);} <EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);} <EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);} <EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);} diff --git a/ld/testsuite/ld-scripts/output-section-types.d b/ld/testsuite/ld-scripts/output-section-types.d new file mode 100644 index 0000000..ab124fa --- /dev/null +++ b/ld/testsuite/ld-scripts/output-section-types.d @@ -0,0 +1,13 @@ +#ld: -Toutput-section-types.t +#source: align2a.s +#objdump: -h +#target: [is_elf_format] + +#... + . \.rom.* +[ ]+ALLOC, READONLY + . \.ro.* +[ ]+CONTENTS, ALLOC, LOAD, READONLY, DATA + . \.over.* +[ ]+CONTENTS, READONLY +#pass diff --git a/ld/testsuite/ld-scripts/output-section-types.t b/ld/testsuite/ld-scripts/output-section-types.t new file mode 100644 index 0000000..d8fdfda --- /dev/null +++ b/ld/testsuite/ld-scripts/output-section-types.t @@ -0,0 +1,7 @@ +SECTIONS { + .rom (NOLOAD) : { LONG(1234); } + .ro (READONLY) : { LONG(5678); } + .over (OVERLAY) : { LONG(0123); } + /DISCARD/ : { *(*) } + +} diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp index 961cd08..ff50199 100644 --- a/ld/testsuite/ld-scripts/script.exp +++ b/ld/testsuite/ld-scripts/script.exp @@ -229,6 +229,7 @@ foreach test_script $test_script_list { run_dump_test "align-with-input" run_dump_test "pr20302" +run_dump_test "output-section-types" run_dump_test "segment-start" {{name (default)}} run_dump_test "segment-start" {{name (overridden)} \ |