This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: Why is _dl_relocate_static_pie linked into crt1.o?


On Thu, Jul 5, 2018 at 5:01 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Jul 5, 2018 at 4:51 AM, Florian Weimer <fweimer@redhat.com> wrote:
>> I see this:
>>
>> “
>> $ objdump -d --reloc /usr/lib64/crt1.o
>>
>> /usr/lib64/crt1.o:     file format elf64-x86-64
>>
>>
>> Disassembly of section .text:
>>
>> 0000000000000000 <_start>:
>>    0:   31 ed                   xor    %ebp,%ebp
>>    2:   49 89 d1                mov    %rdx,%r9
>>    5:   5e                      pop    %rsi
>>    6:   48 89 e2                mov    %rsp,%rdx
>>    9:   48 83 e4 f0             and    $0xfffffffffffffff0,%rsp
>> …
>>
>> 0000000000000030 <_dl_relocate_static_pie>:
>>   30:   c3                      retq
>> ”
>>
>> Isn't _dl_relocate_static_pie useless there?  It will not be used in
>> dynamically linked binaries.  Should it be included in libc_nonshared.a
>> instead, so that static PIE binaries pick it up, as needed?
>>
>
> This dummy function is provided for arm.  Can we find a way to define
> it only for arm?
>
> --
> H.J.

x86 has

/* Return the link-time address of _DYNAMIC.  Conveniently, this is the
   first element of the GOT, a special entry that is never relocated.  */
static inline Elf32_Addr __attribute__ ((unused, const))
elf_machine_dynamic (void)
{
  /* This produces a GOTOFF reloc that resolves to zero at link time, so in
     fact just loads from the GOT register directly.  By doing it without
     an asm we can let the compiler choose any register.  */
  extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
  return _GLOBAL_OFFSET_TABLE_[0];
}

/* Return the run-time load address of the shared object.  */
static inline Elf32_Addr __attribute__ ((unused))
elf_machine_load_address (void)
{
  /* Compute the difference between the runtime address of _DYNAMIC as seen
     by a GOTOFF reference, and the link-time address found in the special
     unrelocated first GOT entry.  */
  extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
  return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
}

arm has

/* Return the run-time load address of the shared object.  */
static inline Elf32_Addr __attribute__ ((unused))
elf_machine_load_address (void)
{
  Elf32_Addr pcrel_addr;
#ifdef SHARED
  extern Elf32_Addr __dl_start (void *) asm ("_dl_start");
  Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
  asm ("adr %0, _dl_start" : "=r" (pcrel_addr));
#else
  extern Elf32_Addr __dl_relocate_static_pie (void *)
    asm ("_dl_relocate_static_pie") attribute_hidden;
  Elf32_Addr got_addr = (Elf32_Addr) &__dl_relocate_static_pie;
  asm ("adr %0, _dl_relocate_static_pie" : "=r" (pcrel_addr));
#endif

No idea why _DYNAMIC isn't used on arm.

-- 
H.J.


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