Skip to content

Commit

Permalink
cc: Correctly treat PIE files as shared objects for symbols
Browse files Browse the repository at this point in the history
When resolving symbols, ProcSyms would treat position-independent
executables (PIE files) incorrectly, resulting in symbol resolution
failures. Specifically, PIE files are treated like shared objects
for ASLR, which means all symbol addresses in the file need to be
taken relative to the executable load address at runtime, the same
as with dynamic library shared objects.

The fix is in the `is_so()` method on `ProcSyms::Module`, which
now uses the correct `bcc_elf_is_shared` helper for testing if a
file is a shared object rather than just looking at the extension
".so", which is very brittle -- and wrong.
  • Loading branch information
goldshtn committed Feb 21, 2017
1 parent 1e34f4e commit 7d8c29c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/cc/bcc_syms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ bool ProcSyms::resolve_name(const char *module, const char *name,
return false;
}

ProcSyms::Module::Module(const char *name, uint64_t start, uint64_t end)
: name_(name), start_(start), end_(end) {
is_so_ = bcc_elf_is_shared_obj(name) == 1;
}

int ProcSyms::Module::_add_symbol(const char *symname, uint64_t start,
uint64_t end, int flags, void *p) {
Module *m = static_cast<Module *>(p);
Expand All @@ -148,10 +153,6 @@ int ProcSyms::Module::_add_symbol(const char *symname, uint64_t start,
return 0;
}

bool ProcSyms::Module::is_so() const {
return strstr(name_.c_str(), ".so") != nullptr;
}

bool ProcSyms::Module::is_perf_map() const {
return strstr(name_.c_str(), ".map") != nullptr;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cc/syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ class ProcSyms : SymbolCache {
};

struct Module {
Module(const char *name, uint64_t start, uint64_t end)
: name_(name), start_(start), end_(end) {}
Module(const char *name, uint64_t start, uint64_t end);
std::string name_;
uint64_t start_;
uint64_t end_;
bool is_so_;
std::unordered_set<std::string> symnames_;
std::vector<Symbol> syms_;

void load_sym_table();
bool find_addr(uint64_t addr, struct bcc_symbol *sym);
bool find_name(const char *symname, uint64_t *addr);
bool is_so() const;
bool is_so() const { return is_so_; }
bool is_perf_map() const;

static int _add_symbol(const char *symname, uint64_t start, uint64_t end,
Expand Down

0 comments on commit 7d8c29c

Please sign in to comment.