Check reloc against IFUNC symbol only with dynamic symbols
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 30 Jan 2016 22:11:03 +0000 (14:11 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 31 Jan 2016 00:08:20 +0000 (16:08 -0800)
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
bfd/elf32-i386.c
bfd/elf64-x86-64.c
ld/ChangeLog
ld/testsuite/ld-elf/pr19539.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr19539.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr19539.t [new file with mode: 0644]

index 7c4642369982dddcdfaffc3c54a661446e8c8c68..d6e4d03dd2b0b3f9d74c5b7a1bc10133152dc63b 100644 (file)
@@ -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
index 5bf715fc7d2570c52bd96756dd3acce265ad1115..81a95e0cf29aa2e6e9277e2702c93727d5036f60 100644 (file)
@@ -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))
     {
index bbdb03a58cfaba82a57b196d253555a07abac508..37528beed436b942db52c214d22a527b69213ade 100644 (file)
@@ -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))
     {
index b9eac34704222431b93c795cfaa1a3c02c243767..34b4feb112a9b6c987108ef078875c5a3698b6ee 100644 (file)
@@ -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 (file)
index 0000000..363aeee
--- /dev/null
@@ -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 (file)
index 0000000..0f55d3f
--- /dev/null
@@ -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 (file)
index 0000000..b6b48e7
--- /dev/null
@@ -0,0 +1 @@
+HIDDEN (foo = .);
This page took 0.034672 seconds and 4 git commands to generate.