Hi, On Thu, 13 Nov 2014, H.J. Lu wrote:
> Linker does: > > ... code that looks like it might create just one GOT slot ... > > So if a symbol is accessed by both @GOT and @PLTOFF, its > needs_plt will be true and its got.plt entry will be used for > both @GOT and @GOTPLT. @GOTPLT has no advantage > over @GOT, but potentially wastes a PLT entry. The above is not correct. Had you tried you'd see this: % cat x.c extern void foo (void); void main (void) { void (*f)(void) = foo; f(); foo(); } % gcc -fPIE -mcmodel=large -S x.c; cat x.s ... movabsq $foo@GOT, %rax ... movabsq $foo@PLTOFF, %rax ... So, foo is access via @GOT offset and @PLTOFF. Then, % cat y.c void foo (void) {} % gcc -o liby.so -shared -fPIC y.c % gcc -fPIE -mcmodel=large x.s liby.so % readelf -r a.out ... 000000600ff8 000400000006 R_X86_64_GLOB_DAT 0000000000000000 foo + 0 ... 000000601028 000400000007 R_X86_64_JUMP_SLO 0000000000000000 foo + 0 ... The first one (to 600ff8) is the normal GOT slot, the second one the GOT slot for the PLT entry. Both are actually used: 00000000004005f0 <foo@plt>: 4005f0: ff 25 32 0a 20 00 jmpq *0x200a32(%rip) # 601028 <_GLOBAL_OFFSET_TABLE_+0x28> That uses the second GOT slot, and: 00000000004006ec <main>: 4006ec: 55 push %rbp 4006ed: 48 89 e5 mov %rsp,%rbp 4006f0: 53 push %rbx 4006f1: 48 83 ec 18 sub $0x18,%rsp 4006f5: 48 8d 1d f9 ff ff ff lea -0x7(%rip),%rbx # 4006f5 <main+0x9> 4006fc: 49 bb 0b 09 20 00 00 movabs $0x20090b,%r11 400703: 00 00 00 400706: 4c 01 db add %r11,%rbx 400709: 48 b8 f8 ff ff ff ff movabs $0xfffffffffffffff8,%rax 400710: ff ff ff 400713: 48 8b 04 03 mov (%rbx,%rax,1),%rax This uses the first slot at 0x600ff8. So, no, currently GOT and GOTPLT (at least how it's supposed to be implemented) are not equivalent. > Here is a patch to mark relocation 30 (R_X86_64_GOTPLT64) as reserved. > I pushed updated x86-64 psABI changes to > > https://github.com/hjl-tools/x86-64-psABI/tree/hjl/master > > I will update linker to keep accepting relocation 30 and treat it the > same as R_X86_64_GOT64. That seems a bit premature given the above. Ciao, Michael.