From 2585b7a5ce5830e60a089aa2316a329558902f0c Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 19 Jul 2020 06:51:19 -0700 Subject: x86: Change PLT32 reloc against section to PC32 Commit 292676c1 resolved PLT32 reloc aganst local symbol to section. Since PLT32 relocation must be against symbols, turn such PLT32 relocation into PC32 relocation. gas/ PR gas/26263 * config/tc-i386.c (i386_validate_fix): Change PLT32 reloc against section to PC32 reloc. * testsuite/gas/i386/relax-5.d: Updated. * testsuite/gas/i386/x86-64-relax-4.d: Likewise. ld/ PR gas/26263 * testsuite/ld-i386/i386.exp: Run PR gas/26263 test. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr26263.d: New file. * testsuite/ld-x86-64/pr26263.d: Likewise. * testsuite/ld-x86-64/pr26263.s: Likewise. --- gas/ChangeLog | 8 ++++++++ gas/config/tc-i386.c | 19 +++++++++++++++---- gas/testsuite/gas/i386/relax-5.d | 2 +- gas/testsuite/gas/i386/x86-64-relax-4.d | 2 +- ld/ChangeLog | 9 +++++++++ ld/testsuite/ld-i386/i386.exp | 1 + ld/testsuite/ld-i386/pr26263.d | 19 +++++++++++++++++++ ld/testsuite/ld-x86-64/pr26263.d | 18 ++++++++++++++++++ ld/testsuite/ld-x86-64/pr26263.s | 8 ++++++++ ld/testsuite/ld-x86-64/x86-64.exp | 1 + 10 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 ld/testsuite/ld-i386/pr26263.d create mode 100644 ld/testsuite/ld-x86-64/pr26263.d create mode 100644 ld/testsuite/ld-x86-64/pr26263.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 2336fb5..e07e4ee 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,11 @@ +2020-07-19 H.J. Lu + + PR gas/26263 + * config/tc-i386.c (i386_validate_fix): Change PLT32 reloc + against section to PC32 reloc. + * testsuite/gas/i386/relax-5.d: Updated. + * testsuite/gas/i386/x86-64-relax-4.d: Likewise. + 2020-07-15 H.J. Lu PR gas/26237 diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 192c5e1..a9c79f1 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -13849,11 +13849,22 @@ i386_validate_fix (fixS *fixp) } } #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) - else if (!object_64bit) + else { - if (fixp->fx_r_type == BFD_RELOC_386_GOT32 - && fixp->fx_tcbit2) - fixp->fx_r_type = BFD_RELOC_386_GOT32X; + /* NB: Commit 292676c1 resolved PLT32 reloc aganst local symbol + to section. Since PLT32 relocation must be against symbols, + turn such PLT32 relocation into PC32 relocation. */ + if (fixp->fx_addsy + && (fixp->fx_r_type == BFD_RELOC_386_PLT32 + || fixp->fx_r_type == BFD_RELOC_X86_64_PLT32) + && symbol_section_p (fixp->fx_addsy)) + fixp->fx_r_type = BFD_RELOC_32_PCREL; + if (!object_64bit) + { + if (fixp->fx_r_type == BFD_RELOC_386_GOT32 + && fixp->fx_tcbit2) + fixp->fx_r_type = BFD_RELOC_386_GOT32X; + } } #endif } diff --git a/gas/testsuite/gas/i386/relax-5.d b/gas/testsuite/gas/i386/relax-5.d index bccfe68..c377133 100644 --- a/gas/testsuite/gas/i386/relax-5.d +++ b/gas/testsuite/gas/i386/relax-5.d @@ -10,6 +10,6 @@ Disassembly of section .text: Disassembly of section .init.text: 0+ : - +[a-f0-9]+: e8 fb ff ff ff call 0 1: R_386_PLT32 .text + +[a-f0-9]+: e8 fc ff ff ff call 1 1: R_386_PC32 .text +[a-f0-9]+: e8 fc ff ff ff call 6 6: R_386_PC32 .text #pass diff --git a/gas/testsuite/gas/i386/x86-64-relax-4.d b/gas/testsuite/gas/i386/x86-64-relax-4.d index 594f95a..ca12c03 100644 --- a/gas/testsuite/gas/i386/x86-64-relax-4.d +++ b/gas/testsuite/gas/i386/x86-64-relax-4.d @@ -12,6 +12,6 @@ Disassembly of section .text: Disassembly of section .init.text: 0+ : - +[a-f0-9]+: e8 00 00 00 00 call 5 1: R_X86_64_PLT32 .text-0x4 + +[a-f0-9]+: e8 00 00 00 00 call 5 1: R_X86_64_PC32 .text-0x4 +[a-f0-9]+: 48 8d 05 00 00 00 00 lea 0x0\(%rip\),%rax # c 8: R_X86_64_PC32 .text-0x4 #pass diff --git a/ld/ChangeLog b/ld/ChangeLog index 37a94aa..7478568 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2020-07-19 H.J. Lu + + PR gas/26263 + * testsuite/ld-i386/i386.exp: Run PR gas/26263 test. + * testsuite/ld-x86-64/x86-64.exp: Likewise. + * testsuite/ld-i386/pr26263.d: New file. + * testsuite/ld-x86-64/pr26263.d: Likewise. + * testsuite/ld-x86-64/pr26263.s: Likewise. + 2020-07-19 Hans-Peter Nilsson * scripttempl/elf.sc (ETEXT_LAST_IN_RODATA_SEGMENT): New variable. diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index e51981a..164c099 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -469,6 +469,7 @@ run_dump_test "pr24322a" run_dump_test "pr24322b" run_dump_test "align-branch-1" run_dump_test "pr26018" +run_dump_test "pr26263" if { !([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"] diff --git a/ld/testsuite/ld-i386/pr26263.d b/ld/testsuite/ld-i386/pr26263.d new file mode 100644 index 0000000..8cf7c15 --- /dev/null +++ b/ld/testsuite/ld-i386/pr26263.d @@ -0,0 +1,19 @@ +#source: ../ld-x86-64/pr26263.s +#as: --32 +#ld: -shared -melf_i386 +#objdump: -dw + +.*: +file format .* + + +Disassembly of section .text: + +0+1000 : + +[a-f0-9]+: c3 ret + +Disassembly of section .init.text: + +0+1001 : + +[a-f0-9]+: e8 fa ff ff ff call 1000 + +[a-f0-9]+: e8 f5 ff ff ff call 1000 +#pass diff --git a/ld/testsuite/ld-x86-64/pr26263.d b/ld/testsuite/ld-x86-64/pr26263.d new file mode 100644 index 0000000..375218c --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr26263.d @@ -0,0 +1,18 @@ +#as: --64 +#ld: -m elf_x86_64 -shared +#objdump: -dw + +.*: +file format .* + + +Disassembly of section .text: + +0+1000 : + +[a-f0-9]+: c3 ret + +Disassembly of section .init.text: + +0+1001 : + +[a-f0-9]+: e8 fa ff ff ff call 1000 + +[a-f0-9]+: e8 f5 ff ff ff call 1000 +#pass diff --git a/ld/testsuite/ld-x86-64/pr26263.s b/ld/testsuite/ld-x86-64/pr26263.s new file mode 100644 index 0000000..5a3332c --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr26263.s @@ -0,0 +1,8 @@ + .section .init.text,"ax",@progbits + .global foo +foo: + call printk + call printk@PLT + .text +printk: + ret diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index e687c42..21aa6a0 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -640,6 +640,7 @@ run_dump_test "pr20253-5b" run_dump_test "tlsdesc2" run_dump_test "pr22048" run_dump_test "pr22929" +run_dump_test "pr26263" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" -- cgit v1.1