public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: binutils@sourceware.org
Subject: Re: [PATCH] PR ld/21389: Put soname in the version definition section
Date: Fri, 14 Apr 2017 21:47:00 -0000	[thread overview]
Message-ID: <20170414214740.GA18613@intel.com> (raw)
In-Reply-To: <20170414201951.GA15854@intel.com>

On Fri, Apr 14, 2017 at 01:19:51PM -0700, H.J. Lu wrote:
> Get soname index before generating the version definition section.
> 
> OK for master and 2.28 branch?
> 
> H.J.
> ---
> bfd/
> 
> 	PR ld/21389
> 	* elflink.c (bfd_elf_size_dynamic_sections): Get soname index
> 	before generating the version definition section.
> 

Updated patch to fix missing SONAME.


H.J.
--
Get soname index before generating the version definition section.

bfd/

	PR ld/21389
	* elflink.c (bfd_elf_size_dynamic_sections): Get soname index
	before generating the version definition section.

ld/

	PR ld/21389
	* testsuite/ld-elf/pr21389.map: New file.
	* testsuite/ld-elf/pr21389.s: Likewise.
	* testsuite/ld-elf/pr21389a.d: Likewise.
	* testsuite/ld-elf/pr21389b.d: Likewise.
	* testsuite/ld-elf/pr21389c.d: Likewise.
---
 bfd/elflink.c                   | 24 ++++++++++++------------
 ld/testsuite/ld-elf/pr21389.map |  6 ++++++
 ld/testsuite/ld-elf/pr21389.s   |  5 +++++
 ld/testsuite/ld-elf/pr21389a.d  | 10 ++++++++++
 ld/testsuite/ld-elf/pr21389b.d  |  8 ++++++++
 ld/testsuite/ld-elf/pr21389c.d  |  8 ++++++++
 6 files changed, 49 insertions(+), 12 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/pr21389.map
 create mode 100644 ld/testsuite/ld-elf/pr21389.s
 create mode 100644 ld/testsuite/ld-elf/pr21389a.d
 create mode 100644 ld/testsuite/ld-elf/pr21389b.d
 create mode 100644 ld/testsuite/ld-elf/pr21389c.d

diff --git a/bfd/elflink.c b/bfd/elflink.c
index dfcc51e..ad2e4e6 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -5921,14 +5921,11 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
 			       struct bfd_link_info *info,
 			       asection **sinterpptr)
 {
-  size_t soname_indx;
   bfd *dynobj;
   const struct elf_backend_data *bed;
 
   *sinterpptr = NULL;
 
-  soname_indx = (size_t) -1;
-
   if (!is_elf_hash_table (info->hash))
     return TRUE;
 
@@ -5943,6 +5940,7 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
       struct elf_info_failed eif;
       bfd_boolean all_defined;
       asection *s;
+      size_t soname_indx;
 
       eif.info = info;
       eif.failed = FALSE;
@@ -5959,6 +5957,17 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
 	    return FALSE;
 	}
 
+      if (soname != NULL)
+	{
+	  soname_indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
+					     soname, TRUE);
+	  if (soname_indx == (size_t) -1
+	      || !_bfd_elf_add_dynamic_entry (info, DT_SONAME, soname_indx))
+	    return FALSE;
+	}
+      else
+	soname_indx = (size_t) -1;
+
       /* Make all global versions with definition.  */
       for (t = info->version_info; t != NULL; t = t->next)
 	for (d = t->globals.list; d != NULL; d = d->next)
@@ -6467,15 +6476,6 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
       *sinterpptr = bfd_get_linker_section (dynobj, ".interp");
       BFD_ASSERT (*sinterpptr != NULL || !bfd_link_executable (info) || info->nointerp);
 
-      if (soname != NULL)
-	{
-	  soname_indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
-					     soname, TRUE);
-	  if (soname_indx == (size_t) -1
-	      || !_bfd_elf_add_dynamic_entry (info, DT_SONAME, soname_indx))
-	    return FALSE;
-	}
-
       if (info->symbolic)
 	{
 	  if (!_bfd_elf_add_dynamic_entry (info, DT_SYMBOLIC, 0))
diff --git a/ld/testsuite/ld-elf/pr21389.map b/ld/testsuite/ld-elf/pr21389.map
new file mode 100644
index 0000000..88c8c28
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21389.map
@@ -0,0 +1,6 @@
+FOO {
+global:
+  foo;
+local:
+  *;
+};
diff --git a/ld/testsuite/ld-elf/pr21389.s b/ld/testsuite/ld-elf/pr21389.s
new file mode 100644
index 0000000..a943cc6
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21389.s
@@ -0,0 +1,5 @@
+	.globl foo
+	.type foo,%object
+	.data
+foo:
+	.long	0
diff --git a/ld/testsuite/ld-elf/pr21389a.d b/ld/testsuite/ld-elf/pr21389a.d
new file mode 100644
index 0000000..2dcd175
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21389a.d
@@ -0,0 +1,10 @@
+#source: pr21389.s
+#ld: -shared --version-script pr21389.map -soname=pr21389.so
+#objdump: -p
+#target: *-*-linux* *-*-gnu*
+
+#...
+Version definitions:
+1 0x01 0x[0-9a-f]* pr21389.so
+2 0x00 0x[0-9a-f]* FOO
+#pass
diff --git a/ld/testsuite/ld-elf/pr21389b.d b/ld/testsuite/ld-elf/pr21389b.d
new file mode 100644
index 0000000..8dbc34b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21389b.d
@@ -0,0 +1,8 @@
+#source: pr21389.s
+#ld: -shared --version-script pr21389.map -soname=pr21389.so
+#readelf: -d
+#target: *-*-linux* *-*-gnu*
+
+#...
+ 0x[0-9a-f]* \(SONAME\) +Library soname: \[pr21389.so\]
+#pass
diff --git a/ld/testsuite/ld-elf/pr21389c.d b/ld/testsuite/ld-elf/pr21389c.d
new file mode 100644
index 0000000..76ac37b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21389c.d
@@ -0,0 +1,8 @@
+#source: pr21389.s
+#ld: -shared -soname=pr21389.so
+#readelf: -d
+#target: *-*-linux* *-*-gnu*
+
+#...
+ 0x[0-9a-f]* \(SONAME\) +Library soname: \[pr21389.so\]
+#pass
-- 
2.9.3

  reply	other threads:[~2017-04-14 21:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-14 20:19 H.J. Lu
2017-04-14 21:47 ` H.J. Lu [this message]
2017-04-15  9:18   ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170414214740.GA18613@intel.com \
    --to=hongjiu.lu@intel.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).