public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR
@ 2014-03-25 20:40 H.J. Lu
  2014-03-25 22:39 ` Alan Modra
  0 siblings, 1 reply; 9+ messages in thread
From: H.J. Lu @ 2014-03-25 20:40 UTC (permalink / raw)
  To: binutils

References in LTO IR may be removed by LTO later.  Instead, make a
warning symbol if needed.  Warnings will be handled after LTO resolves
all references.  OK to install?

Thanks.


H.J.
---
bfd/

	PR ld/16746
	* linker.c (_bfd_generic_link_add_one_symbol): Don't issue a
	warning for reference in LTO IR which may be removed by LTO later.

ld/testsuite/

	PR ld/16746
	* ld-plugin/lto.exp: Add 4 tests for PR ld/16746.
	* ld-plugin/pr16746a.c: New file.
	* ld-plugin/pr16746b.c: Likewise.
	* ld-plugin/pr16746c.c: Likewise.
	* ld-plugin/pr16746d.c: Likewise.
---
 bfd/ChangeLog                     |  6 ++++++
 bfd/linker.c                      | 12 ++++++++++--
 ld/testsuite/ChangeLog            |  9 +++++++++
 ld/testsuite/ld-plugin/lto.exp    | 26 ++++++++++++++++++++++++++
 ld/testsuite/ld-plugin/pr16746a.c |  3 +++
 ld/testsuite/ld-plugin/pr16746b.c |  5 +++++
 ld/testsuite/ld-plugin/pr16746c.c |  8 ++++++++
 ld/testsuite/ld-plugin/pr16746d.c |  8 ++++++++
 8 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 ld/testsuite/ld-plugin/pr16746a.c
 create mode 100644 ld/testsuite/ld-plugin/pr16746b.c
 create mode 100644 ld/testsuite/ld-plugin/pr16746c.c
 create mode 100644 ld/testsuite/ld-plugin/pr16746d.c

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index c719d24..630c5a8 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-25  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/16746
+	* linker.c (_bfd_generic_link_add_one_symbol): Don't issue a
+	warning for reference in LTO IR which may be removed by LTO later.
+
 2014-03-25  Will Newton  <will.newton@linaro.org>
 
 	 * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections):
diff --git a/bfd/linker.c b/bfd/linker.c
index a20a276..4eeb363 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1902,8 +1902,10 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	  break;
 
 	case WARNC:
-	  /* Issue a warning and cycle.  */
-	  if (h->u.i.warning != NULL)
+	  /* Issue a warning and cycle.  Don't issue a warning for
+	     reference in LTO IR which may be removed by LTO later. */
+	  if (h->u.i.warning != NULL
+	      && (abfd->flags & BFD_PLUGIN) == 0)
 	    {
 	      if (! (*info->callbacks->warning) (info, h->u.i.warning,
 						 h->root.string, abfd,
@@ -1928,6 +1930,11 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	  break;
 
 	case WARN:
+	  /* Don't issue a warning for reference in LTO IR which may be
+	     removed by LTO later.  Make a warning symbol instead.  */
+	  if ((hash_entry_bfd (h)->flags & BFD_PLUGIN) != 0)
+	    goto mwarn;
+
 	  /* Issue a warning.  */
 	  if (! (*info->callbacks->warning) (info, string, h->root.string,
 					     hash_entry_bfd (h), NULL, 0))
@@ -1949,6 +1956,7 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	    }
 	  /* Fall through.  */
 	case MWARN:
+mwarn:
 	  /* Make a warning symbol.  */
 	  {
 	    struct bfd_link_hash_entry *sub;
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index d200277..21df737 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2014-03-25  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/16746
+	* ld-plugin/lto.exp: Add 4 tests for PR ld/16746.
+	* ld-plugin/pr16746a.c: New file.
+	* ld-plugin/pr16746b.c: Likewise.
+	* ld-plugin/pr16746c.c: Likewise.
+	* ld-plugin/pr16746d.c: Likewise.
+
 2014-03-25  Will Newton  <will.newton@linaro.org>
 
 	 * ld-aarch64/aarch64-elf.exp: Add relasz dump test.
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index af7307f..c37ecf9 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -205,6 +205,18 @@ set lto_link_elf_tests {
   {"Build libpr15146d.a"
    "" "-flto -O2"
    {pr15146d.c} {} "lib15146d.a"}
+  {"Build libpr16746a.a"
+   "" ""
+   {pr16746a.c pr16746b.c} {} "lib15146a.a"}
+  {"Build libpr16746b.a"
+   "" "-O2 -flto"
+   {pr16746c.c pr16746d.c} {} "lib15146b.a"}
+  {"PR ld/16746 (1)"
+   "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto"
+   {dummy.c} {} "pr16746a.exe"}
+  {"PR ld/16746 (2)"
+   "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto"
+   {dummy.c} {} "pr16746b.exe"}
 }
 
 # Check final symbols in executables.
@@ -308,6 +320,20 @@ if { [is_elf_format] && [check_lto_shared_available] } {
     } {
 	fail $testname
     }
+    set testname "PR ld/16746 (3)"
+    set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
+    if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
+	pass $testname
+    } {
+	fail $testname
+    }
+    set testname "PR ld/16746 (4)"
+    set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
+    if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
+	pass $testname
+    } {
+	fail $testname
+    }
 }
 
 set testname "Build liblto-11.a"
diff --git a/ld/testsuite/ld-plugin/pr16746a.c b/ld/testsuite/ld-plugin/pr16746a.c
new file mode 100644
index 0000000..1705ef1
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746a.c
@@ -0,0 +1,3 @@
+static const char __evoke_link_warning_foobar[]
+ __attribute__ ((used, section (".gnu.warning.foobar\n\t#")))
+ = "foobar";
diff --git a/ld/testsuite/ld-plugin/pr16746b.c b/ld/testsuite/ld-plugin/pr16746b.c
new file mode 100644
index 0000000..c3b7a78
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746b.c
@@ -0,0 +1,5 @@
+static const char __evoke_link_warning_foobar[]
+ __attribute__ ((used, section (".gnu.warning.foobar\n\t#")))
+ = "foobar";
+
+void foobar (void) {}
diff --git a/ld/testsuite/ld-plugin/pr16746c.c b/ld/testsuite/ld-plugin/pr16746c.c
new file mode 100644
index 0000000..fb68ab7
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746c.c
@@ -0,0 +1,8 @@
+extern void foobar (void);
+int
+main (int argc, char **argv)
+{
+  if (__builtin_constant_p (argc))
+    foobar ();
+  return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr16746d.c b/ld/testsuite/ld-plugin/pr16746d.c
new file mode 100644
index 0000000..1fee4dd
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr16746d.c
@@ -0,0 +1,8 @@
+extern void foobar (void);
+int
+main (int argc, char **argv)
+{
+  if (!__builtin_constant_p (argc))
+    foobar ();
+  return 0;
+}
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Merge WARN and CWARN cases in _bfd_generic_link_add_one_symbol
@ 2014-08-07  0:42 Alan Modra
  2014-08-07  0:55 ` [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR Alan Modra
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Modra @ 2014-08-07  0:42 UTC (permalink / raw)
  To: binutils

WARN has always been able to be handled by the CWARN case (WARN was
used when the previous symbols was undef, undefweak or common and thus
must be on the undefs list, so the CWARN test passes).  So let's merge
those two cases.

	* linker.c (WARN, CWARN): Collapse these states to WARN.
	(_bfd_generic_link_add_one_symbol): Use old CWARN case for
	new WARN.

diff --git a/bfd/linker.c b/bfd/linker.c
index 1877e67..93c5465 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1342,8 +1342,7 @@ enum link_action
   CIND,		/* Make indirect symbol from existing common symbol.  */
   SET,		/* Add value to set.  */
   MWARN,	/* Make warning symbol.  */
-  WARN,		/* Issue warning.  */
-  CWARN,	/* Warn if referenced, else MWARN.  */
+  WARN,		/* Warn if referenced, else MWARN.  */
   CYCLE,	/* Repeat with symbol pointed to.  */
   REFC,		/* Mark indirect symbol referenced and then CYCLE.  */
   WARNC		/* Issue warning and then CYCLE.  */
@@ -1361,7 +1360,7 @@ static const enum link_action link_action[8][8] =
   /* DEFW_ROW 	*/  {DEFW,  DEFW,  DEFW,  NOACT, NOACT, NOACT, NOACT, CYCLE },
   /* COMMON_ROW	*/  {COM,   COM,   COM,   CREF,  COM,   BIG,   REFC,  WARNC },
   /* INDR_ROW	*/  {IND,   IND,   IND,   MDEF,  IND,   CIND,  MIND,  CYCLE },
-  /* WARN_ROW   */  {MWARN, WARN,  WARN,  CWARN, CWARN, WARN,  CWARN, NOACT },
+  /* WARN_ROW   */  {MWARN, WARN,  WARN,  WARN,  WARN,  WARN,  WARN,  NOACT },
   /* SET_ROW	*/  {SET,   SET,   SET,   SET,   SET,   SET,   CYCLE, CYCLE }
 };
 
@@ -1803,13 +1802,6 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	  break;
 
 	case WARN:
-	  /* Issue a warning.  */
-	  if (! (*info->callbacks->warning) (info, string, h->root.string,
-					     hash_entry_bfd (h), NULL, 0))
-	    return FALSE;
-	  break;
-
-	case CWARN:
 	  /* Warn if this symbol has been referenced already,
 	     otherwise add a warning.  A symbol has been referenced if
 	     the u.undef.next field is not NULL, or it is the tail of the

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-08-12  1:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-25 20:40 [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR H.J. Lu
2014-03-25 22:39 ` Alan Modra
2014-03-25 22:50   ` H.J. Lu
2014-03-25 23:53     ` Alan Modra
2014-03-26  0:41       ` H.J. Lu
2014-03-26 19:29         ` H.J. Lu
2014-08-07  0:42 Merge WARN and CWARN cases in _bfd_generic_link_add_one_symbol Alan Modra
2014-08-07  0:55 ` [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR Alan Modra
2014-08-11 22:21   ` Hans-Peter Nilsson
2014-08-12  1:12     ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).