Scan all input files for symbol reference warning
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 26 Mar 2014 19:18:59 +0000 (12:18 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 27 Mar 2014 15:12:17 +0000 (08:12 -0700)
This patch scans all input files for symbol reference warning if the
symbol reference doesn't exist in the current input file.

ld/

PR ld/16756
* ldmain.c (symbol_warning): New function.
(warning_callback): Use it.  Scan all input files for a reference
to SYMBOL.

ld/testsuite/

PR ld/16756
* ld-plugin/lto.exp: Expect filename and line number for PR
ld/12760 test.

ld/ChangeLog
ld/ldmain.c
ld/testsuite/ChangeLog
ld/testsuite/ld-plugin/lto.exp

index 292459b4d347418b9ab63edc368dc7e9d1f04514..1c691fe131d6b3d671b961b96a8e0385225885e6 100644 (file)
@@ -1,3 +1,10 @@
+2014-03-27  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/16756
+       * ldmain.c (symbol_warning): New function.
+       (warning_callback): Use it.  Scan all input files for a reference
+       to SYMBOL.
+
 2014-03-17  Christopher Faylor  <me.cygwin2013@cgf.cx>
 
        * ld.texinfo: Document change in handling of --enable-auto-image-base.
index ffc9f84acc93e4c371b02c5d08d664f2f3e3968b..14253a6f0c2a8a4f393a9360116b51d447f43aa1 100644 (file)
@@ -1150,6 +1150,25 @@ struct warning_callback_info
   asymbol **asymbols;
 };
 
+/* Look through the relocs to see if we can find a plausible address
+   for SYMBOL in ABFD.  Return TRUE if found.  Otherwise return FALSE.  */
+
+static bfd_boolean
+symbol_warning (const char *warning, const char *symbol, bfd *abfd)
+{
+  struct warning_callback_info cinfo;
+
+  if (!bfd_generic_link_read_symbols (abfd))
+    einfo (_("%B%F: could not read symbols: %E\n"), abfd);
+
+  cinfo.found = FALSE;
+  cinfo.warning = warning;
+  cinfo.symbol = symbol;
+  cinfo.asymbols = bfd_get_outsymbols (abfd);
+  bfd_map_over_sections (abfd, warning_find_reloc, &cinfo);
+  return cinfo.found;
+}
+
 /* This is called when there is a reference to a warning symbol.  */
 
 static bfd_boolean
@@ -1172,24 +1191,14 @@ warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED,
     einfo ("%P: %s%s\n", _("warning: "), warning);
   else if (symbol == NULL)
     einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
-  else
+  else if (! symbol_warning (warning, symbol, abfd))
     {
-      struct warning_callback_info cinfo;
-
-      /* Look through the relocs to see if we can find a plausible
-        address.  */
-
-      if (!bfd_generic_link_read_symbols (abfd))
-       einfo (_("%B%F: could not read symbols: %E\n"), abfd);
-
-      cinfo.found = FALSE;
-      cinfo.warning = warning;
-      cinfo.symbol = symbol;
-      cinfo.asymbols = bfd_get_outsymbols (abfd);
-      bfd_map_over_sections (abfd, warning_find_reloc, &cinfo);
-
-      if (! cinfo.found)
-       einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
+      bfd *b;
+      /* Search all input files for a reference to SYMBOL.  */
+      for (b = info->input_bfds; b; b = b->link_next)
+       if (b != abfd && symbol_warning (warning, symbol, b))
+         return TRUE;
+      einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
     }
 
   return TRUE;
index d35eb0421fb1fcee8106b6a6bda621f0b728708f..b5d13447053fc238b868820ba69751f670b31f9e 100644 (file)
@@ -1,35 +1,41 @@
+2014-03-27  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/16756
+       * ld-plugin/lto.exp: Expect filename and line number for PR
+       ld/12760 test.
+
 2014-03-27  Yury Gribov  <y.gribov@samsung.com>
-           Pavel Fedin  <p.fedin@samsung.com>
+           Pavel Fedin  <p.fedin@samsung.com>
 
-       * ld-arm/arm-app-abs32.d: Update expected disassembly, taking into
+       * ld-arm/arm-app-abs32.d: Update expected disassembly, taking into
        account the pretty printing of PLT entries.
