This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] x86-64: Resolve R_X86_64_PLT32 referencing a local symbol even if defined in another section
- From: "Fangrui Song via binutils" <binutils at sourceware dot org>
- To: binutils at sourceware dot org
- Cc: Nick Clifton <nickc at redhat dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>
- Date: Wed, 12 Feb 2020 23:25:43 -0800
- Subject: [PATCH] x86-64: Resolve R_X86_64_PLT32 referencing a local symbol even if defined in another section
- Reply-to: Fangrui Song <maskray at google dot com>
See gas/testsuite/gas/i386/relax-5.s
Currently gas incorrectly emits a .L symbol.
Context: https://github.com/ClangBuiltLinux/linux/issues/811
(begin story
I taught clang to emit a call insn referencing a local symbol if the
symbol is defined in the same translation unit. This can avoid unneeded
PLT if the object file is linked with -shared.
.globl foo
foo:
.Lfoo$local:
...
call .Lfoo$local
end story)
The test case x86-64-relax-5.d is almost correct, except the last line.
I cannot figure out how to make runtest accept the last line.
runtest is so rigid about whitespace and newlines.
<printk> is not significant to the test, but I have to include it,
otherwise runtest will complain.
This is how I run tests:
% cd ~/Dev/binutils-gdb/Release/gas
% runtest -v --tool gas --srcdir ../../gas/testsuite/ i386.exp
This command runs a number of unrelated test cases. Is it very difficult to
run an isolated test case? This will be super helpful when developing a
bug fix.
---
gas/config/tc-i386.c | 2 --
gas/testsuite/gas/i386/i386.exp | 1 +
gas/testsuite/gas/i386/relax-5.s | 9 +++++++++
gas/testsuite/gas/i386/x86-64-relax-5.d | 17 +++++++++++++++++
4 files changed, 27 insertions(+), 2 deletions(-)
create mode 100644 gas/testsuite/gas/i386/relax-5.s
create mode 100644 gas/testsuite/gas/i386/x86-64-relax-5.d
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 680016ae45..a9d3a7de01 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -3398,7 +3398,6 @@ tc_i386_fix_adjustable (fixS *fixP ATTRIBUTE_UNUSED)
if (fixP->fx_r_type == BFD_RELOC_SIZE32
|| fixP->fx_r_type == BFD_RELOC_SIZE64
|| fixP->fx_r_type == BFD_RELOC_386_GOTOFF
- || fixP->fx_r_type == BFD_RELOC_386_PLT32
|| fixP->fx_r_type == BFD_RELOC_386_GOT32
|| fixP->fx_r_type == BFD_RELOC_386_GOT32X
|| fixP->fx_r_type == BFD_RELOC_386_TLS_GD
@@ -3411,7 +3410,6 @@ tc_i386_fix_adjustable (fixS *fixP ATTRIBUTE_UNUSED)
|| fixP->fx_r_type == BFD_RELOC_386_TLS_LE
|| fixP->fx_r_type == BFD_RELOC_386_TLS_GOTDESC
|| fixP->fx_r_type == BFD_RELOC_386_TLS_DESC_CALL
- || fixP->fx_r_type == BFD_RELOC_X86_64_PLT32
|| fixP->fx_r_type == BFD_RELOC_X86_64_GOT32
|| fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCREL
|| fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index 2ca8a94132..60bd1113f4 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -1135,6 +1135,7 @@ if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_64_check]] t
run_dump_test "x86-64-relax-2"
run_dump_test "x86-64-relax-3"
+ run_dump_test "x86-64-relax-5"
run_dump_test "x86-64-jump"
run_dump_test "x86-64-branch-2"
diff --git a/gas/testsuite/gas/i386/relax-5.s b/gas/testsuite/gas/i386/relax-5.s
new file mode 100644
index 0000000000..f8bcfce0c5
--- /dev/null
+++ b/gas/testsuite/gas/i386/relax-5.s
@@ -0,0 +1,9 @@
+ .section .init.text,"ax",@progbits
+ call printk
+ call .Lprintk$local
+
+ .text
+ .global printk
+printk:
+.Lprintk$local:
+ ret
diff --git a/gas/testsuite/gas/i386/x86-64-relax-5.d b/gas/testsuite/gas/i386/x86-64-relax-5.d
new file mode 100644
index 0000000000..6ccd40af2b
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-relax-5.d
@@ -0,0 +1,17 @@
+#source: relax-5.s
+#objdump: -drw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+ <printk>:
+ 0: c3 retq
+
+Disassembly of section .init.text:
+
+0+ <.init.text>:
+ 0: e8 00 00 00 00 callq 5 <.init.text\+0x5> 1: R_X86_64_PLT32 printk-0x4
+ 5: e8 00 00 00 00 callq a <printk\+0xa> 6: R_X86_64_PLT32 .text-0x4
+#pass
--
2.25.0