]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add new linker option: --warn-orphan which generates warning messages when orphan...
authorNick Clifton <nickc@redhat.com>
Tue, 7 Apr 2015 15:29:41 +0000 (16:29 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 7 Apr 2015 15:29:41 +0000 (16:29 +0100)
ld * ld.h (struct ld_config_type): Add new field: warn_orphan.
* ldlex.h (enum option_values): Add OPTION_WARN_ORPHAN and
OPTION_NO_WARN_ORPHAN.
* lexsup.c (ld_options): Add --warn-orphan and --no-warn-orphan.
(parse_args): Handle the new options.
* ldemul.c (ldemul_place_orphan): If requested, generate a warning
message when an orphan section is placed in the output file.
* ld.texinfo: Document the new option.
* NEWS: Mention the new feature.

tests * ld-elf/orphan-5.l: New test - checks the linker's output with
--warn-orphan enabled.
* ld-elf/elf.exp: Run the new test.

ld/ChangeLog
ld/NEWS
ld/ld.h
ld/ld.texinfo
ld/ldemul.c
ld/ldlex.h
ld/lexsup.c
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/elf.exp
ld/testsuite/ld-elf/orphan-5.l [new file with mode: 0644]

index 7468a7dcb9ea2039762d6ed3ea1620cfa66c5c77..4228732ee43757d95ab8980a19d1bbed58ae4739 100644 (file)
@@ -9,6 +9,18 @@
        (params): Init new field.
        (ppc_before_allocation): Enable relaxation for pic_fixup.
 
+2015-04-07  Nick Clifton  <nickc@redhat.com>
+
+       * ld.h (struct ld_config_type): Add new field: warn_orphan.
+       * ldlex.h (enum option_values): Add OPTION_WARN_ORPHAN and
+       OPTION_NO_WARN_ORPHAN.
+       * lexsup.c (ld_options): Add --warn-orphan and --no-warn-orphan.
+       (parse_args): Handle the new options.
+       * ldemul.c (ldemul_place_orphan): If requested, generate a warning
+       message when an orphan section is placed in the output file.
+       * ld.texinfo: Document the new option.
+       * NEWS: Mention the new feature.
+
 2015-04-02  Andrew Turner <andrew@freebsd.org>
 
        * Makefile.am: Add FreeBSD aarch64 files.
diff --git a/ld/NEWS b/ld/NEWS
index 3a592be0d5cf73ca398f00805f7b6b5d6e9ee52c..9cafe12c7a1bc94ca551ce88e679c4f3d0c58373 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,7 @@
 -*- text -*-
 
+* Add --warn-orphan option to report orphan sections.
+
 * Add support for LLVM plugin.
 
 Changes in 2.25:
diff --git a/ld/ld.h b/ld/ld.h
index e0ca3e83f0c8bf60c646b0838964de39c6c73687..f804f9c069699f4fd5140dab62ff844f89c48693 100644 (file)
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -226,6 +226,9 @@ typedef struct {
   /* If TRUE, only warn once about a particular undefined symbol.  */
   bfd_boolean warn_once;
 
+  /* If TRUE, issue warning messages when orphan sections are encountered.  */
+  bfd_boolean warn_orphan;
+
   /* If TRUE, warn if multiple global-pointers are needed (Alpha
      only).  */
   bfd_boolean warn_multiple_gp;
index 440fa4158a48f7006e194ce3f46d3f3693bae0d6..82735e9558d8c7b6562827e0ebbeb7eb72b78a38 100644 (file)
@@ -2064,6 +2064,17 @@ option causes a warning to be issued whenever this case occurs.
 Only warn once for each undefined symbol, rather than once per module
 which refers to it.
 
+@kindex --warn-orphan
+@kindex --no-warn-orphan
+@cindex warnings, on orphan sections
+@cindex orphan sections, warnings on
+@item --warn-orphan
+The @option{--warn-orphan} option tells the linker to generate a
+warning message whenever it has to place an orphan section into the
+output file.  @xref{Orphan Sections}  The @option{--no-warn-orphan}
+option restores the default behaviour of just silently placing these
+sections.
+
 @kindex --warn-section-align
 @cindex warnings, on section alignment
 @cindex section alignment, warnings on
index 8b2cae7711bdc41e38b5afd55d37aa745445d879..4898892c43789ecd991f6d0838c58278d67681f6 100644 (file)
@@ -120,6 +120,10 @@ ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search,
 lang_output_section_statement_type *
 ldemul_place_orphan (asection *s, const char *name, int constraint)
 {
+  if (config.warn_orphan)
+    einfo (_("%P: Warning: input section '%s' from file '%B' is not mentioned in linker script\n"),
+          name, s->owner);
+
   if (ld_emulation->place_orphan)
     return (*ld_emulation->place_orphan) (s, name, constraint);
   return NULL;
index be7f653086db6995b1d1642766714e653bf6397d..f174c28823b9f097e34b680ea6f3d8aaa85b15c1 100644 (file)
@@ -85,6 +85,8 @@ enum option_values
   OPTION_NO_WARN_FATAL,
   OPTION_WARN_MULTIPLE_GP,
   OPTION_WARN_ONCE,
+  OPTION_WARN_ORPHAN,
+  OPTION_NO_WARN_ORPHAN,
   OPTION_WARN_SECTION_ALIGN,
   OPTION_SPLIT_BY_RELOC,
   OPTION_SPLIT_BY_FILE ,
index aa6c3cdfdefd1851558e2adcabd53cfd612d026c..a30fafab1dbea703741a642457efdd89fe327307 100644 (file)
@@ -489,6 +489,10 @@ static const struct ld_option ld_options[] =
     '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
   { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
     '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
+  { {"warn-orphan", no_argument, NULL, OPTION_WARN_ORPHAN},
+    '\0', NULL, N_("Warn if any orphan sections are encountered"), TWO_DASHES },
+  { {"no-warn-orphan", no_argument, NULL, OPTION_NO_WARN_ORPHAN},
+    '\0', NULL, N_("Do not warn if orphan sections are encountered (default)"), TWO_DASHES },
   { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
     '\0', NULL, N_("Warn if start of section changes due to alignment"),
     TWO_DASHES },
@@ -1350,6 +1354,12 @@ parse_args (unsigned argc, char **argv)
        case OPTION_WARN_ONCE:
          config.warn_once = TRUE;
          break;
+       case OPTION_WARN_ORPHAN:
+         config.warn_orphan = TRUE;
+         break;
+       case OPTION_NO_WARN_ORPHAN:
+         config.warn_orphan = FALSE;
+         break;
        case OPTION_WARN_SECTION_ALIGN:
          config.warn_section_align = TRUE;
          break;
index 49a74f732c8359fc612fe8907be38049297b5032..ef54e6784c69102412e7903464c21b6e10e65dbb 100644 (file)
        * ld-tic6x/shlib-app-1rb.rd: Likewise.
        * ld-tic6x/shlib-noindex.rd: Likewise.
 
+2015-04-07  Nick Clifton  <nickc@redhat.com>
+
+       * ld-elf/orphan-5.l: New test - checks the linker's output with
+       --warn-orphan enabled.
+       * ld-elf/elf.exp: Run the new test.
+
 2015-04-06  H.J. Lu  <hongjiu.lu@intel.com>
 
        * ld-elf/compress.exp: Remove is_zlib_supported check.
index f126650fc3528f5b3826c4e14ac1a18380a3a8f4..d1a70ea69733e461e7afe20c17fcf6279a6e639b 100644 (file)
@@ -116,6 +116,18 @@ foreach t $test_list {
     run_dump_test [file rootname $t]
 }
 
+# Check that the --warn-orphan option works correctly.
+run_ld_link_tests {
+    {"Report orphan sections"
+       "--script orphan.ld --warn-orphan"
+       ""
+       ""
+       {orphan.s}
+       { { ld "orphan-5.l" } }
+       "orphan"
+    }
+}
+
 if { [istarget *-*-linux*]
      || [istarget *-*-nacl*]
      || [istarget *-*-gnu*] } {
diff --git a/ld/testsuite/ld-elf/orphan-5.l b/ld/testsuite/ld-elf/orphan-5.l
new file mode 100644 (file)
index 0000000..7b65af2
--- /dev/null
@@ -0,0 +1,5 @@
+#...
+.*Warning: input section '.notbad' from file 'tmpdir/orphan.o' is not mentioned in linker script
+#...
+.*Warning: input section '.note.bar' from file 'tmpdir/orphan.o' is not mentioned in linker script
+#...