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/15149: Weak reference leads to DT_NEEDED entry


We shouldn't add DT_NEEDED for weak references unless asked.  This
patch implements it.  OK to install?

Thanks.


H.J.
---
bfd/

2013-02-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/15149
	* elflink.c (elf_link_add_object_symbols): Don't add DT_NEEDED for
	weak references, unless the dynamic object is specified on the
	command line.

ld/testsuite/

2013-02-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/15149
	* ld/testsuite/ld-elf/dummy.s: New file.
	* ld/testsuite/ld-elf/pr15149.rd: Likewise.
	* ld/testsuite/ld-elf/pr15149a.s: Likewise.
	* ld/testsuite/ld-elf/pr15149b.s: Likewise.

	* ld-elf/elf.exp: Add PR ld/15149 test.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index d423ca4..05d5746 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -4477,10 +4477,14 @@ error_free_dyn:
 		break;
 	      }
 
+	  /* Don't add DT_NEEDED for weak references, unless the dynamic
+	     object is specified on the command line.  */
 	  if (!add_needed
 	      && definition
 	      && ((dynsym
-		   && h->ref_regular)
+		   && (h->ref_regular_nonweak
+		       || (h->ref_regular
+			   && (elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) == 0)))
 		  || (h->ref_dynamic
 		      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
 		      && !on_needed_list (elf_dt_name (abfd), htab->needed))))
diff --git a/ld/testsuite/ld-elf/dummy.s b/ld/testsuite/ld-elf/dummy.s
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/ld/testsuite/ld-elf/dummy.s
@@ -0,0 +1 @@
+
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index 50634c6..f198333 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -66,6 +66,7 @@ if { ![istarget hppa64*-hpux*] } {
     if { [check_shared_lib_support] } then {
 	run_ld_link_tests {
 	    {"Build pr14170a.o" "" "" "pr14170a.s" {} "pr14170.a" }
+	    {"Build pr15149a.o" "" "" "pr15149a.s" {} "pr15149.a" }
 	}
 	setup_xfail "tic6x-*-*"
 	run_ld_link_tests {
@@ -74,6 +75,13 @@ if { ![istarget hppa64*-hpux*] } {
 	    {"PR ld/14170"
 		"tmpdir/pr14170a.o tmpdir/pr14170.so" "" "pr14170c.s"
 		{ } "pr14170" }
+	    {"Build shared library pr15149b.so"
+		"-shared" "" "pr15149b.s" {} "pr15149b.so" }
+	    {"Build shared library pr15149a.so"
+		"-shared --no-as-needed tmpdir/pr15149b.so" "" "empty.s" {} "pr15149a.so" }
+	    {"PR ld/15149"
+		"tmpdir/pr15149a.o -rpath-link . tmpdir/pr15149a.so" "" "dummy.s"
+		{{readelf {-d} pr15149.rd}} "pr15149" }
 	}
     }
 }
diff --git a/ld/testsuite/ld-elf/pr15149.rd b/ld/testsuite/ld-elf/pr15149.rd
new file mode 100644
index 0000000..e175452
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr15149.rd
@@ -0,0 +1,4 @@
+#failif
+#...
+ +0x[0-9a-f]+ +\(NEEDED\) +Shared library: +\[.*pr15149b.so\]
+#...
diff --git a/ld/testsuite/ld-elf/pr15149a.s b/ld/testsuite/ld-elf/pr15149a.s
new file mode 100644
index 0000000..74de3d3
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr15149a.s
@@ -0,0 +1,12 @@
+	.text
+	.global start	/* Used by SH targets.  */
+start:
+	.global _start
+_start:
+	.global __start
+__start:
+	.global main	/* Used by HPPA targets.  */
+main:
+	.data
+	.weak foo
+	.dc.a foo
diff --git a/ld/testsuite/ld-elf/pr15149b.s b/ld/testsuite/ld-elf/pr15149b.s
new file mode 100644
index 0000000..f3dd56c
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr15149b.s
@@ -0,0 +1,6 @@
+	.data
+	.type foo,%object
+	.globl foo
+foo:
+	.dc.a 0
+	.size	foo, . - foo


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