Don't complain undefined weak dynamic reference
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 26 Apr 2019 14:52:00 +0000 (07:52 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 26 Apr 2019 14:52:09 +0000 (07:52 -0700)
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/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr24486a.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr24486b.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr24486c.c [new file with mode: 0644]

index 7539773..b39197d 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/24486
+       * elflink.c (elf_link_output_extsym): Don't complain undefined
+       weak dynamic reference.
+
 2019-04-25  Sudakshina Das  <sudi.das@arm.com>
 
        * elfnn-aarch64.c (PLT_BTI_ENTRY_SIZE): Remove.
index 81e667d..ddeaa08 100644 (file)
@@ -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)
index dcdbfef..fed72c8 100644 (file)
@@ -1,3 +1,11 @@
+2019-04-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       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.
+
 2019-04-26  Nick Clifton  <nickc@redhat.com>
 
        * po/ru.po: Updated Russian translation.
index b13a773..e913c6f 100644 (file)
@@ -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 (file)
index 0000000..def0139
--- /dev/null
@@ -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 (file)
index 0000000..3aabe2a
--- /dev/null
@@ -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 (file)
index 0000000..f289177
--- /dev/null
@@ -0,0 +1 @@
+int FLAGS_verbose;