From: H.J. Lu Date: Fri, 20 May 2016 16:41:50 +0000 (-0700) Subject: Don't convert R_386_GOT32 relocation X-Git-Tag: users/ARM/embedded-gdb-2_26-branch-2016q1~4^2~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c10d012d18caf2a39d7348a43eae7d8d5a940cdc;p=thirdparty%2Fbinutils-gdb.git 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. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index f56dca37d1c..fbb875365c5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,17 @@ +2016-05-20 H.J. Lu + + Backport from master + 2016-05-20 H.J. Lu + + * elf32-i386.c (elf_i386_check_relocs): Don't check R_386_GOT32 + when setting need_convert_load. + + 2016-05-19 H.J. Lu + + PR ld/20117 + * elf32-i386.c (elf_i386_convert_load): Don't convert + R_386_GOT32. + 2016-05-18 Christophe Monat Backport from master diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 79f339e53ee..a3a241fe2f9 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 c8ce258fff8..5a6b5bddc3a 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,13 @@ +2016-05-20 H.J. Lu + + Backport from master + 2016-05-19 H.J. Lu + + 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 Backport from master diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 1916c24b6c0..b1332ffe211 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 00000000000..59c77ee0134 --- /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 00000000000..de2dd28e06b --- /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