This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] PR gold/17640
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Ilya Tocar <tocarip dot intel at gmail dot com>
- Cc: Cary Coutant <ccoutant at google dot com>, Binutils <binutils at sourceware dot org>
- Date: Fri, 13 Mar 2015 07:48:15 -0700
- Subject: Re: [PATCH] PR gold/17640
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOq-uSd64h6eeogR3SywtQipMupN9Ng9-EvPLF+3bp7Exw at mail dot gmail dot com> <20150305104052 dot GA16361 at msticlxl7 dot ims dot intel dot com> <CAMe9rOqRQ+HMS12+hn9Nz0pnb95tUDmbAU2QjK9G1Rc-q=woCA at mail dot gmail dot com> <20150310112745 dot GA104717 at msticlxl7 dot ims dot intel dot com> <CAMe9rOoG6NOVLYxZBJ5KRuS9_47=ptsd=Ft9iA9HfN2Asw0UeQ at mail dot gmail dot com> <20150312143236 dot GA95320 at msticlxl7 dot ims dot intel dot com> <CAMe9rOpn0uGDm1qbwgL-7CiYKjQeSHMHX6WzsnZ6eyfcp2MBAw at mail dot gmail dot com> <20150312145732 dot GB95320 at msticlxl7 dot ims dot intel dot com> <CAHACq4qF26jr8QYR_V55oVewLyHpgD2g7TrxDmgye0_S4pdroQ at mail dot gmail dot com> <CAMe9rOrMMxkR4bnoomCdW2P6TQtExMyMeC1oBHXNE3vXEEawLw at mail dot gmail dot com> <20150313112631 dot GA72598 at msticlxl7 dot ims dot intel dot com>
On Fri, Mar 13, 2015 at 4:26 AM, Ilya Tocar <tocarip.intel@gmail.com> wrote:
> On 12 Mar 16:37, H.J. Lu wrote:
>> On Thu, Mar 12, 2015 at 3:08 PM, Cary Coutant <ccoutant@google.com> wrote:
>> > + // If we convert this from
>> > + // mov foo@GOT(%reg), %reg
>> > + // to
>> > + // lea foo@GOTOFF(%reg), %reg
>> > + // in Relocate::relocate, then there is nothing to do here.
>> > + // Avoid converting _DYNAMIC, because its address may be used.
>> >
>> > I'm sorry, but I still don't understand the rationale for treating
>> > _DYNAMIC specially. If you convert all of the references to @GOTOFF,
>> > what's the point of having the GOT entry? If the loader is going to
>> > use it, how does it find it?
>
> I was trying to mirror behavior of bfd linker.
>
>>
>> It is related to
>>
>> https://sourceware.org/bugzilla/show_bug.cgi?id=14538
>>
>> With the old x86-64 elf_machine_dynamic, we generate
>>
>> addq _DYNAMIC@GOTPCREL(%rip), %rdx
>>
>> We need to keep _DYNAMIC GOT entry.
>>
>
> Than why does 32-bit bfd linker also avoids optimizing _DYNAMIC?
Since _DYNAMIC may be used in
---
extern int _DYNAMIC[];
static inline unsigned long
foo (void)
{
return (unsigned long) &_DYNAMIC;
}
static inline unsigned long
bar (void)
{
unsigned long addr;
asm ("xxx %0" : "=r" (addr));
return addr;
}
unsigned long
xxxx (void)
{
return bar () + foo ();
}
---
You can compile it with -fPIC -O3 -S for -m32 and -m64.
-m64:
xxxx:
.LFB2:
.cfi_startproc
#APP
# 13 "x.c" 1
xxx %rax
# 0 "" 2
#NO_APP
addq _DYNAMIC@GOTPCREL(%rip), %rax
ret
.cfi_endproc
.LFE2:
.size xxxx, .-xxxx
-m32:
xxxx:
.LFB2:
.cfi_startproc
call __x86.get_pc_thunk.cx
addl $_GLOBAL_OFFSET_TABLE_, %ecx
#APP
# 13 "x.c" 1
xxx %eax
# 0 "" 2
#NO_APP
addl _DYNAMIC@GOT(%ecx), %eax
ret
.cfi_endproc
.LFE2:
.size xxxx, .-xxxx
Both requires preserve _DYNAMIC GOT entry.
--
H.J.