Don't add DT_NEEDED for references from the dummy bfd
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 16 Feb 2013 17:54:37 +0000 (17:54 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 16 Feb 2013 17:54:37 +0000 (17:54 +0000)
bfd/

PR ld/15146
* elflink.c (elf_link_add_object_symbols): Don't add DT_NEEDED
for references from the dummy bfd.

ld/

PR ld/15146
* plugin.c (plugin_notice): Replace the undefined dummy bfd with
the real one.

ld/testsuite/

PR ld/15146
* ld-plugin/pr15146.d: New file.
* ld-plugin/pr15146a.c: Likewise.
* ld-plugin/pr15146b.c: Likewise.
* ld-plugin/pr15146c.c: Likewise.
* ld-plugin/pr15146d.c: Likewise.

* ld-plugin/lto.exp: Add tests for PR ld/15146.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/plugin.c
ld/testsuite/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr15146.d [new file with mode: 0644]
ld/testsuite/ld-plugin/pr15146a.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr15146b.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr15146d.c [new file with mode: 0644]

index c6fb5b1b42da540d506163f9a323861981385199..905427f0786003795baa680cee61fa5d0a89168b 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/15146
+       * elflink.c (elf_link_add_object_symbols): Don't add DT_NEEDED
+       for references from the dummy bfd.
+
 2013-02-16  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/15149
index 1a45110597ceee17f561e9f1a4394ea63de00bdd..617c505ffb0abff93893bab5f633a3ab78f395d3 100644 (file)
@@ -4480,10 +4480,13 @@ error_free_dyn:
                break;
              }
 
+         /* Don't add DT_NEEDED for references from the dummy bfd.  */
          if (!add_needed
              && definition
              && ((dynsym
-                  && h->ref_regular)
+                  && h->ref_regular
+                  && (undef_bfd == NULL
+                      || (undef_bfd->flags & BFD_PLUGIN) == 0))
                  || (h->ref_dynamic
                      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
                      && !on_needed_list (elf_dt_name (abfd), htab->needed))))
index c8997592d82ed1b271881a16df990c1cb31351b8..2b390f22128bb1d749b63b96bad69f7dce10a111 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/15146
+       * plugin.c (plugin_notice): Replace the undefined dummy bfd with
+       the real one.
+
 2013-02-16  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/15141
index 435f4663b2bd042f32ea4f445673594d83e6bd96..d880164ded9511d56c038f04f82f54ffbef1ac52 100644 (file)
@@ -993,7 +993,14 @@ plugin_notice (struct bfd_link_info *info,
 
       /* If this is a ref, set non_ir_ref.  */
       else if (bfd_is_und_section (section))
-       h->non_ir_ref = TRUE;
+       {
+         /* Replace the undefined dummy bfd with the real one.  */
+         if ((h->type == bfd_link_hash_undefined
+              || h->type == bfd_link_hash_undefweak)
+             && (h->u.undef.abfd->flags & BFD_PLUGIN) != 0)
+           h->u.undef.abfd = abfd;
+         h->non_ir_ref = TRUE;
+       }
 
       /* Otherwise, it must be a new def.  Ensure any symbol defined
         in an IR dummy BFD takes on a new value from a real BFD.
index dd7ee337f7d546a20af05cacd85a209302d90137..0e5eda476e1e5eeed47038136a5fa14bef4127c6 100644 (file)
@@ -1,3 +1,14 @@
+2013-02-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/15146
+       * ld-plugin/pr15146.d: New file.
+       * ld-plugin/pr15146a.c: Likewise.
+       * ld-plugin/pr15146b.c: Likewise.
+       * ld-plugin/pr15146c.c: Likewise.
+       * ld-plugin/pr15146d.c: Likewise.
+
+       * ld-plugin/lto.exp: Add tests for PR ld/15146.
+
 2013-02-15  Markos Chandras  <markos.chandras@imgtec.com>
 
        * ld-metag/pcrel.d: Fix the expected disassembler
index 365b98800a1596c08d4a49e23da733228616b501..269dde7d2a495d1aee32f7401348dcc64aae160a 100644 (file)
@@ -180,6 +180,24 @@ set lto_link_elf_tests {
   {"PR ld/13244"
    "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto"
    {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"}
+  {"Build libpr15146a.a"
+   "" "-flto -O2"
+   {pr15146a.c} {} "lib15146a.a"}
+  {"Build pr15146b.so"
+   "-shared" "-O2 -fpic"
+   {pr15146b.c} {} "pr15146b.so" "c"}
+  {"Build pr15146c.so"
+   "-shared tmpdir/pr15146b.so" "-O2 -fpic"
+   {pr15146c.c} {} "pr15146c.so" "c"}
+  {"PR ld/15146 (1)"
+   "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries tmpdir/pr15146a.o tmpdir/pr15146c.so" ""
+   {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"}
+  {"Build libpr15146d.a"
+   "" "-flto -O2"
+   {pr15146d.c} {} "lib15146d.a"}
+  {"Build libpr15146d.a"
+   "" "-flto -O2"
+   {pr15146d.c} {} "lib15146d.a"}
 }
 
 # Check final symbols in executables.
@@ -269,6 +287,13 @@ run_cc_link_tests $lto_link_tests
 if { [is_elf_format]
      && [run_host_cmd_yesno $CC "-shared -fPIC $srcdir/$subdir/dummy.c -o tmpdir/t.so"] } {
     run_cc_link_tests $lto_link_elf_tests
+    set testname "PR ld/15146 (2)"
+    set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries tmpdir/pr15146d.o tmpdir/pr15146c.so"]
+    if { [ regexp "ltrans.o: undefined reference to symbol 'xxx'" $exec_output ] } {
+       pass $testname
+    } {
+       fail $testname
+    }
 }
 
 set testname "Build liblto-11.a"
diff --git a/ld/testsuite/ld-plugin/pr15146.d b/ld/testsuite/ld-plugin/pr15146.d
new file mode 100644 (file)
index 0000000..48d4b85
--- /dev/null
@@ -0,0 +1,4 @@
+#failif
+#...
+ +0x[0-9a-f]+ +\(NEEDED\) +Shared library: +\[.*pr15146b.so\]
+#...
diff --git a/ld/testsuite/ld-plugin/pr15146a.c b/ld/testsuite/ld-plugin/pr15146a.c
new file mode 100644 (file)
index 0000000..a22860a
--- /dev/null
@@ -0,0 +1,13 @@
+extern int xxx;
+
+int
+bar (void)
+{
+  return xxx;
+}
+
+int
+main ()
+{ 
+  return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr15146b.c b/ld/testsuite/ld-plugin/pr15146b.c
new file mode 100644 (file)
index 0000000..90eb21e
--- /dev/null
@@ -0,0 +1 @@
+int xxx = 3;
diff --git a/ld/testsuite/ld-plugin/pr15146d.c b/ld/testsuite/ld-plugin/pr15146d.c
new file mode 100644 (file)
index 0000000..ba1e0ab
--- /dev/null
@@ -0,0 +1,7 @@
+extern int xxx;
+
+int
+main ()
+{ 
+  return xxx;
+}