[PATCH] D20024: [ELF] - Protect first entries of got.plt with RelRo.

Joerg Sonnenberger via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 20:08:31 PDT 2016


On Fri, May 06, 2016 at 04:55:06PM -0700, H.J. Lu wrote:
> On Fri, May 6, 2016 at 4:09 PM, Joerg Sonnenberger via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > On Fri, May 06, 2016 at 03:37:28PM -0700, Rui Ueyama wrote:
> >> Does that mean the value the static linker writes to the first GOT slot
> >> will be ignored?
> >
> >         leaq    _GLOBAL_OFFSET_TABLE_(%rip),%rax
> >         leaq    _DYNAMIC(%rip),%rdi     # &_DYNAMIC
> >         movq    %rdi,%rbx
> >         subq    (%rax),%rbx             # relocbase
> >
> > ...and %rbx is then passed as argument to the self-relocation function.
> > There are some possible other ways to do it, but they are more involved
> > like parsing the aux vector. Given that this is very early startup code,
> > less magic is better here.
> 
> Since the the link-time address of _DYNAMIC is stored in the first element
> of the GOT as specified by the x86-64 psABI, one can use
> 
> movq _GLOBAL_OFFSET_TABLE_(%rip), %rax
> 
> to get the link-time address of _DYNAMIC.

That's what is done here effectively. Not sure what the historic reason for
using lea + dereferennce in the sub is, but it is equivalent to  your
mov and using plain %rax second.

Joerg


More information about the llvm-commits mailing list