Guido Guenther <firstname.lastname@example.org> writes:
> I'm trying to understand to following snippet from glibc's
That one is really a bit tricky but it should be correct.
You should add the comment in front:
/* Return the run-time load address of the shared object. */
> elf_machine_load_address (void)
> ElfW(Addr) addr;
> asm (" .set noreorder\n"
> " la %0, here\n"
load address this object has at build time (that's the address objdump
prints) and which is different than the current address (a shared
library can be loaded to any address and elf_machine_load_address is
called before relocation).
> " bltzal $0, here\n"
> " nop\n"
> "here: subu %0, $31, %0\n"
Subtract shared address of "here" from address of "here" at build time
- and you know at which address byte 0 of the shared library is
> " .set reorder\n"
> : "=r" (addr)
> : /* No inputs */
> : "$31");
> return addr;
> As of my understanding addr is zero since $31-%0 is always
> zero(%0 stored (before the subu) the address of 'here', as does $31
> after the bltzal). Please beat me with a cluebat.
SuSE Labs email@example.com