-       * ld-arm/arm-app.d: Likewise.
-       * ld-arm/arm-lib-plt32.d: Likewise.
-       * ld-arm/arm-lib.d: Likewise.
-       * ld-arm/armthumb-lib.d: Likewise.
-       * ld-arm/cortex-a8-fix-b-plt.d: Likewise.
-       * ld-arm/cortex-a8-fix-bcc-plt.d: Likewise.
-       * ld-arm/cortex-a8-fix-bl-plt.d: Likewise.
-       * ld-arm/cortex-a8-fix-bl-rel-plt.d: Likewise.
-       * ld-arm/cortex-a8-fix-blx-plt.d: Likewise.
-       * ld-arm/farcall-mixed-app-v5.d: Likewise.
-       * ld-arm/farcall-mixed-app.d: Likewise.
-       * ld-arm/farcall-mixed-lib-v4t.d: Likewise.
-       * ld-arm/farcall-mixed-lib.d: Likewise.
-       * ld-arm/ifunc-10.dd: Likewise.
-       * ld-arm/ifunc-14.dd: Likewise.
-       * ld-arm/ifunc-15.dd: Likewise.
-       * ld-arm/ifunc-3.dd: Likewise.
-       * ld-arm/ifunc-4.dd: Likewise.
-       * ld-arm/ifunc-7.dd: Likewise.
-       * ld-arm/ifunc-8.dd: Likewise.
-       * ld-arm/ifunc-9.dd: Likewise.
-       * ld-arm/long-plt-format.d: Likewise.
-       * ld-arm/mixed-app-v5.d: Likewise.
-       * ld-arm/mixed-app.d: Likewise.
-       * ld-arm/mixed-lib.d: Likewise.
-       * ld-arm/thumb2-bl-undefweak.d: Likewise.
-       * ld-arm/thumb2-bl-undefweak1.d: Likewise.
+       * ld-arm/arm-app.d: Likewise.
+       * ld-arm/arm-lib-plt32.d: Likewise.
+       * ld-arm/arm-lib.d: Likewise.
+       * ld-arm/armthumb-lib.d: Likewise.
+       * ld-arm/cortex-a8-fix-b-plt.d: Likewise.
+       * ld-arm/cortex-a8-fix-bcc-plt.d: Likewise.
+       * ld-arm/cortex-a8-fix-bl-plt.d: Likewise.
+       * ld-arm/cortex-a8-fix-bl-rel-plt.d: Likewise.
+       * ld-arm/cortex-a8-fix-blx-plt.d: Likewise.
+       * ld-arm/farcall-mixed-app-v5.d: Likewise.
+       * ld-arm/farcall-mixed-app.d: Likewise.
+       * ld-arm/farcall-mixed-lib-v4t.d: Likewise.
+       * ld-arm/farcall-mixed-lib.d: Likewise.
+       * ld-arm/ifunc-10.dd: Likewise.
+       * ld-arm/ifunc-14.dd: Likewise.
+       * ld-arm/ifunc-15.dd: Likewise.
+       * ld-arm/ifunc-3.dd: Likewise.
+       * ld-arm/ifunc-4.dd: Likewise.
+       * ld-arm/ifunc-7.dd: Likewise.
+       * ld-arm/ifunc-8.dd: Likewise.
+       * ld-arm/ifunc-9.dd: Likewise.
+       * ld-arm/long-plt-format.d: Likewise.
+       * ld-arm/mixed-app-v5.d: Likewise.
+       * ld-arm/mixed-app.d: Likewise.
+       * ld-arm/mixed-lib.d: Likewise.
+       * ld-arm/thumb2-bl-undefweak.d: Likewise.
+       * ld-arm/thumb2-bl-undefweak1.d: Likewise.
 
 2014-03-26  Alan Modra  <amodra@gmail.com>
 
index af7307f7e01184ff58c2ffa9dc8a9e928e18af66..53543a6f253bf4979eaf3dd1ba3c32555fc86f72 100644 (file)
@@ -116,14 +116,14 @@ set lto_link_tests {
    "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" ""
    {dummy.c} {} "pr12758.exe"}
   {"Build libdummy.a PR ld/12760"
-   "" ""
+   "" "-g -O0"
    {pr12760a.c} {} "libdummy.a"}
   {"Build libpr12760.a"
    "" "-flto -O2 -ffat-lto-objects"
    {pr12760b.c} {} "libpr12760.a"}
   {"PR ld/12760"
    "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" ""
-   {dummy.c} {} "pr12760.exe" "c" "warning: Bad bar"}
+   {dummy.c} {} "pr12760.exe" "c" "pr12760a.c:6: warning: Bad bar"}
   {"Build libpr13183.a"
    "-T" "-flto -O2 -ffat-lto-objects"
    {pr13183a.c} {} "libpr13183.a"}