]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Don't set eh->local_ref to 1 for linker defined symbols
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 18 May 2018 13:43:19 +0000 (06:43 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 21 May 2018 15:23:51 +0000 (08:23 -0700)
Since symbols created by HIDDEN and PROVIDE_HIDDEN assignments in
linker script may be marked as defined, but not hidden, we can't
set eh->local_ref to 1 in _bfd_x86_elf_link_symbol_references_local.

Also R_386_GOT32X should be handled as just like R_386_GOT32 when
relocating a section.  The input R_386_GOT32X relocations, which
can be relaxed, should have been converted to R_386_PC32, R_386_32
or R_386_GOTOFF.

bfd/

PR ld/23189
* elf32-i386.c (elf_i386_relocate_section): Handle R_386_GOT32X
like R_386_GOT32.
* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
set eh->local_ref to 1 for linker defined symbols.

ld/

PR ld/23189
* testsuite/ld-i386/i386.exp: Run pr23189.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr23189.d: New file.
* testsuite/ld-i386/pr23189.s: Likewise.
* testsuite/ld-i386/pr23189.t: Likewise.
* testsuite/ld-x86-64/pr23189.d: Likewise.
* testsuite/ld-x86-64/pr23189.s: Likewise.
* testsuite/ld-x86-64/pr23189.t: Likewise.

(cherry picked from commit 011b32fd4270fb7111ee1f63695ccd44562ee7df)

12 files changed:
bfd/ChangeLog
bfd/elf32-i386.c
bfd/elfxx-x86.c
ld/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr23189.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr23189.s [new file with mode: 0644]
ld/testsuite/ld-i386/pr23189.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23189.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23189.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23189.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index f815f9055886a94dc808774d4b9c56af1a5ccc09..c491ed77aeead9c754cdd7d0c9c33af89f273646 100644 (file)
@@ -1,3 +1,11 @@
+2018-05-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/23189
+       * elf32-i386.c (elf_i386_relocate_section): Handle R_386_GOT32X
+       like R_386_GOT32.
+       * elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
+       set eh->local_ref to 1 for linker defined symbols.
+
 2018-05-18  Alan Modra  <amodra@gmail.com>
 
        PR 23199
index ba567a4440ef52df018d7254cfbc8d05e7d50360..20e4c74643a6475af1e316e983b51166aa2d2bfc 100644 (file)
@@ -2442,66 +2442,7 @@ do_ifunc_pointer:
       switch (r_type)
        {
        case R_386_GOT32X:
-         /* Avoid optimizing _DYNAMIC since ld.so may use its
-            link-time address.  */
-         if (h == htab->elf.hdynamic)
-           goto r_386_got32;
-
-         if (bfd_link_pic (info))
-           {
-             /* It is OK to convert mov to lea and convert indirect
-                branch to direct branch.  It is OK to convert adc,
-                add, and, cmp, or, sbb, sub, test, xor only when PIC
-                is false.   */
-             unsigned int opcode, addend;
-             addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
-             if (addend != 0)
-               goto r_386_got32;
-             opcode = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
-             if (opcode != 0x8b && opcode != 0xff)
-               goto r_386_got32;
-           }
-
-         /* Resolve "mov GOT[(%reg)], %reg",
-            "call/jmp *GOT[(%reg)]", "test %reg, foo@GOT[(%reg)]"
-            and "binop foo@GOT[(%reg)], %reg".  */
-         if (h == NULL
-             || (h->plt.offset == (bfd_vma) -1
-                 && h->got.offset == (bfd_vma) -1)
-             || htab->elf.sgotplt == NULL)
-           abort ();
-
-         offplt = (htab->elf.sgotplt->output_section->vma
-                   + htab->elf.sgotplt->output_offset);
-
-         /* It is relative to .got.plt section.  */
-         if (h->got.offset != (bfd_vma) -1)
-           /* Use GOT entry.  Mask off the least significant bit in
-              GOT offset which may be set by R_386_GOT32 processing
-              below.  */
-           relocation = (htab->elf.sgot->output_section->vma
-                         + htab->elf.sgot->output_offset
-                         + (h->got.offset & ~1) - offplt);
-         else
-           /* Use GOTPLT entry.  */
-           relocation = (h->plt.offset / plt_entry_size
-                         - htab->plt.has_plt0 + 3) * 4;
-
-         if (!bfd_link_pic (info))
-           {
-             /* If not PIC, add the .got.plt section address for
-                baseless addressing.  */
-             unsigned int modrm;
-             modrm = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
-             if ((modrm & 0xc7) == 0x5)
-               relocation += offplt;
-           }
-
-         unresolved_reloc = FALSE;
-         break;
-
        case R_386_GOT32:
-r_386_got32:
          /* Relocation is to the entry for this symbol in the global
             offset table.  */
          if (htab->elf.sgot == NULL)
index fc08d1b977fc9a238bc57693caefd267bf5a656c..8f0523dbe9b85dd0cd878bafd876a8447a3abe49 100644 (file)
@@ -1966,7 +1966,11 @@ _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info *info,
       return TRUE;
     }
 
-  eh->local_ref = 1;
+  /* Symbols created by HIDDEN and PROVIDE_HIDDEN assignments in linker
+     script aren't forced local here yet.  */
+  if (!h->root.ldscript_def)
+    eh->local_ref = 1;
+
   return FALSE;
 }
 
