This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR ld/16756: Incorrect warning message


This patch scans all input files for symbol reference warning if the
symbol reference doesn't exist in the current input file.  It issues a
warning only if a reference is found.  When LTO inlines or removes all
references to the symbol, we won't issue the symbol reference warning.
OK to install?

Thanks.


H.J.
---
ld/

	PR ld/16756
	* ldmain.c (symbol_warning): New function.
	(warning_callback): Use it.  Scan all input files for a reference
	to SYMBOL.  Don't issue warning if reference isn't found.

2014-03-26  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/16756
	* ld-plugin/lto.exp: Expect filename and line number for PR
	ld/12760 test.
---
 ld/ChangeLog                   |  7 +++++++
 ld/ldmain.c                    | 42 +++++++++++++++++++++++++-----------------
 ld/testsuite/ChangeLog         |  6 ++++++
 ld/testsuite/ld-plugin/lto.exp |  4 ++--
 4 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 292459b..c459a4b 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2014-03-26  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.  Don't issue warning if reference isn't found.
+
 2014-03-17  Christopher Faylor  <me.cygwin2013@cgf.cx>
 
 	* ld.texinfo: Document change in handling of --enable-auto-image-base.
diff --git a/ld/ldmain.c b/ld/ldmain.c
index ffc9f84..790d9f2 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -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,13 @@ 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;
     }
 
   return TRUE;
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 279958e..d89a73e 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-26  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-26  Alan Modra  <amodra@gmail.com>
 
 	* ld-powerpc/startv1.s, * ld-powerpc/startv2.s, * ld-powerpc/funref.s,
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index af7307f..53543a6 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -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"}
-- 
1.8.5.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]