This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Avoiding GOT in gold
- From: Jethro Beekman <binutils at jbeekman dot nl>
- To: binutils at sourceware dot org
- Date: Mon, 8 Feb 2016 17:13:37 -0800
- Subject: Re: Avoiding GOT in gold
- Authentication-results: sourceware.org; auth=none
- References: <56B9346F dot 5080201 at jbeekman dot nl>
I'm sorry, I included an incorrect test case, see changes below.
On 08-02-16 16:35, Jethro Beekman wrote:
> I have some code that when using ld doesn't produce a GOT entry, but when using
> gold does.
>
> ### Inputs
>
> test1.S
> =======
> .data
> test1:
> .long 1234
>
> .text
> call test2
test1.S
=======
.data
.global test1
test1:
.long 1234
.text
push test1(%rip)
call test2
> test2.c
> =======
> int test1;
>
> int test2() {
> asm volatile(""::"a"(test1));
> }
>
> ### Compile
>
> test1.S -o test1.o
Should be `as test1.S -o test1.o` of course.
> gcc -fPIC -c test2.c
> ar rcs test2.a test2.o
>
> ### Link with ld
>
> ld -shared -nostdlib -Bstatic -Bsymbolic test1.o test2.a
> objdump -d
>
> 0000000000000222 <test2>:
> 222: 55 push %rbp
> 223: 48 89 e5 mov %rsp,%rbp
> 226: 48 8d 05 1f 01 20 00 lea 0x20011f(%rip),%rax # 20034c <_edata>
> 22d: 8b 00 mov (%rax),%eax
> 22f: 5d pop %rbp
> 230: c3 retq
0000000000000228 <test2>:
228: 55 push %rbp
229: 48 89 e5 mov %rsp,%rbp
22c: 48 8d 05 15 01 20 00 lea 0x200115(%rip),%rax # 200348 <test1>
233: 8b 00 mov (%rax),%eax
235: 5d pop %rbp
236: c3 retq
> ### Link with gold
>
> ld.gold -shared -nostdlib -Bstatic -Bsymbolic test1.o test2.a
> objdump -d
>
> 000000000000025d <test2>:
> 25d: 55 push %rbp
> 25e: 48 89 e5 mov %rsp,%rbp
> 261: 48 8b 05 60 11 00 00 mov 0x1160(%rip),%rax # 13c8 <_DYNAMIC+0x120>
> 268: 8b 00 mov (%rax),%eax
> 26a: 5d pop %rbp
> 26b: c3 retq
0000000000000263 <test2>:
263: 55 push %rbp
264: 48 89 e5 mov %rsp,%rbp
267: 48 8b 05 62 11 00 00 mov 0x1162(%rip),%rax # 13d0 <_DYNAMIC+0x120>
26e: 8b 00 mov (%rax),%eax
270: 5d pop %rbp
271: c3 retq
> I'd like to use gold for various reasons, but how do I make gold not put test1
> in the GOT here?
>
> Jethro Beekman
>