public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [committed, PATCH] Check reloc against IFUNC symbol only with dynamic symbols
@ 2016-01-31  0:09 H.J. Lu
  2016-03-15 12:29 ` H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2016-01-31  0:09 UTC (permalink / raw)
  To: binutils

There is no need to check relocation IFUNC symbol if there are no
dynamic symbols.

bfd/

	PR ld/19539
	* elf32-i386.c (elf_i386_reloc_type_class): Check relocation
	against STT_GNU_IFUNC symbol only with dynamic symbols.
	* elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise.

ld/

	PR ld/19539
	* testsuite/ld-elf/pr19539.d: New file.
	* testsuite/ld-elf/pr19539.s: Likewise.
	* testsuite/ld-elf/pr19539.t: Likewise.
---
 bfd/ChangeLog                 |  7 +++++++
 bfd/elf32-i386.c              | 28 ++++++++++++++++------------
 bfd/elf64-x86-64.c            | 28 ++++++++++++++++------------
 ld/ChangeLog                  |  7 +++++++
 ld/testsuite/ld-elf/pr19539.d |  8 ++++++++
 ld/testsuite/ld-elf/pr19539.s |  2 ++
 ld/testsuite/ld-elf/pr19539.t |  1 +
 7 files changed, 57 insertions(+), 24 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/pr19539.d
 create mode 100644 ld/testsuite/ld-elf/pr19539.s
 create mode 100644 ld/testsuite/ld-elf/pr19539.t

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 7c46423..d6e4d03 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2016-01-30  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/19539
+	* elf32-i386.c (elf_i386_reloc_type_class): Check relocation
+	against STT_GNU_IFUNC symbol only with dynamic symbols.
+	* elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise.
+
 2016-01-28  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR binutils/19523
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 5bf715f..81a95e0 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -5355,19 +5355,23 @@ elf_i386_reloc_type_class (const struct bfd_link_info *info,
   bfd *abfd = info->output_bfd;
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   struct elf_link_hash_table *htab = elf_hash_table (info);
-  unsigned long r_symndx = ELF32_R_SYM (rela->r_info);
-  Elf_Internal_Sym sym;
-
-  if (htab->dynsym == NULL
-      || !bed->s->swap_symbol_in (abfd,
-				  (htab->dynsym->contents
-				   + r_symndx * sizeof (Elf32_External_Sym)),
-				  0, &sym))
-    abort ();
 
-  /* Check relocation against STT_GNU_IFUNC symbol.  */
-  if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
-    return reloc_class_ifunc;
+  if (htab->dynsym != NULL
+      && htab->dynsym->contents != NULL)
+    {
+      /* Check relocation against STT_GNU_IFUNC symbol if there are
+         dynamic symbols.  */
+      unsigned long r_symndx = ELF32_R_SYM (rela->r_info);
+      Elf_Internal_Sym sym;
+      if (!bed->s->swap_symbol_in (abfd,
+				   (htab->dynsym->contents
+				    + r_symndx * sizeof (Elf32_External_Sym)),
+				   0, &sym))
+	abort ();
+
+      if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
+	return reloc_class_ifunc;
+    }
 
   switch (ELF32_R_TYPE (rela->r_info))
     {
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index bbdb03a..37528be 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -5728,19 +5728,23 @@ elf_x86_64_reloc_type_class (const struct bfd_link_info *info,
   bfd *abfd = info->output_bfd;
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info);
-  unsigned long r_symndx = htab->r_sym (rela->r_info);
-  Elf_Internal_Sym sym;
-
-  if (htab->elf.dynsym == NULL
-      || !bed->s->swap_symbol_in (abfd,
-				  (htab->elf.dynsym->contents
-				   + r_symndx * bed->s->sizeof_sym),
-				  0, &sym))
-    abort ();
 
-  /* Check relocation against STT_GNU_IFUNC symbol.  */
-  if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
-    return reloc_class_ifunc;
+  if (htab->elf.dynsym != NULL
+      && htab->elf.dynsym->contents != NULL)
+    {
+      /* Check relocation against STT_GNU_IFUNC symbol if there are
+         dynamic symbols.  */
+      unsigned long r_symndx = htab->r_sym (rela->r_info);
+      Elf_Internal_Sym sym;
+      if (!bed->s->swap_symbol_in (abfd,
+				   (htab->elf.dynsym->contents
+				    + r_symndx * bed->s->sizeof_sym),
+				   0, &sym))
+	abort ();
+
+      if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
+	return reloc_class_ifunc;
+    }
 
   switch ((int) ELF32_R_TYPE (rela->r_info))
     {
diff --git a/ld/ChangeLog b/ld/ChangeLog
index b9eac34..34b4feb 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2016-01-30  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/19539
+	* testsuite/ld-elf/pr19539.d: New file.
+	* testsuite/ld-elf/pr19539.s: Likewise.
+	* testsuite/ld-elf/pr19539.t: Likewise.
+
 2016-01-29  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR ld/19533
diff --git a/ld/testsuite/ld-elf/pr19539.d b/ld/testsuite/ld-elf/pr19539.d
new file mode 100644
index 0000000..363aeee
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19539.d
@@ -0,0 +1,8 @@
+#source: start.s
+#source: pr19539.s
+#ld: -pie -T pr19539.t
+#readelf : --dyn-syms --wide
+#target: *-*-linux* *-*-gnu* *-*-solaris*
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+#pass
diff --git a/ld/testsuite/ld-elf/pr19539.s b/ld/testsuite/ld-elf/pr19539.s
new file mode 100644
index 0000000..0f55d3f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19539.s
@@ -0,0 +1,2 @@
+	.section .prefix,"a",%progbits
+	.dc.a foo
diff --git a/ld/testsuite/ld-elf/pr19539.t b/ld/testsuite/ld-elf/pr19539.t
new file mode 100644
index 0000000..b6b48e7
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19539.t
@@ -0,0 +1 @@
+HIDDEN (foo = .);
-- 
2.5.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [committed, PATCH] Check reloc against IFUNC symbol only with dynamic symbols
  2016-01-31  0:09 [committed, PATCH] Check reloc against IFUNC symbol only with dynamic symbols H.J. Lu
@ 2016-03-15 12:29 ` H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2016-03-15 12:29 UTC (permalink / raw)
  To: Binutils

On Sat, Jan 30, 2016 at 4:09 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> There is no need to check relocation IFUNC symbol if there are no
> dynamic symbols.
>
> bfd/
>
>         PR ld/19539
>         * elf32-i386.c (elf_i386_reloc_type_class): Check relocation
>         against STT_GNU_IFUNC symbol only with dynamic symbols.
>         * elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise.
>
> ld/
>
>         PR ld/19539
>         * testsuite/ld-elf/pr19539.d: New file.
>         * testsuite/ld-elf/pr19539.s: Likewise.
>         * testsuite/ld-elf/pr19539.t: Likewise.

I backported it to 2.26 branch.


-- 
H.J.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-15 12:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-31  0:09 [committed, PATCH] Check reloc against IFUNC symbol only with dynamic symbols H.J. Lu
2016-03-15 12:29 ` 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).