This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] PR ld/20117: Don't convert R_386_GOT32 relocation
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Fri, 20 May 2016 09:44:49 -0700
- Subject: Re: [committed, PATCH] PR ld/20117: Don't convert R_386_GOT32 relocation
- Authentication-results: sourceware.org; auth=none
- References: <20160519195835 dot GA12937 at intel dot com>
On Thu, May 19, 2016 at 12:58 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Don't convert R_386_GOT32 since we can't tell if it is applied
> to "mov $foo@GOT, %reg" which isn't a load via GOT.
>
> Checked into master. Will backport it to 2.26 branch.
>
>
> H.J.
> --
> bfd/
>
> PR ld/20117
> * elf32-i386.c (elf_i386_convert_load_reloc): Don't check
> R_386_GOT32X.
> (elf_i386_convert_load): Don't convert R_386_GOT32.
>
> ld/
>
> PR ld/20117
> * testsuite/ld-i386/i386.exp: Run pr20117.
> * testsuite/ld-i386/pr19609-1i.d: Updated.
> * testsuite/ld-i386/pr20117.d: New file.
> * testsuite/ld-i386/pr20117.s: Likewise.
This is what I checked into 2.26 branch.
--
H.J.
From c10d012d18caf2a39d7348a43eae7d8d5a940cdc Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 20 May 2016 09:41:50 -0700
Subject: [PATCH] Don't convert R_386_GOT32 relocation
Don't convert R_386_GOT32 since we can't tell if it is applied
to "mov $foo@GOT, %reg" which isn't a load via GOT.
bfd/
Backport from master
* elf32-i386.c (elf_i386_check_relocs): Don't check R_386_GOT32
when setting need_convert_load.
PR ld/20117
* elf32-i386.c (elf_i386_convert_load): Don't convert
R_386_GOT32.
ld/
Backport from master
PR ld/20117
* testsuite/ld-i386/i386.exp: Run pr20117.
* testsuite/ld-i386/pr20117.d: New file.
* testsuite/ld-i386/pr20117.s: Likewise.
---
bfd/ChangeLog | 14 ++++++++++++++
bfd/elf32-i386.c | 27 ++++++++++-----------------
ld/ChangeLog | 10 ++++++++++
ld/testsuite/ld-i386/i386.exp | 1 +
ld/testsuite/ld-i386/pr20117.d | 12 ++++++++++++
ld/testsuite/ld-i386/pr20117.s | 7 +++++++
6 files changed, 54 insertions(+), 17 deletions(-)
create mode 100644 ld/testsuite/ld-i386/pr20117.d
create mode 100644 ld/testsuite/ld-i386/pr20117.s
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f56dca3..fbb8753 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,17 @@
+2016-05-20 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from master
+ 2016-05-20 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elf32-i386.c (elf_i386_check_relocs): Don't check R_386_GOT32
+ when setting need_convert_load.
+
+ 2016-05-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/20117
+ * elf32-i386.c (elf_i386_convert_load): Don't convert
+ R_386_GOT32.
+
2016-05-18 Christophe Monat <christophe.monat@st.com>
Backport from master
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 79f339e..a3a241f 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1962,7 +1962,7 @@ do_size:
return FALSE;
}
- if ((r_type == R_386_GOT32 || r_type == R_386_GOT32X)
+ if (r_type == R_386_GOT32X
&& (h == NULL || h->type != STT_GNU_IFUNC))
sec->need_convert_load = 1;
}
@@ -2816,14 +2816,16 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
unsigned int nop;
bfd_vma nop_offset;
- if (r_type != R_386_GOT32 && r_type != R_386_GOT32X)
+ /* Don't convert R_386_GOT32 since we can't tell if it is applied
+ to "mov $foo@GOT, %reg" which isn't a load via GOT. */
+ if (r_type != R_386_GOT32X)
continue;
roff = irel->r_offset;
if (roff < 2)
continue;
- /* Addend for R_386_GOT32 and R_386_GOT32X relocations must be 0. */
+ /* Addend for R_386_GOT32X relocation must be 0. */
addend = bfd_get_32 (abfd, contents + roff);
if (addend != 0)
continue;
@@ -2831,13 +2833,11 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
modrm = bfd_get_8 (abfd, contents + roff - 1);
baseless = (modrm & 0xc7) == 0x5;
- if (r_type == R_386_GOT32X
- && baseless
+ if (baseless
&& bfd_link_pic (link_info))
{
/* For PIC, disallow R_386_GOT32X without a base register
- since we don't know what the GOT base is. Allow
- R_386_GOT32 for existing object files. */
+ since we don't know what the GOT base is. */
const char *name;
if (r_symndx < symtab_hdr->sh_info)
@@ -2865,12 +2865,6 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
/* It is OK to convert mov to lea. */
if (opcode != 0x8b)
{
- /* Only convert R_386_GOT32X relocation for call, jmp or
- one of adc, add, and, cmp, or, sbb, sub, test, xor
- instructions. */
- if (r_type != R_386_GOT32X)
- continue;
-
/* It is OK to 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. */
@@ -2878,8 +2872,8 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
continue;
}
- /* Try to convert R_386_GOT32 and R_386_GOT32X. Get the symbol
- referred to by the reloc. */
+ /* Try to convert R_386_GOT32X. Get the symbol referred to by
+ the reloc. */
if (r_symndx < symtab_hdr->sh_info)
{
isym = bfd_sym_from_r_symndx (&htab->sym_cache,
@@ -2991,8 +2985,7 @@ convert_load:
{
/* Convert "mov foo@GOT(%reg1), %reg2" to
"lea foo@GOTOFF(%reg1), %reg2". */
- if (r_type == R_386_GOT32X
- && (baseless || !bfd_link_pic (link_info)))
+ if (baseless || !bfd_link_pic (link_info))
{
r_type = R_386_32;
/* For R_386_32, convert
diff --git a/ld/ChangeLog b/ld/ChangeLog
index c8ce258..5a6b5bd 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,13 @@
+2016-05-20 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from master
+ 2016-05-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/20117
+ * testsuite/ld-i386/i386.exp: Run pr20117.
+ * testsuite/ld-i386/pr20117.d: New file.
+ * testsuite/ld-i386/pr20117.s: Likewise.
+
2016-05-18 Christophe Monat <christophe.monat@st.com>
Backport from master
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 1916c24..b1332ff 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -328,6 +328,7 @@ run_dump_test "load5b"
run_dump_test "load6"
run_dump_test "pr19175"
run_dump_test "pr19615"
+run_dump_test "pr20117"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr20117.d b/ld/testsuite/ld-i386/pr20117.d
new file mode 100644
index 0000000..59c77ee
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr20117.d
@@ -0,0 +1,12 @@
+#as: --32
+#ld: -melf_i386
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+[ ]*[a-f0-9]+: eb 8b jmp [a-f0-9]+ <_start\-0x[a-f0-9]+>
+[ ]*[a-f0-9]+: bd ([0-9a-f]{2} ){4} * mov \$0x[a-f0-9]+\,%ebp
diff --git a/ld/testsuite/ld-i386/pr20117.s b/ld/testsuite/ld-i386/pr20117.s
new file mode 100644
index 0000000..de2dd28
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr20117.s
@@ -0,0 +1,7 @@
+ .comm DEBUGLEVEL,4,4
+ .text
+ .globl _start
+ .type _start, @function
+_start:
+ .byte 0xeb, 0x8b
+ movl $DEBUGLEVEL@GOT, %ebp
--
2.5.5