• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisionc005eb9e34ac08be0cd40e19a741d345bd43eab9 (tree)
Zeit2015-09-05 06:30:55
AutorAndrew Burgess <andrew.burgess@embe...>
CommiterAndrew Burgess

Log Message

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.

Ändern Zusammenfassung

Diff

--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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+
120 2015-09-03 Nick Clifton <nickc@redhat.com>
221
322 * ld.texinfo (--build-id): Fix typo. The COFF/PE build-id section
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -6,7 +6,11 @@
66 * New command line option for ELF targets to compress DWARF debug
77 sections, --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi].
88
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.
1014
1115 * Add support for LLVM plugin.
1216
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -207,6 +207,25 @@ extern args_type command_line;
207207
208208 typedef int token_code_type;
209209
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+
210229 typedef struct {
211230 bfd_boolean magic_demand_paged;
212231 bfd_boolean make_executable;
@@ -229,8 +248,8 @@ typedef struct {
229248 /* If TRUE, only warn once about a particular undefined symbol. */
230249 bfd_boolean warn_once;
231250
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;
234253
235254 /* If TRUE, warn if multiple global-pointers are needed (Alpha
236255 only). */
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1001,6 +1001,35 @@ with @samp{-Ur}; once the constructor table has been built, it cannot
10011001 be added to. Use @samp{-Ur} only for the last partial link, and
10021002 @samp{-r} for the others.
10031003
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+
10041033 @kindex --unique[=@var{SECTION}]
10051034 @item --unique[=@var{SECTION}]
10061035 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.
21052134 Only warn once for each undefined symbol, rather than once per module
21062135 which refers to it.
21072136
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-
21192137 @kindex --warn-section-align
21202138 @cindex warnings, on section alignment
21212139 @cindex section alignment, warnings on
@@ -5569,6 +5587,10 @@ at the end of the file.
55695587 For ELF targets, the attribute of the section includes section type as
55705588 well as section flag.
55715589
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+
55725594 If an orphaned section's name is representable as a C identifier then
55735595 the linker will automatically @pxref{PROVIDE} two symbols:
55745596 __start_SECNAME and __stop_SECNAME, where SECNAME is the name of the
--- a/ld/ldemul.c
+++ b/ld/ldemul.c
@@ -120,10 +120,6 @@ ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search,
120120 lang_output_section_statement_type *
121121 ldemul_place_orphan (asection *s, const char *name, int constraint)
122122 {
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-
127123 if (ld_emulation->place_orphan)
128124 return (*ld_emulation->place_orphan) (s, name, constraint);
129125 return NULL;
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -6102,6 +6102,55 @@ lang_one_common (struct bfd_link_hash_entry *h, void *info)
61026102 return TRUE;
61036103 }
61046104
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+
61056154 /* Run through the input files and ensure that every input section has
61066155 somewhere to go. If one is found without a destination then create
61076156 an input request and place it into the statement tree. */
@@ -6141,27 +6190,7 @@ lang_place_orphans (void)
61416190 }
61426191 }
61436192 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);
61656194 }
61666195 }
61676196 }
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -85,8 +85,6 @@ enum option_values
8585 OPTION_NO_WARN_FATAL,
8686 OPTION_WARN_MULTIPLE_GP,
8787 OPTION_WARN_ONCE,
88- OPTION_WARN_ORPHAN,
89- OPTION_NO_WARN_ORPHAN,
9088 OPTION_WARN_SECTION_ALIGN,
9189 OPTION_SPLIT_BY_RELOC,
9290 OPTION_SPLIT_BY_FILE ,
@@ -144,6 +142,7 @@ enum option_values
144142 OPTION_POP_STATE,
145143 OPTION_PRINT_MEMORY_USAGE,
146144 OPTION_REQUIRE_DEFINED_SYMBOL,
145+ OPTION_ORPHAN_HANDLING,
147146 };
148147
149148 /* The initial parser states. */
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -492,10 +492,6 @@ static const struct ld_option ld_options[] =
492492 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
493493 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
494494 '\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 },
499495 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
500496 '\0', NULL, N_("Warn if start of section changes due to alignment"),
501497 TWO_DASHES },
@@ -528,6 +524,9 @@ static const struct ld_option ld_options[] =
528524 TWO_DASHES },
529525 { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
530526 '\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 },
531530 };
532531
533532 #define OPTION_COUNT ARRAY_SIZE (ld_options)
@@ -1375,12 +1374,6 @@ parse_args (unsigned argc, char **argv)
13751374 case OPTION_WARN_ONCE:
13761375 config.warn_once = TRUE;
13771376 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;
13841377 case OPTION_WARN_SECTION_ALIGN:
13851378 config.warn_section_align = TRUE;
13861379 break;
@@ -1515,6 +1508,20 @@ parse_args (unsigned argc, char **argv)
15151508 case OPTION_PRINT_MEMORY_USAGE:
15161509 command_line.print_memory_usage = TRUE;
15171510 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;
15181525 }
15191526 }
15201527
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -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+
113 2015-09-03 H.J. Lu <hongjiu.lu@intel.com>
214
315 * ld-ifunc/ifunc-21-i386.s: Add tests for call, jmp, add, test.
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -124,18 +124,6 @@ foreach t $test_list {
124124 run_dump_test [file rootname $t]
125125 }
126126
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-
139127 if { [istarget *-*-linux*]
140128 || [istarget *-*-nacl*]
141129 || [istarget *-*-gnu*] } {
--- /dev/null
+++ b/ld/testsuite/ld-elf/orphan-5.d
@@ -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
--- a/ld/testsuite/ld-elf/orphan-5.l
+++ b/ld/testsuite/ld-elf/orphan-5.l
@@ -1,5 +1,5 @@
11 #...
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'\.
33 #...
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'\.
55 #...
--- /dev/null
+++ b/ld/testsuite/ld-elf/orphan-6.d
@@ -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
--- /dev/null
+++ b/ld/testsuite/ld-elf/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+#...
--- /dev/null
+++ b/ld/testsuite/ld-elf/orphan-7.d
@@ -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
--- /dev/null
+++ b/ld/testsuite/ld-elf/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+#...
--- /dev/null
+++ b/ld/testsuite/ld-elf/orphan-8.d
@@ -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
--- /dev/null
+++ b/ld/testsuite/ld-elf/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+#...