From: Marcus Shawcroft <marcus.shawcroft@linaro.org>
To: Mark Salter <msalter@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>,
libc-ports <libc-ports@sourceware.org>
Subject: Re: aarch64 prelink issue
Date: Wed, 26 Jun 2013 15:36:00 -0000 [thread overview]
Message-ID: <CABXK9neZz4zhyEzvgeE91+iYBNg3FcboYxKWjWp-R6FeUeR0rw@mail.gmail.com> (raw)
In-Reply-To: <1372250579.3739.42.camel@t520.redhat.com>
On 26 June 2013 13:42, Mark Salter <msalter@redhat.com> wrote:
> On Mon, 2013-06-24 at 10:18 -0700, Richard Henderson wrote:
>> Try the x86_64 solution:
>>
>> /* This produces an IP-relative reloc which is resolved at link time. */
>> extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
>> return _GLOBAL_OFFSET_TABLE_[0];
>>
>> with the extra hidden attribute, this should result in an ADR(P)
>> reference to the _G_O_T_.
>>
>
> This isn't working for aarch64. It doesn't use a PC-relative reference
> and it tries reading from the GOT at the link time absolute address.
It looks to me that Richard's proposal gives the correct sequence in
elf_machine_dynamic():
adrp x0, _GLOBAL_OFFSET_TABLE_
ldr x0, [x0,#:lo12:_GLOBAL_OFFSET_TABLE_]
ret
... but, this exposes an issue in the static linker:
Currently the static linker produces:
.got
<-_GLOBAL_OFFSET_TABLE_
...
.gotplt[0] &_DYNAMIC <--DT_PLTGOT
.gotplt[1] reserved for ld.so (&linkmap)
.gotplt[2] reserved fpr ld.so (resolver)
...
This layout is broken wrt the placement of &_DYNAMIC. The correct
layout should be:
.got[0] &_DYNAMIC <-_GLOBAL_OFFSET_TABLE_
...
.gotplt[0] reserved for ld.so (&linkmap) <--DT_PLTGOT
.gotplt[1] reserved fpr ld.so (resolver)
...
Hence when we use Richard's suggestion we end up picking junk out of .got[0]
I'm still looking at this, but at the moment I think we can fix the
static linker to emit:
.got[0] &_DYNAMIC <-_GLOBAL_OFFSET_TABLE_
...
.gotplt[0] reserved for ld.so (&linkmap) <--DT_PLTGOT
.gotplt[1] reserved for ld.so (resolver)
.gotplt[2] reserved
With this change, I believe that we do not introduce an
incompatibility between existing binaries / .so's and the modified
ld.so because the code within elf_machine_dynamic() is only
instantiated within ld.so and is only used to inspect ld.so's own
image.
The .gotplt[2] entry remains reserved in the new layout to ensure that
an unmodified ld.so can load a binary built using a modified static ld
without clobbering the first real PLT entry.
I'd really appreciate some feedback on the sanity of this proposal.
Thanks
/Marcus
next prev parent reply other threads:[~2013-06-26 15:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-24 16:41 Mark Salter
2013-06-24 17:18 ` Richard Henderson
2013-06-26 12:43 ` Mark Salter
2013-06-26 15:36 ` Marcus Shawcroft [this message]
2013-06-26 16:48 ` Richard Henderson
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=CABXK9neZz4zhyEzvgeE91+iYBNg3FcboYxKWjWp-R6FeUeR0rw@mail.gmail.com \
--to=marcus.shawcroft@linaro.org \
--cc=libc-ports@sourceware.org \
--cc=msalter@redhat.com \
--cc=rth@twiddle.net \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).