https://sourceware.org/bugzilla/show_bug.cgi?id=34423
Bug ID: 34423
Summary: Generate R_X86_64_PLT32 in PIC jump table
Product: binutils
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: gas
Assignee: unassigned at sourceware dot org
Reporter: hjl.tools at gmail dot com
CC: jbeulich at suse dot com
Target Milestone: ---
Target: x86-64
The PIC jump table may look like:
[hjl@gnu-tgl-3 pic-1]$ cat j.S
.text
.p2align 4
.globl foo
.type foo, @function
foo:
.cfi_startproc
cmpl $4, %edi
ja .L1
leaq .L4(%rip), %rdx
movl %edi, %edi
movslq (%rdx,%rdi,4), %rax
addq %rdx, %rax
jmp *%rax
.L1:
ret
.cfi_endproc
.size foo, .-foo
.section .rodata
.p2align 2
.type bar0, @function
.type bar1, @function
.type bar2, @function
.type bar3, @function
.type bar4, @function
.L4:
.long bar0-.L4
.long bar1-.L4
.long bar2-.L4
.long bar3-.L4
.long bar4-.L4
.LFE0:
.section .note.GNU-stack,"",@progbits
[hjl@gnu-tgl-3 pic-1]$
Currently R_X86_64_PC32 is generated and linker complaints:
[hjl@gnu-tgl-3 pic-1]$ as -o j.o j.S
[hjl@gnu-tgl-3 pic-1]$ ld -shared -o libj.so j.o
/usr/local/bin/ld: j.o: warning: relocation against `bar0' in read-only section
`.rodata'
/usr/local/bin/ld: j.o: relocation R_X86_64_PC32 against undefined symbol
`bar0' can not be used when making a shared object; recompile with -fPIC
/usr/local/bin/ld: final link failed: bad value
[hjl@gnu-tgl-3 pic-1]$
If we generate R_X86_64_PLT32 instead, it works:
[hjl@gnu-tgl-3 pic-1]$ ./as -o j.o j.S
[hjl@gnu-tgl-3 pic-1]$ ld -shared -o libj.so j.o
[hjl@gnu-tgl-3 pic-1]$ readelf -rW j.o
Relocation section '.rela.text' at offset 0x1c8 contains 1 entry:
Offset Info Type Symbol's Value
Symbol's Name + Addend
0000000000000008 0000000200000002 R_X86_64_PC32 0000000000000000
.rodata - 4
Relocation section '.rela.rodata' at offset 0x1e0 contains 5 entries:
Offset Info Type Symbol's Value
Symbol's Name + Addend
0000000000000000 0000000400000004 R_X86_64_PLT32 0000000000000000 bar0
+ 0
0000000000000004 0000000500000004 R_X86_64_PLT32 0000000000000000 bar1
+ 4
0000000000000008 0000000600000004 R_X86_64_PLT32 0000000000000000 bar2
+ 8
000000000000000c 0000000700000004 R_X86_64_PLT32 0000000000000000 bar3
+ c
0000000000000010 0000000800000004 R_X86_64_PLT32 0000000000000000 bar4
+ 10
Relocation section '.rela.eh_frame' at offset 0x258 contains 1 entry:
Offset Info Type Symbol's Value
Symbol's Name + Addend
0000000000000020 0000000100000002 R_X86_64_PC32 0000000000000000
.text + 0
[hjl@gnu-tgl-3 pic-1]$
--
You are receiving this mail because:
You are on the CC list for the bug.