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/12761: .gnu.warning.* doesn't work when building shared library


Hi,

We should issure a gnu warning when building shared library.  This patch
implements it.  OK for trunk?

Thanks.


H.J.
---
bfd/

2011-05-16  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12761
	* elflink.c (elf_link_add_object_symbols): Also generate warnings
	when building shared libraries.

ld/testsuite/

2011-05-16  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/12761
	* ld-elf/elf.exp: Compile tmpdir/warn3a.o and tmpdir/warn3b.o.

	* ld-elf/shared.exp (build_tests): Build libbarw.so with
	warn.c.  Add "Build beginwarn.o with PIC".

	* ld-elf/warn.c: New.
	* ld-elf/warn3.d: Likewise.
	* ld-elf/warn3a.c: Likewise.
	* ld-elf/warn3b.c: Likewise.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index e4f728d..8d18ea8 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3423,7 +3423,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
      .gnu.warning.SYMBOL are treated as warning symbols for the given
      symbol.  This differs from .gnu.warning sections, which generate
      warnings when they are included in an output file.  */
-  if (info->executable)
+  if (info->executable || info->shared)
     {
       asection *s;
 
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index b9ff0bd..2a8886d 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -40,6 +40,14 @@ if { [is_remote host] } then {
     remote_download host merge.ld
 }
 
+if ![ld_compile "$CC -fPIC" $srcdir/$subdir/warn3a.c tmpdir/warn3a.o] {
+    fail "warn3a.c with PIC"
+}
+
+if ![ld_compile "$CC -fPIC" $srcdir/$subdir/warn3b.c tmpdir/warn3b.o] {
+    fail "warn3b.c with PIC"
+}
+
 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
 foreach t $test_list {
     # We need to strip the ".d", but can leave the dirname.
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index d0c3478..2fc31c8 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -47,7 +47,10 @@ set build_tests {
    {begin.c end.c} {} "libbar.so"}
   {"Build warn libbar.so"
    "-shared" "-fPIC"
-   {beginwarn.c end.c} {} "libbarw.so"}
+   {warn.c} {} "libbarw.so"}
+  {"Build beginwarn.o with PIC"
+   "" "-fPIC"
+   {beginwarn.c} {} "libdummy.a"}
   {"Build hidden libbar.so"
    "-shared" "-fPIC"
    {begin.c endhidden.c} {} "libbarh.so"}
diff --git a/ld/testsuite/ld-elf/warn.c b/ld/testsuite/ld-elf/warn.c
new file mode 100644
index 0000000..8d01db2
--- /dev/null
+++ b/ld/testsuite/ld-elf/warn.c
@@ -0,0 +1,8 @@
+static const char _evoke_link_warning_foo []
+  __attribute__ ((used, section (".gnu.warning.foo")))
+    = "function foo is deprecated";
+
+void
+foo (void)
+{
+}
diff --git a/ld/testsuite/ld-elf/warn3.d b/ld/testsuite/ld-elf/warn3.d
new file mode 100644
index 0000000..65eb6e1
--- /dev/null
+++ b/ld/testsuite/ld-elf/warn3.d
@@ -0,0 +1,15 @@
+#source: empty.s
+#ld: -shared tmpdir/warn3a.o tmpdir/warn3b.o
+#warning: \A[^\n]*warn3a.o: In function `bar':\n[^\n]*warn3a.c:.* warning: function foo is deprecated\Z
+#readelf: -s
+#notarget: "sparc64-*-solaris2*" "sparcv9-*-solaris2*"
+#xfail: arc-*-* d30v-*-* dlx-*-* fr30-*-* frv-*-elf i860-*-* i960-*-*
+#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* or32-*-* pj*-*-*
+# if not using elf32.em, you don't get fancy section handling
+
+# Check that warnings are generated for the symbols in .gnu.warning
+# construct and that the symbol still appears as expected.
+
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9]+ +FUNC +GLOBAL +DEFAULT +[1-9] foo
+#pass
diff --git a/ld/testsuite/ld-elf/warn3a.c b/ld/testsuite/ld-elf/warn3a.c
new file mode 100644
index 0000000..eae278d
--- /dev/null
+++ b/ld/testsuite/ld-elf/warn3a.c
@@ -0,0 +1,7 @@
+extern void foo (void);
+
+void
+bar (void)
+{
+  foo ();
+}
diff --git a/ld/testsuite/ld-elf/warn3b.c b/ld/testsuite/ld-elf/warn3b.c
new file mode 100644
index 0000000..ad82105
--- /dev/null
+++ b/ld/testsuite/ld-elf/warn3b.c
@@ -0,0 +1,5 @@
+static const char _evoke_link_warning_foo []
+  __attribute__ ((used, section (".gnu.warning.foo")))
+    = "function foo is deprecated";
+
+void foo (void) {} 


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