mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
mtrace: Fix output with PIE and ASLR [BZ #22716]
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. Fixes BZ #22716. Co-authored-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Andreas Schwab <schwab@linux-m68k.org> Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
@@ -65,9 +65,9 @@ tr_where (const void *caller, Dl_info *info)
|
|||||||
offset);
|
offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (mallstream, "@ %s%s%s[%p] ", info->dli_fname ? : "",
|
fprintf (mallstream, "@ %s%s%s[0x%" PRIxPTR "] ",
|
||||||
info->dli_fname ? ":" : "",
|
info->dli_fname ? : "", info->dli_fname ? ":" : "", buf,
|
||||||
buf, caller);
|
caller - info->dli_fbase);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fprintf (mallstream, "@ [%p] ", caller);
|
fprintf (mallstream, "@ [%p] ", caller);
|
||||||
|
@@ -75,11 +75,15 @@ if ($#ARGV == 0) {
|
|||||||
} else {
|
} else {
|
||||||
$prog = "./$binary";
|
$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>) {
|
while (<LOCS>) {
|
||||||
chop;
|
chop;
|
||||||
if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) {
|
if (/^.*=> (.*) \((0x[0123456789abcdef]*), (0x[0123456789abcdef]*).*/) {
|
||||||
$locs{$1} = $2;
|
$locs{$1} = $2;
|
||||||
|
$rel{$1} = hex($2) - hex($3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close (LOCS);
|
close (LOCS);
|
||||||
@@ -110,12 +114,7 @@ sub location {
|
|||||||
my $addr = $2;
|
my $addr = $2;
|
||||||
my $searchaddr;
|
my $searchaddr;
|
||||||
return $cache{$addr} if (exists $cache{$addr});
|
return $cache{$addr} if (exists $cache{$addr});
|
||||||
if ($locs{$prog} ne "") {
|
$searchaddr = sprintf "%#x", hex($addr) + $rel{$prog};
|
||||||
$searchaddr = sprintf "%#x", $addr - $locs{$prog};
|
|
||||||
} else {
|
|
||||||
$searchaddr = $addr;
|
|
||||||
$prog = $binary;
|
|
||||||
}
|
|
||||||
if ($binary ne "" && open (ADDR, "addr2line -e $prog $searchaddr|")) {
|
if ($binary ne "" && open (ADDR, "addr2line -e $prog $searchaddr|")) {
|
||||||
my $line = <ADDR>;
|
my $line = <ADDR>;
|
||||||
chomp $line;
|
chomp $line;
|
||||||
|
Reference in New Issue
Block a user