public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: binutils@sourceware.org
Subject: PATCH: PR ld/12761: .gnu.warning.* doesn't work when building shared library
Date: Mon, 16 May 2011 19:05:00 -0000	[thread overview]
Message-ID: <20110516190512.GA10653@intel.com> (raw)

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) {} 

             reply	other threads:[~2011-05-16 19:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-16 19:05 H.J. Lu [this message]
2011-05-17  1:51 ` Alan Modra
2011-05-17  6:04 ` Ian Lance Taylor
2011-05-17 13:12   ` H.J. Lu
2011-05-17 14:30     ` Ian Lance Taylor
2011-05-17 14:36       ` H.J. Lu
2011-05-17 15:02         ` Ian Lance Taylor
2011-05-17 15:05           ` H.J. Lu
2011-05-17 16:34             ` Ian Lance Taylor

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=20110516190512.GA10653@intel.com \
    --to=hongjiu.lu@intel.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).