mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: [musl] Why the entries in the dynamic section are not always relocated?
Date: Sun, 8 May 2022 13:39:10 +0200	[thread overview]
Message-ID: <20220508113910.GC7958@voyager> (raw)
In-Reply-To: <CAFjbc8H+ZpF2cOs8cdpurTo=dm6W5dJsAYbVurtkn0ZRa-13Kw@mail.gmail.com>

On Sun, May 08, 2022 at 08:48:29AM +0100, Pablo Galindo Salgado wrote:
> Why is this happening?

The easy question first: This is happening because glibc finds some
value in writing the actual addresses into the dynamic section, and musl
does not. All of the addresses given in the dynamic section must
necessarily be offsets into the library itself (rather, the run-time map
of the library), so anyone who knows the base address of the library can
interpret these values, anyway.

See, you are accessing an implementation detail here. I am not aware of
any documentation of dl_iterate_phdr() which says whether the dynamic
section is relocated or not. Which leads directly to:

> How can one programmatically know when the linker is
> going to place here offsets or full
> relocated addresses?

In general, you cannot. You could reconstruct the length of the library
mapping from the LOAD headers, then heuristically assume that any value
below that is an offset, and any value above it probably a pointer.
Doesn't help you far, though, since you also need the base address.
Though I suppose you could assume that the start of the page the PHDRs
start on is likely the base of the library mapping.

Also, the heuristic will fail for libraries mapped to a low address. In
theory, all address space after the zero page is fair game, right? But
libraries can take more space than that.

And God help you if you ever run into an FDPIC architecture.

It appears to me that whatever you are trying to do is not possible
portibly on Linux at this time. Could you fill us in?

Ciao,
Markus

  reply	other threads:[~2022-05-08 11:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-08  7:48 Pablo Galindo Salgado
2022-05-08 11:39 ` Markus Wichmann [this message]
2022-05-08 13:54   ` Rich Felker
2022-05-08 14:23     ` Pablo Galindo Salgado
2022-05-08 19:38       ` 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=20220508113910.GC7958@voyager \
    --to=nullplan@gmx.net \
    --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).