From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: ppc soft-float regression
Date: Mon, 18 May 2015 16:14:23 -0400 [thread overview]
Message-ID: <20150518201422.GY17573@brightrain.aerifal.cx> (raw)
In-Reply-To: <20150518201043.GX17573@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 2484 bytes --]
On Mon, May 18, 2015 at 04:10:43PM -0400, Rich Felker wrote:
> OK I've looked at this and I understand what's happening. PowerPC does
> not have a separate relocation type for GOT entries; instead it uses
> the same relocation type used for address constants global data. These
> do not get re-processed after the main program and libraries are
> added, because unlike GOT slots, they have addends, and if the addend
> is inline (using REL rather than RELA) then it's already been
> clobbered by the early relocation phase and can't easily be recovered.
>
> I see three possible solutions:
>
> 1. Treat R_PPC_ADDR32 as a GOT relocation instead of a regular
> symbolic relocation in data. This would suppress the addend (giving
> wrong address) if inline addends (REL) were used, but in practice
> powerpc aways uses RELA. I consider this a hack, and perhaps risky,
> since in principle someone could make powerpc binaries with REL.
>
> 2. Re-process not just GOT type relocs, but also any RELA
> (non-inline-addend) relocs again on the second pass. This would
> work as long as powerpc only uses RELA, and if REL is ever used,
> the worst that would happen is the current bug (losing environ,
> etc.) rather than silently wrong relocations in global data. This
> approach is not a hack, but I consider it something of an
> incomplete fix.
>
> 3. Re-process all symbolic relocations. For REL-type (inline addend),
> we have to recover the original addend, which can be done by
> calling find_sym again, but using ldso instead of the current
> library chain head as the context to search for the symbol in, then
> subtracting the resulting address to get back the original addend.
>
> I like the third solution best, even though it incurs a small code
> size cost and a performance cost for archs using REL, because it's
> completely robust against any weird ways some archs might end up using
> relocations. The expected number of such relocations is tiny anyway;
> on my i386 builds it's 14.
>
> If option 3 proves to be difficult or costly, however, we could
> consider option 2 as a temporary measure to get powerpc working. It
> wouldn't even need to be reverted, because option 3 includes/subsumes
> the work that would be done for option 2.
Attached is a patch to implement option 2. I'll probably commit it
soon anyway but here is it in case you want to test sooner. I verified
it fixes the test program on powerpc for me.
Rich
[-- Attachment #2: reprocess_rela.diff --]
[-- Type: text/plain, Size: 473 bytes --]
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 7c92ef6..93595a0 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -281,7 +281,7 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
}
int gotplt = (type == REL_GOT || type == REL_PLT);
- if (dso->rel_update_got && !gotplt) continue;
+ if (dso->rel_update_got && !gotplt && stride==2) continue;
addend = stride>2 ? rel[2]
: gotplt || type==REL_COPY ? 0
next prev parent reply other threads:[~2015-05-18 20:14 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-17 8:03 Waldemar Brodkorb
2015-05-17 10:02 ` Felix Janda
2015-05-17 16:37 ` Rich Felker
2015-05-17 17:50 ` Felix Janda
2015-05-17 18:15 ` Felix Janda
2015-05-17 19:56 ` Felix Janda
2015-05-18 18:39 ` Felix Janda
2015-05-18 20:10 ` Rich Felker
2015-05-18 20:14 ` Rich Felker [this message]
2015-05-18 22:07 ` Felix Janda
2015-05-22 6:23 ` Rich Felker
2015-05-24 3:08 ` Rich Felker
2015-05-25 0:36 ` Rich Felker
2015-05-25 6:31 ` Jens Gustedt
2015-05-25 6:57 ` Rich Felker
2015-05-25 7:44 ` Jens Gustedt
2015-05-25 13:26 ` Szabolcs Nagy
2015-05-25 13:40 ` Alexander Monakov
2015-05-25 14:35 ` Szabolcs Nagy
2015-05-25 14:45 ` Alexander Monakov
2015-05-25 21:45 ` Rich Felker
2015-05-25 22:46 ` Rich Felker
2015-05-25 23:51 ` Rich Felker
2015-05-17 13:06 ` Felix Janda
2015-05-17 16:35 ` Rich Felker
2015-05-17 17:20 ` Szabolcs Nagy
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=20150518201422.GY17573@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).