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] Ignore dynamic references on forced local symbols


We should ignore dynamic references on forced local symbols during
garbage collection since they can never be referenced dynamically.

OK for master?

H.J.
---
bfd/

	PR ld/22649
	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Ignore dynamic
	references on forced local symbols.

ld/

	PR ld/22649
	* testsuite/ld-elf/pr22649-1.s: New file.
	* testsuite/ld-elf/pr22649-2a.s: Likewise.
	* testsuite/ld-elf/pr22649-2b.s: Likewise.
	* testsuite/ld-elf/pr22649.msg: Likewise.
	* testsuite/ld-elf/shared.exp: Run ld/22649 tests.
---
 bfd/elflink.c                    |  2 +-
 ld/testsuite/ld-elf/pr22649-1.s  |  4 ++++
 ld/testsuite/ld-elf/pr22649-2a.s |  8 +++++++
 ld/testsuite/ld-elf/pr22649-2b.s |  7 +++++++
 ld/testsuite/ld-elf/pr22649.msg  |  1 +
 ld/testsuite/ld-elf/shared.exp   | 45 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-elf/pr22649-1.s
 create mode 100644 ld/testsuite/ld-elf/pr22649-2a.s
 create mode 100644 ld/testsuite/ld-elf/pr22649-2b.s
 create mode 100644 ld/testsuite/ld-elf/pr22649.msg

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 4c92a048ce..e3751fa122 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13277,7 +13277,7 @@ bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry *h, void *inf)
 
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
-      && (h->ref_dynamic
+      && ((h->ref_dynamic && !h->forced_local)
 	  || ((h->def_regular || ELF_COMMON_DEF_P (h))
 	      && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
 	      && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
diff --git a/ld/testsuite/ld-elf/pr22649-1.s b/ld/testsuite/ld-elf/pr22649-1.s
new file mode 100644
index 0000000000..9a7da7e919
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22649-1.s
@@ -0,0 +1,4 @@
+	.data
+	.globl foo
+foo:
+	.dc.a bar
diff --git a/ld/testsuite/ld-elf/pr22649-2a.s b/ld/testsuite/ld-elf/pr22649-2a.s
new file mode 100644
index 0000000000..b5908b061c
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22649-2a.s
@@ -0,0 +1,8 @@
+	.data
+	.hidden foo
+	.hidden bar
+	.globl foo
+	.globl bar
+foo:
+bar:
+	.dc.a foo
diff --git a/ld/testsuite/ld-elf/pr22649-2b.s b/ld/testsuite/ld-elf/pr22649-2b.s
new file mode 100644
index 0000000000..999686cb65
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22649-2b.s
@@ -0,0 +1,7 @@
+	.data
+	.hidden foo
+	.globl foo
+	.globl bar
+foo:
+bar:
+	.dc.a foo
diff --git a/ld/testsuite/ld-elf/pr22649.msg b/ld/testsuite/ld-elf/pr22649.msg
new file mode 100644
index 0000000000..b4e45bd662
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22649.msg
@@ -0,0 +1 @@
+.*: Removing unused section '\.data' in file 'tmpdir/pr22649-2.*\.o'
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 0c54568879..95bac37900 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -81,6 +81,51 @@ run_ld_link_tests [list \
 	{} \
 	"pr22471" \
     ] \
+    [list \
+	"Build pr22649-1.so" \
+	"$LFLAGS -shared" \
+	"" \
+	"$AFLAGS_PIC" \
+	{pr22649-1.s} \
+	{} \
+	"pr22649-1.so" \
+    ] \
+    [list \
+	"Build pr22649-2a.so" \
+	"$LFLAGS -shared -gc-sections -print-gc-sections" \
+	"" \
+	"$AFLAGS_PIC" \
+	{pr22649-2a.s} \
+	{{ld pr22649.msg}} \
+	"pr22649-2a.so" \
+    ] \
+    [list \
+	"Build pr22649-2b.so" \
+	"$LFLAGS -shared -gc-sections -print-gc-sections" \
+	"tmpdir/pr22649-1.so" \
+	"$AFLAGS_PIC" \
+	{pr22649-2a.s} \
+	{{ld pr22649.msg}} \
+	"pr22649-2b.so" \
+    ] \
+    [list \
+	"Build pr22649-2c.so" \
+	"$LFLAGS -shared -gc-sections -print-gc-sections" \
+	"" \
+	"$AFLAGS_PIC" \
+	{pr22649-2b.s} \
+	{} \
+	"pr22649-2b.so" \
+    ] \
+    [list \
+	"Build pr22649-2d.so" \
+	"$LFLAGS -shared -gc-sections -print-gc-sections" \
+	"tmpdir/pr22649-1.so" \
+	"$AFLAGS_PIC" \
+	{pr22649-2b.s} \
+	{} \
+	"pr22649-2b.so" \
+    ] \
 ]
 
 run_ld_link_tests [list \
-- 
2.14.3


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