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.
This commit is contained in:
Aliaksey Kandratsenka 2013-12-14 12:03:02 -08:00 committed by David Goldblatt
parent d4e98bc0b2
commit 5bf800a542

View File

@ -71,6 +71,7 @@
use strict; use strict;
use warnings; use warnings;
use Getopt::Long; use Getopt::Long;
use Cwd;
my $JEPROF_VERSION = "@jemalloc_version@"; my $JEPROF_VERSION = "@jemalloc_version@";
my $PPROF_VERSION = "2.0"; my $PPROF_VERSION = "2.0";
@ -4570,7 +4571,7 @@ sub ParseTextSectionHeader {
# Split /proc/pid/maps dump into a list of libraries # Split /proc/pid/maps dump into a list of libraries
sub ParseLibraries { sub ParseLibraries {
return if $main::use_symbol_page; # We don't need libraries info. 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 $map = shift;
my $pcs = shift; my $pcs = shift;
@ -4603,6 +4604,16 @@ sub ParseLibraries {
$finish = HexExtend($2); $finish = HexExtend($2);
$offset = $zero_offset; $offset = $zero_offset;
$lib = $3; $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
} }
# FreeBSD 10.0 virtual memory map /proc/curproc/map as defined in # FreeBSD 10.0 virtual memory map /proc/curproc/map as defined in
# function procfs_doprocmap (sys/fs/procfs/procfs_map.c) # function procfs_doprocmap (sys/fs/procfs/procfs_map.c)