Don't issue a warning for references in LTO IR to warning symbols
authorH.J. Lu <hongjiu.lu@intel.com>
Thu, 7 Aug 2014 00:23:46 +0000 (09:53 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 7 Aug 2014 00:58:48 +0000 (10:28 +0930)
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.

bfd/ChangeLog
bfd/linker.c
ld/testsuite/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr16746a.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr16746b.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr16746c.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr16746d.c [new file with mode: 0644]

index ad651a6a3a6efabdbf69dcb272d03ca412b0dabd..edbcffa6e7984fff44456943cb8a26923369bfc5 100644 (file)
@@ -1,3 +1,10 @@
+2014-08-07  H.J. Lu  <hongjiu.lu@intel.com>
+           Alan Modra  <amodra@gmail.com>
+
+       PR ld/16746
+       * linker.c (_bfd_generic_link_add_one_symbol): Don't issue a
+       warning for references in LTO IR to warning symbols.
+
 2014-08-07  Alan Modra  <amodra@gmail.com>
 
        * linker.c (WARN, CWARN): Collapse these states to WARN.
index 93c5465e063bc25d1c51098200b8421afc6e90d5..d4b053c9c6f905dffc7b1e7044fe9a90078fe599 100644 (file)
@@ -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))
index da8f2f597643d408c943100d3ed4ab40257ca9a6..bcddeacb4b01282a738b6ee72fe4800b0a9e6cd5 100644 (file)
@@ -1,3 +1,12 @@
+2014-08-07  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-08-06  Alan Modra  <amodra@gmail.com>
 
        * lib/ld-lib.exp (check_lto_fat_available): New.
index 432c7533d774882158da40ecec8dbc54a98aaf03..7ff5bfb5cdc3cc3f2cb567e923c57c5ddd45343f 100644 (file)
@@ -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 (file)
index 0000000..1705ef1
--- /dev/null
@@ -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 (file)
index 0000000..c3b7a78
--- /dev/null
@@ -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 (file)
index 0000000..fb68ab7
--- /dev/null
@@ -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 (file)
index 0000000..1fee4dd
--- /dev/null
@@ -0,0 +1,8 @@
+extern void foobar (void);
+int
+main (int argc, char **argv)
+{
+  if (!__builtin_constant_p (argc))
+    foobar ();
+  return 0;
+}