* understanding elf_machine_load_address
@ 2001-12-08 14:11 Guido Guenther
2001-12-08 15:18 ` Andreas Jaeger
0 siblings, 1 reply; 8+ messages in thread
From: Guido Guenther @ 2001-12-08 14:11 UTC (permalink / raw)
To: linux-mips
Hi,
I'm trying to understand to following snippet from glibc's
sysdeps/mips/dl-machine.h:
elf_machine_load_address (void)
{
ElfW(Addr) addr;
asm (" .set noreorder\n"
" la %0, here\n"
" bltzal $0, here\n"
" nop\n"
"here: subu %0, $31, %0\n"
" .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.
-- Guido
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: understanding elf_machine_load_address
2001-12-08 14:11 understanding elf_machine_load_address Guido Guenther
@ 2001-12-08 15:18 ` Andreas Jaeger
2001-12-08 16:37 ` Guido Guenther
2001-12-08 16:47 ` Daniel Jacobowitz
0 siblings, 2 replies; 8+ messages in thread
From: Andreas Jaeger @ 2001-12-08 15:18 UTC (permalink / raw)
To: Guido Guenther; +Cc: linux-mips
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: understanding elf_machine_load_address
2001-12-08 15:18 ` Andreas Jaeger
@ 2001-12-08 16:37 ` Guido Guenther
2001-12-08 16:47 ` Daniel Jacobowitz
1 sibling, 0 replies; 8+ messages in thread
From: Guido Guenther @ 2001-12-08 16:37 UTC (permalink / raw)
To: Andreas Jaeger; +Cc: linux-mips
On Sat, Dec 08, 2001 at 04:18:53PM +0100, Andreas Jaeger wrote:
> Enough cluebat?
Yes. Thanks.
-- Guido
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: understanding elf_machine_load_address
2001-12-08 15:18 ` Andreas Jaeger
2001-12-08 16:37 ` Guido Guenther
@ 2001-12-08 16:47 ` Daniel Jacobowitz
2001-12-08 19:42 ` Andreas Jaeger
2001-12-08 20:52 ` Andreas Jaeger
1 sibling, 2 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2001-12-08 16:47 UTC (permalink / raw)
To: Andreas Jaeger; +Cc: Guido Guenther, linux-mips
On Sat, Dec 08, 2001 at 04:18:53PM +0100, Andreas Jaeger wrote:
> > " 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.
Wait a second. Does bltzal fill in $31 even on a not-taken branch?
Because bltzal $0 should never be taken. My handy MIPS reference and
SPIM seem to agree that it won't fill in $31.
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: understanding elf_machine_load_address
2001-12-08 16:47 ` Daniel Jacobowitz
@ 2001-12-08 19:42 ` Andreas Jaeger
2001-12-08 20:23 ` Guido Guenther
2001-12-08 20:52 ` Andreas Jaeger
1 sibling, 1 reply; 8+ messages in thread
From: Andreas Jaeger @ 2001-12-08 19:42 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Guido Guenther, linux-mips
Daniel Jacobowitz <dan@debian.org> writes:
> On Sat, Dec 08, 2001 at 04:18:53PM +0100, Andreas Jaeger wrote:
>> > " 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.
>
> Wait a second. Does bltzal fill in $31 even on a not-taken branch?
> Because bltzal $0 should never be taken. My handy MIPS reference and
> SPIM seem to agree that it won't fill in $31.
That's what I've asked myself also when fixing the dynamic linker.
But Ralf convinced me that $31 will get filled in (and I verified that
it did) - otherwise the dynamic linker would not work on any system at
all.
But it might be worth checking if Guido notices a problem.
Btw. could anybody send me a patch documenting this instruction so
that next time everybody knows directly what's going on?
Thanks,
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: understanding elf_machine_load_address
2001-12-08 19:42 ` Andreas Jaeger
@ 2001-12-08 20:23 ` Guido Guenther
0 siblings, 0 replies; 8+ messages in thread
From: Guido Guenther @ 2001-12-08 20:23 UTC (permalink / raw)
To: Andreas Jaeger; +Cc: Daniel Jacobowitz, linux-mips
On Sat, Dec 08, 2001 at 08:42:32PM +0100, Andreas Jaeger wrote:
[..snip..]
> That's what I've asked myself also when fixing the dynamic linker.
> But Ralf convinced me that $31 will get filled in (and I verified that
> it did) - otherwise the dynamic linker would not work on any system at
> all.
>
> But it might be worth checking if Guido notices a problem.
Not in elf_machine_load_address but in _dl_runtime_resolve(see my other
posting), I just came across it when looking at dl-machine.h.
-- Guido
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: understanding elf_machine_load_address
2001-12-08 16:47 ` Daniel Jacobowitz
2001-12-08 19:42 ` Andreas Jaeger
@ 2001-12-08 20:52 ` Andreas Jaeger
2001-12-08 21:03 ` Daniel Jacobowitz
1 sibling, 1 reply; 8+ messages in thread
From: Andreas Jaeger @ 2001-12-08 20:52 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Guido Guenther, linux-mips
Daniel Jacobowitz <dan@debian.org> writes:
> On Sat, Dec 08, 2001 at 04:18:53PM +0100, Andreas Jaeger wrote:
>> > " 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.
>
> Wait a second. Does bltzal fill in $31 even on a not-taken branch?
> Because bltzal $0 should never be taken. My handy MIPS reference and
> SPIM seem to agree that it won't fill in $31.
I just checked the MIPS R4000 Microprocessor Manual, 2nd Ed. by Joe
Heinrich and it mentions "Unconditanally, the address of the
instruction after the delay slot is placed in the link register, $31".
Therefore the code is correct.
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: understanding elf_machine_load_address
2001-12-08 20:52 ` Andreas Jaeger
@ 2001-12-08 21:03 ` Daniel Jacobowitz
0 siblings, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2001-12-08 21:03 UTC (permalink / raw)
To: Andreas Jaeger; +Cc: Guido Guenther, linux-mips
On Sat, Dec 08, 2001 at 09:52:01PM +0100, Andreas Jaeger wrote:
> Daniel Jacobowitz <dan@debian.org> writes:
>
> > On Sat, Dec 08, 2001 at 04:18:53PM +0100, Andreas Jaeger wrote:
> >> > " 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.
> >
> > Wait a second. Does bltzal fill in $31 even on a not-taken branch?
> > Because bltzal $0 should never be taken. My handy MIPS reference and
> > SPIM seem to agree that it won't fill in $31.
>
> I just checked the MIPS R4000 Microprocessor Manual, 2nd Ed. by Joe
> Heinrich and it mentions "Unconditanally, the address of the
> instruction after the delay slot is placed in the link register, $31".
> Therefore the code is correct.
OK, thanks. Yet another thing that changed between my simulator and my
hardware :)
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2001-12-08 22:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-12-08 14:11 understanding elf_machine_load_address Guido Guenther
2001-12-08 15:18 ` Andreas Jaeger
2001-12-08 16:37 ` Guido Guenther
2001-12-08 16:47 ` Daniel Jacobowitz
2001-12-08 19:42 ` Andreas Jaeger
2001-12-08 20:23 ` Guido Guenther
2001-12-08 20:52 ` Andreas Jaeger
2001-12-08 21:03 ` Daniel Jacobowitz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.