public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Subject: [PATCH] Don't complain undefined weak dynamic reference
Date: Thu, 25 Apr 2019 21:20:00 -0000	[thread overview]
Message-ID: <20190425212000.4919-1-hjl.tools@gmail.com> (raw)

When undefined non-weak references in IR objects are optimized out
by LTO, we can have weak dynamic referencs to symbols marked with
bfd_link_hash_undefined.  We shouldn't complain such undefined weak
dynamic references.

bfd/

	PR ld/24486
	* elflink.c (elf_link_output_extsym): Don't complain undefined
	weak dynamic reference.

ld/

	PR ld/24486
	* testsuite/ld-plugin/lto.exp: Run PR ld/24486 tests.
	* testsuite/ld-plugin/pr24486a.c: New file.
	* testsuite/ld-plugin/pr24486b.c: Likewise.
	* testsuite/ld-plugin/pr24486c.c: Likewise.
---
 bfd/elflink.c                     |  2 +-
 ld/testsuite/ld-plugin/lto.exp    | 12 ++++++++++++
 ld/testsuite/ld-plugin/pr24486a.c |  8 ++++++++
 ld/testsuite/ld-plugin/pr24486b.c |  8 ++++++++
 ld/testsuite/ld-plugin/pr24486c.c |  1 +
 5 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-plugin/pr24486a.c
 create mode 100644 ld/testsuite/ld-plugin/pr24486b.c
 create mode 100644 ld/testsuite/ld-plugin/pr24486c.c

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 81e667dab0..ddeaa08d50 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -9776,7 +9776,7 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
 
       /* If we are reporting errors for this situation then do so now.  */
       if (!ignore_undef
-	  && h->ref_dynamic
+	  && h->ref_dynamic_nonweak
 	  && (!h->ref_regular || flinfo->info->gc_sections)
 	  && !elf_link_check_versioned_symbol (flinfo->info, bed, h)
 	  && flinfo->info->unresolved_syms_in_shared_libs != RM_IGNORE)
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index b13a77333f..e913c6f203 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -325,6 +325,18 @@ set lto_link_elf_tests [list \
   [list {Build pr22220main.o} \
    {} {-flto} \
    {pr22220main.cc} {} {} {c++}] \
+  [list "Build pr24486a.o" \
+   "$plug_opt" "-flto -O2" \
+   {pr24486a.c} {} "" "c"] \
+  [list "Build pr24486b.so" \
+   "-shared" "-O2 -fpic" \
+   {pr24486b.c} {} "pr24486b.so" "c"] \
+  [list "Build pr24486c.so" \
+   "-shared -Wl,--no-as-needed tmpdir/pr24486b.so" "-O2 -fpic" \
+   {pr24486c.c} {} "pr24486c.so" "c"] \
+  [list "PR ld/24486" \
+   "-O2 -flto tmpdir/pr24486a.o tmpdir/pr24486c.so -Wl,--as-needed tmpdir/pr24486b.so" "" \
+   {dummy.c} {} "pr24486.exe"] \
 ]
 
 # PR 14918 checks that libgcc is not spuriously included in a shared link of
diff --git a/ld/testsuite/ld-plugin/pr24486a.c b/ld/testsuite/ld-plugin/pr24486a.c
new file mode 100644
index 0000000000..def0139598
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr24486a.c
@@ -0,0 +1,8 @@
+extern int FLAGS_verbose;
+extern void bar (void);
+int
+a(void) {
+return FLAGS_verbose;
+}
+void unused (void) { bar(); }
+int main() { return a (); }
diff --git a/ld/testsuite/ld-plugin/pr24486b.c b/ld/testsuite/ld-plugin/pr24486b.c
new file mode 100644
index 0000000000..3aabe2a395
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr24486b.c
@@ -0,0 +1,8 @@
+extern void bar (void) __attribute__((weak));
+
+void
+foo (void)
+{
+  if (bar)
+    bar ();
+}
diff --git a/ld/testsuite/ld-plugin/pr24486c.c b/ld/testsuite/ld-plugin/pr24486c.c
new file mode 100644
index 0000000000..f289177d3e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr24486c.c
@@ -0,0 +1 @@
+int FLAGS_verbose;
-- 
2.20.1

             reply	other threads:[~2019-04-25 21:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 21:20 H.J. Lu [this message]
2019-04-25 23:38 ` Alan Modra

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=20190425212000.4919-1-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    /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).