unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org>
To: John Ogness <john.ogness@linutronix.de>, libc-alpha@sourceware.org
Subject: Re: [PATCH] mtrace: Fix output with PIE and ASLR [BZ #22716]
Date: Thu, 22 Jul 2021 20:47:28 +0530	[thread overview]
Message-ID: <917aac64-3f79-b6ed-0f17-aa2864a69362@sourceware.org> (raw)
In-Reply-To: <877dhis8z7.fsf@jogness.linutronix.de>

On 7/22/21 8:15 PM, John Ogness wrote:
> Thank you for the clarification. I forgot about non-pie. But then it
> means we are always interested in l_addr. l_map_start is irrelevant.

Not really.  The end result we want is an address that points to the 
correct symbol in the ELF binary.  We may think of that address as the 
ELF base address and the offset of the symbol from the base because 
regardless of whether the object is relocatable or not, the offset of 
the symbol will be constant from the base.

We get the offset of the symbol from base in the MALLOC_TRACE run; I 
have modified the output to be the offset instead of the actual address 
because for relocatable objects the actual address is practically 
useless across multiple runs.

In the second run (i.e. prelinking trace), we want to compute the ELF 
base address.  We have l_map_start (which is the actual base address in 
memory) and l_addr (which is l_map_start - ELF base address).  So the 
ELF base address is clearly l_map_start - l_addr.

Finally we get the symbol address as ELF base + offset recorded in the 
trace.

>> So the (l_addr - l_map_start) is 0 for PIC and PIE, but not for non-pie
>> executables.  Adding that relative offset in the binary for addr2line
>> will give you the correct symbol in both pic/pie and non-pie cases.
> 
> OK, but settings MALLOC_TRACE will cause the memory addresses to be
> stored. So it is l_addr that must be subtracted for addr2line.

My patch updates the dump to be that of the offset from base and not the 
actual address, which is why all of this works.

Siddhesh

  reply	other threads:[~2021-07-22 15:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22 13:24 [PATCH] mtrace: Fix output with PIE and ASLR [BZ #22716] Siddhesh Poyarekar via Libc-alpha
2021-07-22 14:12 ` John Ogness via Libc-alpha
2021-07-22 14:31   ` Siddhesh Poyarekar via Libc-alpha
2021-07-22 14:45     ` John Ogness via Libc-alpha
2021-07-22 15:17       ` Siddhesh Poyarekar via Libc-alpha [this message]
2021-07-22 15:19       ` Siddhesh Poyarekar via Libc-alpha
2021-08-11  7:41 ` [PING][PATCH] " Siddhesh Poyarekar via Libc-alpha
2021-08-12  4:15 ` [PATCH] " DJ Delorie via Libc-alpha
2021-08-12  4:33   ` Siddhesh Poyarekar via Libc-alpha
2021-08-12  4:35     ` DJ Delorie via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=917aac64-3f79-b6ed-0f17-aa2864a69362@sourceware.org \
    --to=libc-alpha@sourceware.org \
    --cc=john.ogness@linutronix.de \
    --cc=siddhesh@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).