diff options
author | Aliaksey Kandratsenka <alk@tut.by> | 2013-12-14 12:03:02 -0800 |
---|---|---|
committer | Aliaksey Kandratsenka <alk@tut.by> | 2013-12-14 17:58:33 -0800 |
commit | 7bd193bca97d93b43ff6c824bc9f39227329312f (patch) | |
tree | c27e10cd3dd79f3675d0e16451a29d8e2659363b | |
parent | f8a2163b5131050765ea877e2573f4930e41f630 (diff) | |
download | gperftools-7bd193bca97d93b43ff6c824bc9f39227329312f.tar.gz |
issue-586: detect main executable even if PIE is active
Previous logic of detecting main program addresses is to assume that
main executable is at least addressess. With PIE (active by default on
Ubuntus) it doesn't work.
In order to deal with that, we're attempting to find main executable
mapping in /proc/[pid]/maps. And old logic is preserved too just in
case.
-rwxr-xr-x | src/pprof | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -71,6 +71,7 @@ use strict; use warnings; use Getopt::Long; +use Cwd; my $PPROF_VERSION = "2.0"; @@ -4326,7 +4327,7 @@ sub ParseTextSectionHeader { # Split /proc/pid/maps dump into a list of libraries sub ParseLibraries { return if $main::use_symbol_page; # We don't need libraries info. - my $prog = shift; + my $prog = Cwd::abs_path(shift); my $map = shift; my $pcs = shift; @@ -4359,6 +4360,16 @@ sub ParseLibraries { $finish = HexExtend($2); $offset = $zero_offset; $lib = $3; + } elsif (($l =~ /^($h)-($h)\s+..x.\s+($h)\s+\S+:\S+\s+\d+\s+(\S+)$/i) && ($4 eq $prog)) { + # PIEs and address space randomization do not play well with our + # default assumption that main executable is at lowest + # addresses. So we're detecting main executable in + # /proc/self/maps as well. + $start = HexExtend($1); + $finish = HexExtend($2); + $offset = HexExtend($3); + $lib = $4; + $lib =~ s|\\|/|g; # turn windows-style paths into unix-style paths } else { next; } |