SHA256
3
0
forked from pool/binutils
binutils/binutils-2.24-bso16746.diff

151 lines
5.3 KiB
Diff

commit 26c2ff33f8fcd57d52194a159226b639a4fee00c
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Tue Mar 25 13:33:51 2014 -0700
Don't issue a warning for reference in LTO IR
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.
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.
Index: binutils-2.24/bfd/linker.c
===================================================================
--- binutils-2.24.orig/bfd/linker.c 2014-05-06 16:08:45.649990914 +0200
+++ binutils-2.24/bfd/linker.c 2014-05-06 16:08:49.819990627 +0200
@@ -1904,8 +1904,10 @@ _bfd_generic_link_add_one_symbol (struct
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,
@@ -1930,6 +1932,11 @@ _bfd_generic_link_add_one_symbol (struct
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))
@@ -1951,6 +1958,7 @@ _bfd_generic_link_add_one_symbol (struct
}
/* Fall through. */
case MWARN:
+mwarn:
/* Make a warning symbol. */
{
struct bfd_link_hash_entry *sub;
Index: binutils-2.24/ld/testsuite/ld-plugin/lto.exp
===================================================================
--- binutils-2.24.orig/ld/testsuite/ld-plugin/lto.exp 2014-05-06 16:08:45.649990914 +0200
+++ binutils-2.24/ld/testsuite/ld-plugin/lto.exp 2014-05-06 16:10:14.334984808 +0200
@@ -206,6 +206,18 @@ set lto_link_elf_tests {
{"Build libpr15146d.a"
"" "-flto -O2"
{pr15146d.c} {} "lib15146d.a"}
+ {"Build libpr16746a.a"
+ "" ""
+ {pr16746a.c pr16746b.c} {} "lib16746a.a"}
+ {"Build libpr16746b.a"
+ "" "-O2 -flto"
+ {pr16746c.c pr16746d.c} {} "lib16746b.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.
@@ -309,6 +321,20 @@ if { [is_elf_format]
pass $testname
} {
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
}
}
Index: binutils-2.24/ld/testsuite/ld-plugin/pr16746a.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.24/ld/testsuite/ld-plugin/pr16746a.c 2014-05-06 16:08:49.819990627 +0200
@@ -0,0 +1,3 @@
+static const char __evoke_link_warning_foobar[]
+ __attribute__ ((used, section (".gnu.warning.foobar\n\t#")))
+ = "foobar";
Index: binutils-2.24/ld/testsuite/ld-plugin/pr16746b.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.24/ld/testsuite/ld-plugin/pr16746b.c 2014-05-06 16:08:49.820990627 +0200
@@ -0,0 +1,5 @@
+static const char __evoke_link_warning_foobar[]
+ __attribute__ ((used, section (".gnu.warning.foobar\n\t#")))
+ = "foobar";
+
+void foobar (void) {}
Index: binutils-2.24/ld/testsuite/ld-plugin/pr16746c.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.24/ld/testsuite/ld-plugin/pr16746c.c 2014-05-06 16:08:49.820990627 +0200
@@ -0,0 +1,8 @@
+extern void foobar (void);
+int
+main (int argc, char **argv)
+{
+ if (__builtin_constant_p (argc))
+ foobar ();
+ return 0;
+}
Index: binutils-2.24/ld/testsuite/ld-plugin/pr16746d.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-2.24/ld/testsuite/ld-plugin/pr16746d.c 2014-05-06 16:08:49.820990627 +0200
@@ -0,0 +1,8 @@
+extern void foobar (void);
+int
+main (int argc, char **argv)
+{
+ if (!__builtin_constant_p (argc))
+ foobar ();
+ return 0;
+}