Revert "Add support for custom loaders to symbolizer"
This broke the windows buildbots, revert for now. This reverts commit 24050b5ddef42f6f3306aa94d4a1f42a7893a9a7. llvm-svn: 314347
This commit is contained in:
parent
53eb637115
commit
cb15e22b3b
|
@ -727,10 +727,9 @@ class LoadedModule {
|
||||||
// filling this information.
|
// filling this information.
|
||||||
class ListOfModules {
|
class ListOfModules {
|
||||||
public:
|
public:
|
||||||
ListOfModules() {}
|
ListOfModules() : modules_(kInitialCapacity) {}
|
||||||
~ListOfModules() { clear(); }
|
~ListOfModules() { clear(); }
|
||||||
void init();
|
void init();
|
||||||
void fallbackInit(); // Uses fallback init if available, otherwise clears
|
|
||||||
const LoadedModule *begin() const { return modules_.begin(); }
|
const LoadedModule *begin() const { return modules_.begin(); }
|
||||||
LoadedModule *begin() { return modules_.begin(); }
|
LoadedModule *begin() { return modules_.begin(); }
|
||||||
const LoadedModule *end() const { return modules_.end(); }
|
const LoadedModule *end() const { return modules_.end(); }
|
||||||
|
@ -746,11 +745,8 @@ class ListOfModules {
|
||||||
for (auto &module : modules_) module.clear();
|
for (auto &module : modules_) module.clear();
|
||||||
modules_.clear();
|
modules_.clear();
|
||||||
}
|
}
|
||||||
void clearOrInit() {
|
|
||||||
modules_.capacity() ? clear() : modules_.Initialize(kInitialCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
InternalMmapVectorNoCtor<LoadedModule> modules_;
|
InternalMmapVector<LoadedModule> modules_;
|
||||||
// We rarely have more than 16K loaded modules.
|
// We rarely have more than 16K loaded modules.
|
||||||
static const uptr kInitialCapacity = 1 << 14;
|
static const uptr kInitialCapacity = 1 << 14;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "sanitizer_placement_new.h"
|
#include "sanitizer_placement_new.h"
|
||||||
#include "sanitizer_procmaps.h"
|
#include "sanitizer_procmaps.h"
|
||||||
#include "sanitizer_stacktrace.h"
|
#include "sanitizer_stacktrace.h"
|
||||||
#include "sanitizer_symbolizer.h"
|
|
||||||
|
|
||||||
#include <dlfcn.h> // for dlsym()
|
#include <dlfcn.h> // for dlsym()
|
||||||
#include <link.h>
|
#include <link.h>
|
||||||
|
@ -425,7 +424,7 @@ typedef ElfW(Phdr) Elf_Phdr;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
struct DlIteratePhdrData {
|
struct DlIteratePhdrData {
|
||||||
InternalMmapVectorNoCtor<LoadedModule> *modules;
|
InternalMmapVector<LoadedModule> *modules;
|
||||||
bool first;
|
bool first;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -463,37 +462,21 @@ extern "C" __attribute__((weak)) int dl_iterate_phdr(
|
||||||
int (*)(struct dl_phdr_info *, size_t, void *), void *);
|
int (*)(struct dl_phdr_info *, size_t, void *), void *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool requiresProcmaps() {
|
void ListOfModules::init() {
|
||||||
|
clear();
|
||||||
#if SANITIZER_ANDROID && __ANDROID_API__ <= 22
|
#if SANITIZER_ANDROID && __ANDROID_API__ <= 22
|
||||||
|
u32 api_level = AndroidGetApiLevel();
|
||||||
// Fall back to /proc/maps if dl_iterate_phdr is unavailable or broken.
|
// Fall back to /proc/maps if dl_iterate_phdr is unavailable or broken.
|
||||||
// The runtime check allows the same library to work with
|
// The runtime check allows the same library to work with
|
||||||
// both K and L (and future) Android releases.
|
// both K and L (and future) Android releases.
|
||||||
return AndroidGetApiLevel() <= ANDROID_LOLLIPOP_MR1;
|
if (api_level <= ANDROID_LOLLIPOP_MR1) { // L or earlier
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void procmapsInit(InternalMmapVectorNoCtor<LoadedModule> *modules) {
|
|
||||||
MemoryMappingLayout memory_mapping(false);
|
MemoryMappingLayout memory_mapping(false);
|
||||||
memory_mapping.DumpListOfModules(modules);
|
memory_mapping.DumpListOfModules(&modules_);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
void ListOfModules::init() {
|
#endif
|
||||||
clearOrInit();
|
|
||||||
if (requiresProcmaps()) {
|
|
||||||
procmapsInit(&modules_);
|
|
||||||
} else {
|
|
||||||
DlIteratePhdrData data = {&modules_, true};
|
DlIteratePhdrData data = {&modules_, true};
|
||||||
dl_iterate_phdr(dl_iterate_phdr_cb, &data);
|
dl_iterate_phdr(dl_iterate_phdr_cb, &data);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When a custom loader is used, dl_iterate_phdr may not contain the full
|
|
||||||
// list of modules. Allow callers to fall back to using procmaps.
|
|
||||||
void ListOfModules::fallbackInit() {
|
|
||||||
clearOrInit();
|
|
||||||
if (!requiresProcmaps()) procmapsInit(&modules_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getrusage does not give us the current RSS, only the max RSS.
|
// getrusage does not give us the current RSS, only the max RSS.
|
||||||
|
|
|
@ -411,13 +411,11 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListOfModules::init() {
|
void ListOfModules::init() {
|
||||||
clearOrInit();
|
clear();
|
||||||
MemoryMappingLayout memory_mapping(false);
|
MemoryMappingLayout memory_mapping(false);
|
||||||
memory_mapping.DumpListOfModules(&modules_);
|
memory_mapping.DumpListOfModules(&modules_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListOfModules::fallbackInit() { clear(); }
|
|
||||||
|
|
||||||
static HandleSignalMode GetHandleSignalModeImpl(int signum) {
|
static HandleSignalMode GetHandleSignalModeImpl(int signum) {
|
||||||
switch (signum) {
|
switch (signum) {
|
||||||
case SIGABRT:
|
case SIGABRT:
|
||||||
|
|
|
@ -76,7 +76,7 @@ class MemoryMappingLayout {
|
||||||
static void CacheMemoryMappings();
|
static void CacheMemoryMappings();
|
||||||
|
|
||||||
// Adds all mapped objects into a vector.
|
// Adds all mapped objects into a vector.
|
||||||
void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
|
void DumpListOfModules(InternalMmapVector<LoadedModule> *modules);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadFromCache();
|
void LoadFromCache();
|
||||||
|
|
|
@ -120,7 +120,7 @@ void MemoryMappingLayout::LoadFromCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryMappingLayout::DumpListOfModules(
|
void MemoryMappingLayout::DumpListOfModules(
|
||||||
InternalMmapVectorNoCtor<LoadedModule> *modules) {
|
InternalMmapVector<LoadedModule> *modules) {
|
||||||
Reset();
|
Reset();
|
||||||
InternalScopedString module_name(kMaxPathLength);
|
InternalScopedString module_name(kMaxPathLength);
|
||||||
MemoryMappedSegment segment(module_name.data(), module_name.size());
|
MemoryMappedSegment segment(module_name.data(), module_name.size());
|
||||||
|
|
|
@ -353,7 +353,7 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryMappingLayout::DumpListOfModules(
|
void MemoryMappingLayout::DumpListOfModules(
|
||||||
InternalMmapVectorNoCtor<LoadedModule> *modules) {
|
InternalMmapVector<LoadedModule> *modules) {
|
||||||
Reset();
|
Reset();
|
||||||
InternalScopedString module_name(kMaxPathLength);
|
InternalScopedString module_name(kMaxPathLength);
|
||||||
MemoryMappedSegment segment(module_name.data(), kMaxPathLength);
|
MemoryMappedSegment segment(module_name.data(), kMaxPathLength);
|
||||||
|
|
|
@ -119,7 +119,6 @@ class Symbolizer final {
|
||||||
void AddHooks(StartSymbolizationHook start_hook,
|
void AddHooks(StartSymbolizationHook start_hook,
|
||||||
EndSymbolizationHook end_hook);
|
EndSymbolizationHook end_hook);
|
||||||
|
|
||||||
void RefreshModules();
|
|
||||||
const LoadedModule *FindModuleForAddress(uptr address);
|
const LoadedModule *FindModuleForAddress(uptr address);
|
||||||
|
|
||||||
void InvalidateModuleList();
|
void InvalidateModuleList();
|
||||||
|
@ -152,7 +151,6 @@ class Symbolizer final {
|
||||||
uptr *module_offset,
|
uptr *module_offset,
|
||||||
ModuleArch *module_arch);
|
ModuleArch *module_arch);
|
||||||
ListOfModules modules_;
|
ListOfModules modules_;
|
||||||
ListOfModules fallback_modules_;
|
|
||||||
// If stale, need to reload the modules before looking up addresses.
|
// If stale, need to reload the modules before looking up addresses.
|
||||||
bool modules_fresh_;
|
bool modules_fresh_;
|
||||||
|
|
||||||
|
|
|
@ -163,47 +163,29 @@ bool Symbolizer::FindModuleNameAndOffsetForAddress(uptr address,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Symbolizer::RefreshModules() {
|
|
||||||
modules_.init();
|
|
||||||
fallback_modules_.fallbackInit();
|
|
||||||
RAW_CHECK(modules_.size() > 0);
|
|
||||||
modules_fresh_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const LoadedModule *SearchForModule(const ListOfModules &modules,
|
|
||||||
uptr address) {
|
|
||||||
for (uptr i = 0; i < modules.size(); i++) {
|
|
||||||
if (modules[i].containsAddress(address)) {
|
|
||||||
return &modules[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const LoadedModule *Symbolizer::FindModuleForAddress(uptr address) {
|
const LoadedModule *Symbolizer::FindModuleForAddress(uptr address) {
|
||||||
bool modules_were_reloaded = false;
|
bool modules_were_reloaded = false;
|
||||||
if (!modules_fresh_) {
|
if (!modules_fresh_) {
|
||||||
RefreshModules();
|
modules_.init();
|
||||||
|
RAW_CHECK(modules_.size() > 0);
|
||||||
|
modules_fresh_ = true;
|
||||||
modules_were_reloaded = true;
|
modules_were_reloaded = true;
|
||||||
}
|
}
|
||||||
const LoadedModule *module = SearchForModule(modules_, address);
|
for (uptr i = 0; i < modules_.size(); i++) {
|
||||||
if (module) return module;
|
if (modules_[i].containsAddress(address)) {
|
||||||
|
return &modules_[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
// dlopen/dlclose interceptors invalidate the module list, but when
|
// dlopen/dlclose interceptors invalidate the module list, but when
|
||||||
// interception is disabled, we need to retry if the lookup fails in
|
// interception is disabled, we need to retry if the lookup fails in
|
||||||
// case the module list changed.
|
// case the module list changed.
|
||||||
#if !SANITIZER_INTERCEPT_DLOPEN_DLCLOSE
|
#if !SANITIZER_INTERCEPT_DLOPEN_DLCLOSE
|
||||||
if (!modules_were_reloaded) {
|
if (!modules_were_reloaded) {
|
||||||
RefreshModules();
|
modules_fresh_ = false;
|
||||||
module = SearchForModule(modules_, address);
|
return FindModuleForAddress(address);
|
||||||
if (module) return module;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
if (fallback_modules_.size()) {
|
|
||||||
module = SearchForModule(fallback_modules_, address);
|
|
||||||
}
|
|
||||||
return module;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For now we assume the following protocol:
|
// For now we assume the following protocol:
|
||||||
|
|
|
@ -524,7 +524,7 @@ static uptr GetPreferredBase(const char *modname) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListOfModules::init() {
|
void ListOfModules::init() {
|
||||||
clearOrInit();
|
clear();
|
||||||
HANDLE cur_process = GetCurrentProcess();
|
HANDLE cur_process = GetCurrentProcess();
|
||||||
|
|
||||||
// Query the list of modules. Start by assuming there are no more than 256
|
// Query the list of modules. Start by assuming there are no more than 256
|
||||||
|
@ -583,9 +583,7 @@ void ListOfModules::init() {
|
||||||
modules_.push_back(cur_module);
|
modules_.push_back(cur_module);
|
||||||
}
|
}
|
||||||
UnmapOrDie(hmodules, modules_buffer_size);
|
UnmapOrDie(hmodules, modules_buffer_size);
|
||||||
}
|
};
|
||||||
|
|
||||||
void ListOfModules::fallbackInit() { clear(); }
|
|
||||||
|
|
||||||
// We can't use atexit() directly at __asan_init time as the CRT is not fully
|
// We can't use atexit() directly at __asan_init time as the CRT is not fully
|
||||||
// initialized at this point. Place the functions into a vector and use
|
// initialized at this point. Place the functions into a vector and use
|
||||||
|
|
Loading…
Reference in New Issue