mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Dynamic linker changes
Date: Wed, 8 Apr 2015 19:19:11 -0400	[thread overview]
Message-ID: <20150408231911.GK6817@brightrain.aerifal.cx> (raw)
In-Reply-To: <20150405225533.GH6817@brightrain.aerifal.cx>

So far I've been hitting some ugly obstacles:

1. If we want the new code to eliminate the need for platform-specific
__reloc_self functions for mips/microblaze/powerpc/etc., the first
phase needs to perform relative relocations without making _any_
function calls, since even calls to static functions go through
(anonymous) got entries. That's not such a bad idea if it would
eliminate this ugly per-arch code, but...

2. The current method of making relocations generic rather than
arch-specific uses a function/switch statement to remap them. This is
not going to be usable for solving item 1 above in an arch-agnostic
manner. So perhaps we should replace this function with a set of
macros. Rather than having generic values for the REL_* macros and
mapping the R_{arch}_* values to them with switch, we could do
something like (example for microblaze):

#define REL_SYMBOLIC R_MICROBLAZE_32
#define REL_GOT R_MICROBLAZE_GLOB_DAT
...

However it's not clear to me whether the mapping from arch-specific
reloc types to generic ones is one-to-one in all archs, so we'd
potentially have to have extra macros like REL_SYMBOLIC_2.

One benefit of this approach, on the other hand, is that the switch in
the portable reloc processing code can have #ifdef around each case
and eliminate code for relocations a given arch doesn't support.
(Technically the compiler's dead code elimination could already after
inlining the mapping function or performing inter-procedural range
analysis, but I seriously doubt it did so.)

3. The original plan was to have one early-ldso-relocation step and
avoid all possible GOT/globals use and everything after that free to
use arbitrary global data and symbols, with a single barrier in
between to prevent reordering of GOT loads before they're relocated.
This seems impractical since it's hard, due to issue 1, do to symbolic
relocations without being able to make function calls.

Instead I'd like to treat the early-ldso-relocation process as two
steps. The first is generalizing and making arch-agnostic the work
mips, microblaze, and powerpc are doing now to get to a state where
all non-symbolic global accesses are safe. The second would be a
separate function call from the asm (or chained from the first if
there's an obvious way to do it) that performs symbolic relocations on
itself. It would end by (as proposed in the sketch before) doing a
symbol lookup and final call into the code that will setup the dso
chain, load dependencies, perform all remaining relocations, and pass
control to the program's entry point.

Rich


  reply	other threads:[~2015-04-08 23:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-05 22:30 Rich Felker
2015-04-05 22:55 ` Rich Felker
2015-04-08 23:19   ` Rich Felker [this message]
2015-04-11 20:21     ` Rich Felker
2015-04-12  1:59       ` Rich Felker

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=20150408231911.GK6817@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).