This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR gold/17640


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]