index 5355cc3f46b95086c4dd2f8a91cf5a0fd3d1ebe5..54609215480653ca852d95c274935c99b132c840 100644 (file)
@@ -1,3 +1,15 @@
+2018-05-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/23189
+       * testsuite/ld-i386/i386.exp: Run pr23189.
+       * testsuite/ld-x86-64/x86-64.exp: Likewise.
+       * testsuite/ld-i386/pr23189.d: New file.
+       * testsuite/ld-i386/pr23189.s: Likewise.
+       * testsuite/ld-i386/pr23189.t: Likewise.
+       * testsuite/ld-x86-64/pr23189.d: Likewise.
+       * testsuite/ld-x86-64/pr23189.s: Likewise.
+       * testsuite/ld-x86-64/pr23189.t: Likewise.
+
 2018-02-05  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22782
index e4ec07d0e97712c68bfa837ae38350c413f42aba..b01ab26370450894062545d6546992b2edb9b94d 100644 (file)
@@ -451,6 +451,7 @@ run_dump_test "pr22115-1c"
 run_dump_test "pr22115-1d"
 run_dump_test "pr22135"
 run_dump_test "pr22782"
+run_dump_test "pr23189"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr23189.d b/ld/testsuite/ld-i386/pr23189.d
new file mode 100644 (file)
index 0000000..9345b42
--- /dev/null
@@ -0,0 +1,7 @@
+#as: --32  -mrelax-relocations=yes
+#ld: -shared -melf_i386 -T pr23189.t
+#readelf: -r --wide
+
+Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
+ Offset     Info    Type                Sym. Value  Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_RELATIVE +
diff --git a/ld/testsuite/ld-i386/pr23189.s b/ld/testsuite/ld-i386/pr23189.s
new file mode 100644 (file)
index 0000000..4a6c9cd
--- /dev/null
@@ -0,0 +1,5 @@
+       .globl  _start
+       .type   _start, @function
+_start:
+       movl    __hidden_sym@GOT(%eax), %eax
+       .size   _start, .-_start
diff --git a/ld/testsuite/ld-i386/pr23189.t b/ld/testsuite/ld-i386/pr23189.t
new file mode 100644 (file)
index 0000000..0e6ff65
--- /dev/null
@@ -0,0 +1,11 @@
+EXTERN(_start)
+ENTRY(_start)
+
+SECTIONS
+{
+  .text :
+  {
+    HIDDEN (__hidden_sym = .);
+    *(.text*)
+  }
+}
diff --git a/ld/testsuite/ld-x86-64/pr23189.d b/ld/testsuite/ld-x86-64/pr23189.d
new file mode 100644 (file)
index 0000000..7951c7a
--- /dev/null
@@ -0,0 +1,7 @@
+#as: --64  -mrelax-relocations=yes
+#ld: -shared -melf_x86_64 -T pr23189.t
+#readelf: -r --wide
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
+    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
diff --git a/ld/testsuite/ld-x86-64/pr23189.s b/ld/testsuite/ld-x86-64/pr23189.s
new file mode 100644 (file)
index 0000000..971ad8f
--- /dev/null
@@ -0,0 +1,5 @@
+       .globl  _start
+       .type   _start, @function
+_start:
+       movq    __hidden_sym@GOTPCREL(%rip), %rax
+       .size   _start, .-_start
diff --git a/ld/testsuite/ld-x86-64/pr23189.t b/ld/testsuite/ld-x86-64/pr23189.t
new file mode 100644 (file)
index 0000000..0e6ff65
--- /dev/null
@@ -0,0 +1,11 @@
+EXTERN(_start)
+ENTRY(_start)
+
+SECTIONS
+{
+  .text :
+  {
+    HIDDEN (__hidden_sym = .);
+    *(.text*)
+  }
+}
index af3afcc2c735a4d5e393978c84c95b0e7bde7d79..9632a903ed0ec6cde3030dcc890ac84a08ccdee1 100644 (file)
@@ -381,6 +381,7 @@ run_dump_test "pr22115-1d-x32"
 run_dump_test "pr22135"
 run_dump_test "pr22782a"
 run_dump_test "pr22782b"
+run_dump_test "pr23189"
 
 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
     return