public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Check the DYNAMIC bit for input shared objects
@ 2017-06-19 22:16 H.J. Lu
  0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2017-06-19 22:16 UTC (permalink / raw)
  To: binutils

Since the BFD section count may not be cleared for shared objects during
linking, we should check the DYNAMIC bit for input shared objects.

I will check it in shortly.


H.J.
---
bfd/

	PR ld/21626
	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Check
	the DYNAMIC bit instead of bfd_count_sections.

ld/

	PR ld/21626
	* testsuite/ld-i386/i386.exp: Run ld/21626 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
---
 bfd/elf-properties.c              |  4 ++--
 ld/testsuite/ld-i386/i386.exp     | 18 ++++++++++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp | 18 ++++++++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
index 2d054dd..13d620d 100644
--- a/bfd/elf-properties.c
+++ b/bfd/elf-properties.c
@@ -318,7 +318,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
   /* Find the first relocatable ELF input with GNU properties.  */
   for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
     if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
-	&& bfd_count_sections (abfd) != 0
+	&& (abfd->flags & DYNAMIC) == 0
 	&& elf_properties (abfd) != NULL)
       {
 	has_properties = TRUE;
@@ -342,7 +342,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 
   /* Merge .note.gnu.property sections.  */
   for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
-    if (abfd != first_pbfd && bfd_count_sections (abfd) != 0)
+    if (abfd != first_pbfd && (abfd->flags & DYNAMIC) == 0)
       {
 	elf_property_list *null_ptr = NULL;
 	elf_property_list **listp = &null_ptr;
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index a92bd91..2e3c224 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -1182,6 +1182,24 @@ run_ld_link_tests [list \
 	{{objdump -dwr plt-pic2.dd}} \
 	"plt-pic2.so" \
     ] \
+    [list \
+	"Build pr21626.so" \
+	"-shared -melf_i386" \
+	"" \
+	"--32" \
+	{property-x86-3.s} \
+	"" \
+	"pr21626.so" \
+    ] \
+    [list \
+	"Build pr21626" \
+	"-melf_i386 tmpdir/pr21626.so" \
+	"" \
+	"--32" \
+	{start.s foo.s} \
+	"" \
+	"pr21626" \
+    ] \
 ]
 
 # Linux only tests
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 079c161..48d8ad2 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -1368,6 +1368,24 @@ run_ld_link_tests [list \
 	{{readelf -SW plt2.rd} {objdump -dwr plt2.dd}} \
 	"plt2" \
     ] \
+    [list \
+	"Build pr21626.so" \
+	"-shared -melf_x86_64" \
+	"" \
+	"--64 -defsym __64_bit__=1" \
+	{property-x86-3.s} \
+	"" \
+	"pr21626.so" \
+    ] \
+    [list \
+	"Build pr21626" \
+	"-melf_x86_64 tmpdir/pr21626.so" \
+	"" \
+	"--64" \
+	{start.s foo.s} \
+	"" \
+	"pr21626" \
+    ] \
 ]
 
 # Linux only tests
-- 
2.9.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-19 22:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 22:16 [PATCH] Check the DYNAMIC bit for input shared objects H.J. Lu

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).