linux-mips
[Top] [All Lists]

Re: understanding elf_machine_load_address

To: Guido Guenther <guido.guenther@gmx.net>
Subject: Re: understanding elf_machine_load_address
From: Andreas Jaeger <aj@suse.de>
Date: Sat, 08 Dec 2001 16:18:53 +0100
Cc: linux-mips@oss.sgi.com
In-reply-to: <20011208141141.GA11437@bogon.ms20.nix> (Guido Guenther's message of "Sat, 8 Dec 2001 15:11:42 +0100")
Mail-copies-to: never
References: <20011208141141.GA11437@bogon.ms20.nix>
Sender: owner-linux-mips@oss.sgi.com
User-agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.4 (Artificial Intelligence, i386-suse-linux)
Guido Guenther <guido.guenther@gmx.net> writes:

> Hi,
> I'm trying to understand to following snippet from glibc's
> sysdeps/mips/dl-machine.h:

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
  loaded.

>        "      .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.

Enough cluebat?

Andreas
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

<Prev in Thread] Current Thread [Next in Thread>