public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: Re: [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR
Date: Thu, 07 Aug 2014 00:55:00 -0000	[thread overview]
Message-ID: <20140807005451.GU8921@bubble.grove.modra.org> (raw)
In-Reply-To: <20140807004158.GT8921@bubble.grove.modra.org>

The thread https://sourceware.org/ml/binutils/2014-03/msg00261.html 
died without any resolution, I guess a case of me wanting perfection
and rejecting the good.  So now that I've merged the WARN and CWARN
my concern with HJ's patch is covered.  This is what I'm about to
commit on HJ's behalf.

bfd/
	PR ld/16746
	* linker.c (_bfd_generic_link_add_one_symbol): Don't issue a
	warning for references in LTO IR to warning symbols.

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.

diff --git a/bfd/linker.c b/bfd/linker.c
index 93c5465..d4b053c 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1776,8 +1776,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, except when the reference is
+	     in LTO IR.  */
+	  if (h->u.i.warning != NULL
+	      && (abfd->flags & BFD_PLUGIN) == 0)
 	    {
 	      if (! (*info->callbacks->warning) (info, h->u.i.warning,
 						 h->root.string, abfd,
@@ -1802,12 +1804,9 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 	  break;
 
 	case WARN:
-	  /* 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
-	     undefined symbol list.  The REF case above helps to
-	     ensure this.  */
-	  if (h->u.undef.next != NULL || info->hash->undefs_tail == h)
+	  /* Warn if this symbol has been referenced already from non-IR,
+	     otherwise add a warning.  */
+	  if (h->non_ir_ref)
 	    {
 	      if (! (*info->callbacks->warning) (info, string, h->root.string,
 						 hash_entry_bfd (h), NULL, 0))
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 432c753..7ff5bfb 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -232,6 +232,18 @@ set lto_link_elf_tests [list \
   [list "Build libpr15146d.a" \
    "$plug_opt" "-flto -O2" \
    {pr15146d.c} {} "lib15146d.a"] \
+  [list "Build libpr16746a.a" \
+   "" "" \
+   {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
+  [list "Build libpr16746b.a" \
+   "$plug_opt" "-O2 -flto" \
+   {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
+  [list "PR ld/16746 (1)" \
+   "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
+   {dummy.c} {} "pr16746a.exe"] \
+  [list "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.
@@ -335,6 +347,20 @@ if { [is_elf_format] && [check_lto_shared_available] } {
     } {
 	fail $testname
     }
+    set testname "PR ld/16746 (3)"
+    set exec_output [run_host_cmd "$CC" "-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" "-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;
+}


-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2014-08-07  0:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-07  0:42 Merge WARN and CWARN cases in _bfd_generic_link_add_one_symbol Alan Modra
2014-08-07  0:55 ` Alan Modra [this message]
2014-08-11 22:21   ` [PATCH] PR ld/16746: Don't issue a warning for reference in LTO IR Hans-Peter Nilsson
2014-08-12  1:12     ` Alan Modra
  -- strict thread matches above, loose matches on Subject: below --
2014-03-25 20:40 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140807005451.GU8921@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).