This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/70743] New: Extend -fno-plt to function pointer
- From: "hjl.tools at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Apr 2016 22:24:20 +0000
- Subject: [Bug target/70743] New: Extend -fno-plt to function pointer
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70743
Bug ID: 70743
Summary: Extend -fno-plt to function pointer
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
CC: ubizjak at gmail dot com
Target Milestone: ---
Target: x86
Even when -fno-plt is used, GCC still generates PLT for function
pointer:
[hjl@gnu-6 plt-2]$ cat x.i
extern void foo (void);
void *
_start (void)
{
foo ();
return foo;
}
[hjl@gnu-6 plt-2]$ cat foo.c
void
foo (void)
{
}
[hjl@gnu-6 plt-2]$ make
/export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -fno-plt -c -o x.o x.i
/export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -fno-plt -fPIC -c -o
foo.o foo.c
ld -shared -o foo.so foo.o
ld -o x x.o foo.so
readelf -r x
Relocation section '.rela.dyn' at offset 0x268 contains 1 entries:
Offset Info Type Sym. Value Sym. Name +
Addend
000000600470 000200000006 R_X86_64_GLOB_DAT 00000000004002b0 foo + 0
Relocation section '.rela.plt' at offset 0x280 contains 1 entries:
Offset Info Type Sym. Value Sym. Name +
Addend
000000600490 000200000007 R_X86_64_JUMP_SLO 00000000004002b0 foo + 0
objdump -dw x
x: file format elf64-x86-64
Disassembly of section .plt:
00000000004002a0 <foo@plt-0x10>:
4002a0: ff 35 da 01 20 00 pushq 0x2001da(%rip) # 600480
<_GLOBAL_OFFSET_TABLE_+0x8>
4002a6: ff 25 dc 01 20 00 jmpq *0x2001dc(%rip) # 600488
<_GLOBAL_OFFSET_TABLE_+0x10>
4002ac: 0f 1f 40 00 nopl 0x0(%rax)
00000000004002b0 <foo@plt>:
4002b0: ff 25 da 01 20 00 jmpq *0x2001da(%rip) # 600490
<_GLOBAL_OFFSET_TABLE_+0x18>
4002b6: 68 00 00 00 00 pushq $0x0
4002bb: e9 e0 ff ff ff jmpq 4002a0 <foo@plt-0x10>
Disassembly of section .text:
00000000004002c0 <_start>:
4002c0: 48 83 ec 08 sub $0x8,%rsp
4002c4: ff 15 a6 01 20 00 callq *0x2001a6(%rip) # 600470
<_DYNAMIC+0x140>
4002ca: b8 b0 02 40 00 mov $0x4002b0,%eax
4002cf: 48 83 c4 08 add $0x8,%rsp
4002d3: c3 retq
[hjl@gnu-6 plt-2]$
GCC can generate
movq foo@GOTPCREL(%rip), %rax
for function pointer. It will remove PLT and only needs one run-time
relocation:
readelf -r x
Relocation section '.rela.dyn' at offset 0x268 contains 1 entries:
Offset Info Type Sym. Value Sym. Name +
Addend
0000006003c8 000200000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0
objdump -dw x
x: file format elf64-x86-64
Disassembly of section .text:
0000000000400280 <_start>:
400280: 48 83 ec 08 sub $0x8,%rsp
400284: ff 15 3e 01 20 00 callq *0x20013e(%rip) # 6003c8
<_DYNAMIC+0x100>
40028a: 48 8b 05 37 01 20 00 mov 0x200137(%rip),%rax #
6003c8 <_DYNAMIC+0x100>
400291: 48 83 c4 08 add $0x8,%rsp
400295: c3 retq
[hjl@gnu-6 plt-2]$