* [PATCH v2] mtrace: Fix output with PIE and ASLR [BZ #22716]
@ 2021-08-12 4:41 Siddhesh Poyarekar
2021-08-12 8:00 ` Andreas Schwab
0 siblings, 1 reply; 2+ messages in thread
From: Siddhesh Poyarekar @ 2021-08-12 4:41 UTC (permalink / raw)
To: libc-alpha; +Cc: dj, John Ogness
Record only the relative address of the caller in mtrace file. Use
LD_TRACE_PRELINKING to get the executable as well as binary vs
executable load offsets so that we may compute a base to add to the
relative address in the mtrace file. This allows us to get a valid
address to pass to addr2line in all cases.
Co-authored-by: John Ogness <john.ogness@linutronix.de>
---
Changes from v1:
- Set LD_TRACE_PRELINK to an empty string so that it doesn't match any
files and add a comment explaining it.
- Formatting change in mtrace-impl.c
malloc/mtrace-impl.c | 6 +++---
malloc/mtrace.pl | 15 +++++++--------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/malloc/mtrace-impl.c b/malloc/mtrace-impl.c
index 6af1a6e01a..23afc9a1df 100644
--- a/malloc/mtrace-impl.c
+++ b/malloc/mtrace-impl.c
@@ -67,9 +67,9 @@ tr_where (const void *caller, Dl_info *info)
offset);
}
- fprintf (mallstream, "@ %s%s%s[%p] ", info->dli_fname ? : "",
- info->dli_fname ? ":" : "",
- buf, caller);
+ fprintf (mallstream, "@ %s%s%s[0x%" PRIxPTR "] ",
+ info->dli_fname ? : "", info->dli_fname ? ":" : "", buf,
+ caller - info->dli_fbase);
}
else
fprintf (mallstream, "@ [%p] ", caller);
diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl
index 6f49c8338d..bdc407122b 100644
--- a/malloc/mtrace.pl
+++ b/malloc/mtrace.pl
@@ -75,11 +75,15 @@ if ($#ARGV == 0) {
} else {
$prog = "./$binary";
}
- if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) {
+ # Set the environment variable LD_TRACE_PRELINKING to an empty string so
+ # that we trigger tracing but do not match with the executable or any of
+ # its dependencies.
+ if (open (LOCS, "env LD_TRACE_PRELINKING=\"\" $prog |")) {
while (<LOCS>) {
chop;
- if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) {
+ if (/^.*=> (.*) \((0x[0123456789abcdef]*), (0x[0123456789abcdef]*).*/) {
$locs{$1} = $2;
+ $rel{$1} = hex($2) - hex($3);
}
}
close (LOCS);
@@ -110,12 +114,7 @@ sub location {
my $addr = $2;
my $searchaddr;
return $cache{$addr} if (exists $cache{$addr});
- if ($locs{$prog} ne "") {
- $searchaddr = sprintf "%#x", $addr - $locs{$prog};
- } else {
- $searchaddr = $addr;
- $prog = $binary;
- }
+ $searchaddr = sprintf "%#x", hex($addr) + $rel{$prog};
if ($binary ne "" && open (ADDR, "addr2line -e $prog $searchaddr|")) {
my $line = <ADDR>;
chomp $line;
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mtrace: Fix output with PIE and ASLR [BZ #22716]
2021-08-12 4:41 [PATCH v2] mtrace: Fix output with PIE and ASLR [BZ #22716] Siddhesh Poyarekar
@ 2021-08-12 8:00 ` Andreas Schwab
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2021-08-12 8:00 UTC (permalink / raw)
To: Siddhesh Poyarekar via Libc-alpha; +Cc: Siddhesh Poyarekar, John Ogness
On Aug 12 2021, Siddhesh Poyarekar via Libc-alpha wrote:
> + if (open (LOCS, "env LD_TRACE_PRELINKING=\"\" $prog |")) {
No need for "".
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-08-12 8:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 4:41 [PATCH v2] mtrace: Fix output with PIE and ASLR [BZ #22716] Siddhesh Poyarekar
2021-08-12 8:00 ` Andreas Schwab
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).