From: linas@austin.ibm.com (Linas Vepstas)
To: Alan Modra <amodra@bigpond.net.au>
Cc: linuxppc-dev@ozlabs.org
Subject: Re: Why the "opd" section?
Date: Fri, 28 Jul 2006 13:19:09 -0500 [thread overview]
Message-ID: <20060728181909.GS7448@austin.ibm.com> (raw)
In-Reply-To: <20060725140634.GH6872@bubble.grove.modra.org>
On Tue, Jul 25, 2006 at 11:36:34PM +0930, Alan Modra wrote:
> >
> > So, why is it only in the 64-bit ELF? Is it just because it's a newer
> > idea?
>
> The idea isn't exactly new. It's more the case that the powerpc32 ABI
> is so old.
The basic idea/structure of the TOC was fixed in 1988, when the
linkage conventions for the pre-powerpc POWER were being speced.
I have no idea why the ppc32 ABI wouldn't have used this.
> > mflr 0
> > std 0,16(1)
> > stdu 1,-112(1)
> > bl addone
> > nop
> > bl addone
> > nop
> > addi 1,1,112
> > ld 0,16(1)
> > mtlr 0
> > blr
> >
> Yes, you're right. It does look to be branching directly to the opd
> entry at the assembly level. It of course won't do that because
> powerpc64-ld is clever enough to realise that doing so would never make
> any sense. Instead, ld does the OPD lookup and modifies the "bl" insns
> to go directly to the function's code entry if the TOC vallue of caller
> and callee is identical, or to go via a linker generated stub if they
> are different.
I beleive the no-op provides the space for the needed extra insns when
the linker goes to fix this up. If you disassemble the exectuable for
the case where addone is in some shared library, you'd see the bl replaced
by bl .glink (I think its called .glink, I don't remember), with the
.glink code fiddling with loading the right r2 TOC pointer as needed.
I've forgotten the details.
I vaguely remember yet another interesting trick, where the linker inserts
some dynamic-link stubs -- and so, when the subroutine is called for the
very first time ever, some additional linkage is done by the stub. I
have no idea if the current gcc/glibc do this.
--linas
next prev parent reply other threads:[~2006-07-28 18:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-24 4:01 Why the "opd" section? Jonathan Bartlett
2006-07-25 2:15 ` Alan Modra
2006-07-25 13:23 ` Jonathan Bartlett
2006-07-25 14:06 ` Alan Modra
2006-07-28 18:19 ` Linas Vepstas [this message]
2006-08-09 13:15 ` .tc entries question Jonathan Bartlett
2006-08-09 13:55 ` Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060728181909.GS7448@austin.ibm.com \
--to=linas@austin.ibm.com \
--cc=amodra@bigpond.net.au \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).