GNU Binutils with patches for OS216
Revision | c005eb9e34ac08be0cd40e19a741d345bd43eab9 (tree) |
---|---|
Zeit | 2015-09-05 06:30:55 |
Autor | Andrew Burgess <andrew.burgess@embe...> |
Commiter | Andrew Burgess |
ld: Extend options for altering orphan handling behaviour.
Replace the options --warn-orphan and --no-warn-orphan with a single
option --orphan-handling=MODE, where mode can be place, warn, error, and
discard.
Mode 'place' is the default, and is the current behaviour, placing the
orphan section into a suitable output section.
Mode 'warn' is the same as '--warn-orphan'. The orphan is also placed
using the same algorithm as for 'place'.
Mode 'error' is the same as '--warn-orphan' and '--fatal-warnings'.
Mode 'discard' assigns all output sections to the /DISCARD/ section.
ld/ChangeLog:
* ld.h (enum orphan_handling_enum): New.
(ld_config_type): Remove warn_orphan, add orphan_handling.
* ldemul.c (ldemul_place_orphan): Remove warning about orphan
sections.
* ldlang.c (ldlang_place_orphan): New function.
(lang_place_orphans): Call ldlang_place_orphan.
* ldlex.h (enum option_values): Remove OPTION_WARN_ORPHAN and
OPTION_NO_WARN_ORPHAN, add OPTION_ORPHAN_HANDLING.
* lexsup.c (ld_options): Remove 'warn-orphan' and
'no-warn-orphan', add 'orphan-handling'.
(parse_args): Remove handling for OPTION_WARN_ORPHAN and
OPTION_NO_WARN_ORPHAN, add handling for OPTION_ORPHAN_HANDLING.
* NEWS: Replace text about --warn-orphan with --orphan-handling.
* ld.texinfo (Options): Remove --warn-orphan entry and add
entry on --orphan-handling.
(Orphan Sections): Add reference to relevant command line options.
ld/testsuite/ChangeLog:
* ld-elf/elf.exp: Switch to rely on run_dump_test.
* ld-elf/orphan-5.l: Update expected output.
* ld-elf/orphan-5.d: New file.
* ld-elf/orphan-6.d: New file.
* ld-elf/orphan-6.l: New file.
* ld-elf/orphan-7.d: New file.
* ld-elf/orphan-7.map: New file.
* ld-elf/orphan-8.d: New file.
* ld-elf/orphan-8.map: New file.
@@ -1,3 +1,22 @@ | ||
1 | +2015-07-28 Andrew Burgess <andrew.burgess@embecosm.com> | |
2 | + | |
3 | + * ld.h (enum orphan_handling_enum): New. | |
4 | + (ld_config_type): Remove warn_orphan, add orphan_handling. | |
5 | + * ldemul.c (ldemul_place_orphan): Remove warning about orphan | |
6 | + sections. | |
7 | + * ldlang.c (ldlang_place_orphan): New function. | |
8 | + (lang_place_orphans): Call ldlang_place_orphan. | |
9 | + * ldlex.h (enum option_values): Remove OPTION_WARN_ORPHAN and | |
10 | + OPTION_NO_WARN_ORPHAN, add OPTION_ORPHAN_HANDLING. | |
11 | + * lexsup.c (ld_options): Remove 'warn-orphan' and | |
12 | + 'no-warn-orphan', add 'orphan-handling'. | |
13 | + (parse_args): Remove handling for OPTION_WARN_ORPHAN and | |
14 | + OPTION_NO_WARN_ORPHAN, add handling for OPTION_ORPHAN_HANDLING. | |
15 | + * NEWS: Replace text about --warn-orphan with --orphan-handling. | |
16 | + * ld.texinfo (Options): Remove --warn-orphan entry and add | |
17 | + entry on --orphan-handling. | |
18 | + (Orphan Sections): Add reference to relevant command line options. | |
19 | + | |
1 | 20 | 2015-09-03 Nick Clifton <nickc@redhat.com> |
2 | 21 | |
3 | 22 | * ld.texinfo (--build-id): Fix typo. The COFF/PE build-id section |
@@ -6,7 +6,11 @@ | ||
6 | 6 | * New command line option for ELF targets to compress DWARF debug |
7 | 7 | sections, --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]. |
8 | 8 | |
9 | -* Add --warn-orphan option to report orphan sections. | |
9 | +* New command line option, --orphan-handling=[place|warn|error|discard], to | |
10 | + adjust how orphan sections are handled. The default is 'place' which gives | |
11 | + the current behaviour, 'warn' and 'error' issue a warning or error | |
12 | + respectively when orphan sections are found, and 'discard' will discard all | |
13 | + orphan sections. | |
10 | 14 | |
11 | 15 | * Add support for LLVM plugin. |
12 | 16 |
@@ -207,6 +207,25 @@ extern args_type command_line; | ||
207 | 207 | |
208 | 208 | typedef int token_code_type; |
209 | 209 | |
210 | +/* Different ways we can handle orphan sections. */ | |
211 | + | |
212 | +enum orphan_handling_enum { | |
213 | + /* The classic strategy, find a suitable section to place the orphan | |
214 | + into. */ | |
215 | + orphan_handling_place = 0, | |
216 | + | |
217 | + /* Discard any orphan sections as though they were assign to the section | |
218 | + /DISCARD/. */ | |
219 | + orphan_handling_discard, | |
220 | + | |
221 | + /* Find somewhere to place the orphan section, as with | |
222 | + ORPHAN_HANDLING_PLACE, but also issue a warning. */ | |
223 | + orphan_handling_warn, | |
224 | + | |
225 | + /* Issue a fatal error if any orphan sections are found. */ | |
226 | + orphan_handling_error, | |
227 | +}; | |
228 | + | |
210 | 229 | typedef struct { |
211 | 230 | bfd_boolean magic_demand_paged; |
212 | 231 | bfd_boolean make_executable; |
@@ -229,8 +248,8 @@ typedef struct { | ||
229 | 248 | /* If TRUE, only warn once about a particular undefined symbol. */ |
230 | 249 | bfd_boolean warn_once; |
231 | 250 | |
232 | - /* If TRUE, issue warning messages when orphan sections are encountered. */ | |
233 | - bfd_boolean warn_orphan; | |
251 | + /* How should we deal with orphan sections. */ | |
252 | + enum orphan_handling_enum orphan_handling; | |
234 | 253 | |
235 | 254 | /* If TRUE, warn if multiple global-pointers are needed (Alpha |
236 | 255 | only). */ |
@@ -1001,6 +1001,35 @@ with @samp{-Ur}; once the constructor table has been built, it cannot | ||
1001 | 1001 | be added to. Use @samp{-Ur} only for the last partial link, and |
1002 | 1002 | @samp{-r} for the others. |
1003 | 1003 | |
1004 | +@kindex --orphan-handling=@var{MODE} | |
1005 | +@cindex orphan sections | |
1006 | +@cindex sections, orphan | |
1007 | +@item --orphan-handling=@var{MODE} | |
1008 | +Control how orphan sections are handled. An orphan section is one not | |
1009 | +specifically mentioned in a linker script. @xref{Orphan Sections}. | |
1010 | + | |
1011 | +@var{MODE} can have any of the following values: | |
1012 | + | |
1013 | +@table @code | |
1014 | +@item place | |
1015 | +Orphan sections are placed into a suitable output section following | |
1016 | +the strategy described in @ref{Orphan Sections}. The option | |
1017 | +@samp{--unique} also effects how sections are placed. | |
1018 | + | |
1019 | +@item discard | |
1020 | +All orphan sections are discarded, by placing them in the | |
1021 | +@samp{/DISCARD/} section (@pxref{Output Section Discarding}). | |
1022 | + | |
1023 | +@item warn | |
1024 | +The linker will place the orphan section as for @code{place} and also | |
1025 | +issue a warning. | |
1026 | + | |
1027 | +@item error | |
1028 | +The linker will exit with an error if any orphan section is found. | |
1029 | +@end table | |
1030 | + | |
1031 | +The default if @samp{--orphan-handling} is not given is @code{place}. | |
1032 | + | |
1004 | 1033 | @kindex --unique[=@var{SECTION}] |
1005 | 1034 | @item --unique[=@var{SECTION}] |
1006 | 1035 | Creates a separate output section for every input section matching |
@@ -2105,17 +2134,6 @@ option causes a warning to be issued whenever this case occurs. | ||
2105 | 2134 | Only warn once for each undefined symbol, rather than once per module |
2106 | 2135 | which refers to it. |
2107 | 2136 | |
2108 | -@kindex --warn-orphan | |
2109 | -@kindex --no-warn-orphan | |
2110 | -@cindex warnings, on orphan sections | |
2111 | -@cindex orphan sections, warnings on | |
2112 | -@item --warn-orphan | |
2113 | -The @option{--warn-orphan} option tells the linker to generate a | |
2114 | -warning message whenever it has to place an orphan section into the | |
2115 | -output file. @xref{Orphan Sections}. The @option{--no-warn-orphan} | |
2116 | -option restores the default behaviour of just silently placing these | |
2117 | -sections. | |
2118 | - | |
2119 | 2137 | @kindex --warn-section-align |
2120 | 2138 | @cindex warnings, on section alignment |
2121 | 2139 | @cindex section alignment, warnings on |
@@ -5569,6 +5587,10 @@ at the end of the file. | ||
5569 | 5587 | For ELF targets, the attribute of the section includes section type as |
5570 | 5588 | well as section flag. |
5571 | 5589 | |
5590 | +The command line options @samp{--orphan-handling} and @samp{--unique} | |
5591 | +(@pxref{Options,,Command Line Options}) can be used to control which | |
5592 | +output sections an orphan is placed in. | |
5593 | + | |
5572 | 5594 | If an orphaned section's name is representable as a C identifier then |
5573 | 5595 | the linker will automatically @pxref{PROVIDE} two symbols: |
5574 | 5596 | __start_SECNAME and __stop_SECNAME, where SECNAME is the name of the |
@@ -120,10 +120,6 @@ ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search, | ||
120 | 120 | lang_output_section_statement_type * |
121 | 121 | ldemul_place_orphan (asection *s, const char *name, int constraint) |
122 | 122 | { |
123 | - if (config.warn_orphan) | |
124 | - einfo (_("%P: Warning: input section '%s' from file '%B' is not mentioned in linker script\n"), | |
125 | - name, s->owner); | |
126 | - | |
127 | 123 | if (ld_emulation->place_orphan) |
128 | 124 | return (*ld_emulation->place_orphan) (s, name, constraint); |
129 | 125 | return NULL; |
@@ -6102,6 +6102,55 @@ lang_one_common (struct bfd_link_hash_entry *h, void *info) | ||
6102 | 6102 | return TRUE; |
6103 | 6103 | } |
6104 | 6104 | |
6105 | +/* Handle a single orphan section S, placing the orphan into an appropriate | |
6106 | + output section. The effects of the --orphan-handling command line | |
6107 | + option are handled here. */ | |
6108 | + | |
6109 | +static void | |
6110 | +ldlang_place_orphan (asection *s) | |
6111 | +{ | |
6112 | + if (config.orphan_handling == orphan_handling_discard) | |
6113 | + { | |
6114 | + lang_output_section_statement_type *os; | |
6115 | + os = lang_output_section_statement_lookup (DISCARD_SECTION_NAME, 0, | |
6116 | + TRUE); | |
6117 | + if (os->addr_tree == NULL | |
6118 | + && (bfd_link_relocatable (&link_info) | |
6119 | + || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) | |
6120 | + os->addr_tree = exp_intop (0); | |
6121 | + lang_add_section (&os->children, s, NULL, os); | |
6122 | + } | |
6123 | + else | |
6124 | + { | |
6125 | + lang_output_section_statement_type *os; | |
6126 | + const char *name = s->name; | |
6127 | + int constraint = 0; | |
6128 | + | |
6129 | + if (config.orphan_handling == orphan_handling_error) | |
6130 | + einfo ("%X%P: error: unplaced orphan section `%A' from `%B'.\n", | |
6131 | + s, s->owner); | |
6132 | + | |
6133 | + if (config.unique_orphan_sections || unique_section_p (s, NULL)) | |
6134 | + constraint = SPECIAL; | |
6135 | + | |
6136 | + os = ldemul_place_orphan (s, name, constraint); | |
6137 | + if (os == NULL) | |
6138 | + { | |
6139 | + os = lang_output_section_statement_lookup (name, constraint, TRUE); | |
6140 | + if (os->addr_tree == NULL | |
6141 | + && (bfd_link_relocatable (&link_info) | |
6142 | + || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) | |
6143 | + os->addr_tree = exp_intop (0); | |
6144 | + lang_add_section (&os->children, s, NULL, os); | |
6145 | + } | |
6146 | + | |
6147 | + if (config.orphan_handling == orphan_handling_warn) | |
6148 | + einfo ("%P: warning: orphan section `%A' from `%B' being " | |
6149 | + "placed in section `%s'.\n", | |
6150 | + s, s->owner, os->name); | |
6151 | + } | |
6152 | +} | |
6153 | + | |
6105 | 6154 | /* Run through the input files and ensure that every input section has |
6106 | 6155 | somewhere to go. If one is found without a destination then create |
6107 | 6156 | an input request and place it into the statement tree. */ |
@@ -6141,27 +6190,7 @@ lang_place_orphans (void) | ||
6141 | 6190 | } |
6142 | 6191 | } |
6143 | 6192 | else |
6144 | - { | |
6145 | - const char *name = s->name; | |
6146 | - int constraint = 0; | |
6147 | - | |
6148 | - if (config.unique_orphan_sections | |
6149 | - || unique_section_p (s, NULL)) | |
6150 | - constraint = SPECIAL; | |
6151 | - | |
6152 | - if (!ldemul_place_orphan (s, name, constraint)) | |
6153 | - { | |
6154 | - lang_output_section_statement_type *os; | |
6155 | - os = lang_output_section_statement_lookup (name, | |
6156 | - constraint, | |
6157 | - TRUE); | |
6158 | - if (os->addr_tree == NULL | |
6159 | - && (bfd_link_relocatable (&link_info) | |
6160 | - || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)) | |
6161 | - os->addr_tree = exp_intop (0); | |
6162 | - lang_add_section (&os->children, s, NULL, os); | |
6163 | - } | |
6164 | - } | |
6193 | + ldlang_place_orphan (s); | |
6165 | 6194 | } |
6166 | 6195 | } |
6167 | 6196 | } |
@@ -85,8 +85,6 @@ enum option_values | ||
85 | 85 | OPTION_NO_WARN_FATAL, |
86 | 86 | OPTION_WARN_MULTIPLE_GP, |
87 | 87 | OPTION_WARN_ONCE, |
88 | - OPTION_WARN_ORPHAN, | |
89 | - OPTION_NO_WARN_ORPHAN, | |
90 | 88 | OPTION_WARN_SECTION_ALIGN, |
91 | 89 | OPTION_SPLIT_BY_RELOC, |
92 | 90 | OPTION_SPLIT_BY_FILE , |
@@ -144,6 +142,7 @@ enum option_values | ||
144 | 142 | OPTION_POP_STATE, |
145 | 143 | OPTION_PRINT_MEMORY_USAGE, |
146 | 144 | OPTION_REQUIRE_DEFINED_SYMBOL, |
145 | + OPTION_ORPHAN_HANDLING, | |
147 | 146 | }; |
148 | 147 | |
149 | 148 | /* The initial parser states. */ |
@@ -492,10 +492,6 @@ static const struct ld_option ld_options[] = | ||
492 | 492 | '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES }, |
493 | 493 | { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE}, |
494 | 494 | '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES }, |
495 | - { {"warn-orphan", no_argument, NULL, OPTION_WARN_ORPHAN}, | |
496 | - '\0', NULL, N_("Warn if any orphan sections are encountered"), TWO_DASHES }, | |
497 | - { {"no-warn-orphan", no_argument, NULL, OPTION_NO_WARN_ORPHAN}, | |
498 | - '\0', NULL, N_("Do not warn if orphan sections are encountered (default)"), TWO_DASHES }, | |
499 | 495 | { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN}, |
500 | 496 | '\0', NULL, N_("Warn if start of section changes due to alignment"), |
501 | 497 | TWO_DASHES }, |
@@ -528,6 +524,9 @@ static const struct ld_option ld_options[] = | ||
528 | 524 | TWO_DASHES }, |
529 | 525 | { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE}, |
530 | 526 | '\0', NULL, N_("Report target memory usage"), TWO_DASHES }, |
527 | + { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING}, | |
528 | + '\0', N_("=MODE"), N_("Control how orphan sections are handled."), | |
529 | + TWO_DASHES }, | |
531 | 530 | }; |
532 | 531 | |
533 | 532 | #define OPTION_COUNT ARRAY_SIZE (ld_options) |
@@ -1375,12 +1374,6 @@ parse_args (unsigned argc, char **argv) | ||
1375 | 1374 | case OPTION_WARN_ONCE: |
1376 | 1375 | config.warn_once = TRUE; |
1377 | 1376 | break; |
1378 | - case OPTION_WARN_ORPHAN: | |
1379 | - config.warn_orphan = TRUE; | |
1380 | - break; | |
1381 | - case OPTION_NO_WARN_ORPHAN: | |
1382 | - config.warn_orphan = FALSE; | |
1383 | - break; | |
1384 | 1377 | case OPTION_WARN_SECTION_ALIGN: |
1385 | 1378 | config.warn_section_align = TRUE; |
1386 | 1379 | break; |
@@ -1515,6 +1508,20 @@ parse_args (unsigned argc, char **argv) | ||
1515 | 1508 | case OPTION_PRINT_MEMORY_USAGE: |
1516 | 1509 | command_line.print_memory_usage = TRUE; |
1517 | 1510 | break; |
1511 | + | |
1512 | + case OPTION_ORPHAN_HANDLING: | |
1513 | + if (strcasecmp (optarg, "place") == 0) | |
1514 | + config.orphan_handling = orphan_handling_place; | |
1515 | + else if (strcasecmp (optarg, "warn") == 0) | |
1516 | + config.orphan_handling = orphan_handling_warn; | |
1517 | + else if (strcasecmp (optarg, "error") == 0) | |
1518 | + config.orphan_handling = orphan_handling_error; | |
1519 | + else if (strcasecmp (optarg, "discard") == 0) | |
1520 | + config.orphan_handling = orphan_handling_discard; | |
1521 | + else | |
1522 | + einfo (_("%P%F: invalid argument to option" | |
1523 | + " \"--orphan-handling\"\n")); | |
1524 | + break; | |
1518 | 1525 | } |
1519 | 1526 | } |
1520 | 1527 |
@@ -1,3 +1,15 @@ | ||
1 | +2015-07-28 Andrew Burgess <andrew.burgess@embecosm.com> | |
2 | + | |
3 | + * ld-elf/elf.exp: Switch to rely on run_dump_test. | |
4 | + * ld-elf/orphan-5.l: Update expected output. | |
5 | + * ld-elf/orphan-5.d: New file. | |
6 | + * ld-elf/orphan-6.d: New file. | |
7 | + * ld-elf/orphan-6.l: New file. | |
8 | + * ld-elf/orphan-7.d: New file. | |
9 | + * ld-elf/orphan-7.map: New file. | |
10 | + * ld-elf/orphan-8.d: New file. | |
11 | + * ld-elf/orphan-8.map: New file. | |
12 | + | |
1 | 13 | 2015-09-03 H.J. Lu <hongjiu.lu@intel.com> |
2 | 14 | |
3 | 15 | * ld-ifunc/ifunc-21-i386.s: Add tests for call, jmp, add, test. |
@@ -124,18 +124,6 @@ foreach t $test_list { | ||
124 | 124 | run_dump_test [file rootname $t] |
125 | 125 | } |
126 | 126 | |
127 | -# Check that the --warn-orphan option works correctly. | |
128 | -run_ld_link_tests { | |
129 | - {"Report orphan sections" | |
130 | - "--script orphan.ld --warn-orphan" | |
131 | - "" | |
132 | - "" | |
133 | - {orphan.s} | |
134 | - { { ld "orphan-5.l" } } | |
135 | - "orphan" | |
136 | - } | |
137 | -} | |
138 | - | |
139 | 127 | if { [istarget *-*-linux*] |
140 | 128 | || [istarget *-*-nacl*] |
141 | 129 | || [istarget *-*-gnu*] } { |
@@ -0,0 +1,4 @@ | ||
1 | +#name: Report warning for orphan sections | |
2 | +#ld: --script orphan.ld --orphan-handling=warn | |
3 | +#source: orphan.s | |
4 | +#warning_output: orphan-5.l |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #... |
2 | -.*Warning: input section '.notbad' from file 'tmpdir/orphan.o' is not mentioned in linker script | |
2 | +.*warning: orphan section `\.notbad' from `tmpdir/orphan\.o' being placed in section `\.notbad'\. | |
3 | 3 | #... |
4 | -.*Warning: input section '.note.bar' from file 'tmpdir/orphan.o' is not mentioned in linker script | |
4 | +.*warning: orphan section `\.note\.bar' from `tmpdir/orphan\.o' being placed in section `\.note\.bar'\. | |
5 | 5 | #... |
@@ -0,0 +1,4 @@ | ||
1 | +#name: Report error for orphan sections | |
2 | +#ld: --script orphan.ld --orphan-handling=error | |
3 | +#source: orphan.s | |
4 | +#error_output: orphan-6.l |
@@ -0,0 +1,5 @@ | ||
1 | +#... | |
2 | +.*error: unplaced orphan section `\.notbad' from `tmpdir/orphan\.o'\. | |
3 | +#... | |
4 | +.*error: unplaced orphan section `\.note\.bar' from `tmpdir/orphan\.o'\. | |
5 | +#... |
@@ -0,0 +1,4 @@ | ||
1 | +#name: Discard orphan sections | |
2 | +#ld: --script orphan.ld --orphan-handling=discard | |
3 | +#source: orphan.s | |
4 | +#map: orphan-7.map |
@@ -0,0 +1,7 @@ | ||
1 | + | |
2 | +Discarded input sections | |
3 | + | |
4 | + \.notbad 0x0+ 0x4 tmpdir/.*\.o | |
5 | + \.note\.bar 0x0+ 0x4 tmpdir/.*\.o | |
6 | + | |
7 | +#... |
@@ -0,0 +1,4 @@ | ||
1 | +#name: Place orphan sections | |
2 | +#ld: --script orphan.ld --orphan-handling=place | |
3 | +#source: orphan.s | |
4 | +#map: orphan-8.map |
@@ -0,0 +1,7 @@ | ||
1 | +#... | |
2 | +.notbad 0x0000000000000004 0x4 | |
3 | + .notbad 0x0000000000000004 0x4 tmpdir/dump0.o | |
4 | +#... | |
5 | +.note.bar 0x0000000000000010 0x4 | |
6 | + .note.bar 0x0000000000000010 0x4 tmpdir/dump0.o | |
7 | +#... |