This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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] Move DONT_USE_BOOTSTRAP_MAP defininition to dl-machine.h


I'm now trying these definitions and they seem to be fine.  This requires a
compiler with working visibility support to make sure you get a GOTOFF
reloc.  But given that, it is about as kosher as this code could get,
giving the compiler a free hand to choose registers.  GCC 3.2 under -O3
produces very tight code for this, using a single load from the GOT for
both calls, and scheduling other insns inside the sequence to it's little
optimizing heart's content as it could not with the asm.

    /* Return the link-time address of _DYNAMIC.  We can access the GOT, which
       has not been relocated yet.  Since _DYNAMIC is not an exported symbol,
       a GOT reference will produce an R_386_RELATIVE reloc with an addend
       (initial value) of the link-time address we are looking for.  */
    static inline Elf32_Addr __attribute__ ((unused))
    elf_machine_dynamic (void)
    {
      return (Elf32_Addr) &_DYNAMIC;
    }


    /* 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 a symbol as seen
	 by a GOTOFF reference, and the link-time address found in the
	 unrelocated GOT entry for an unexported symbol.  Any unexported symbol
	 would do, but using _DYNAMIC reuses the same GOT entry produced by
	 `elf_machine_dynamic', and in fact the loaded value can be CSE'd.  */
      extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
      return (Elf32_Addr) &bygotoff - (Elf32_Addr) &_DYNAMIC;
    }

It seems safe to leave the old code as it was for compilers without working
visibility support.  Such compilers won't ever know they can PLT-free calls
and so they will always use %ebx (with my recent fix).  For compilers with
visibility support, it could become unsafe to do anything but this new code
below if we were to the more visibility decls we should add to allow the
freeest possible optimization (i.e. not necessarily using %ebx for the GOT).

The optimal thing would be to get rid of the normal (local) GOT entry this
creates for _DYNAMIC (corresponding to the one for _dl_start in the old
code) and have some way to refer to the special unrelocated 0'th GOT entry
that is already there for it.  Wait!  I got it!

   static inline Elf32_Addr __attribute__ ((unused))
   elf_machine_dynamic (void)
   {
     extern Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
     return _GLOBAL_OFFSET_TABLE_[0];
   }

   static inline Elf32_Addr __attribute__ ((unused))
   elf_machine_load_address (void)
   {
     extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
     return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
   }

That seems to work, and the useless R_386_RELATIVE reloc is gone.



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