Skip to content

Commit

Permalink
[sanitizer] Make stack traces from dlclose()'d modules more meaningful.
Browse files Browse the repository at this point in the history
Previously, they silently omitted PCs belonging to unknown modules. Now we print
(<unknown module>) instead.

llvm-svn: 209522
  • Loading branch information
earthdok committed May 23, 2014
1 parent 3892013 commit 2be4a28
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Expand Up @@ -37,6 +37,14 @@ void StackTrace::PrintStack(const uptr *addr, uptr size) {
uptr pc = GetPreviousInstructionPc(addr[i]);
uptr addr_frames_num = Symbolizer::GetOrInit()->SymbolizePC(
pc, addr_frames.data(), addr_frames.size());
if (addr_frames_num == 0) {
frame_desc.clear();
PrintStackFramePrefix(&frame_desc, frame_num, pc);
frame_desc.append(" (<unknown module>)");
Printf("%s\n", frame_desc.data());
frame_num++;
continue;
}
for (uptr j = 0; j < addr_frames_num; j++) {
AddressInfo &info = addr_frames[j];
frame_desc.clear();
Expand Down
40 changes: 40 additions & 0 deletions compiler-rt/test/asan/TestCases/Linux/stack-trace-dlclose.cc
@@ -0,0 +1,40 @@
// RUN: %clangxx_asan -DSHARED %s -shared -o %T/stack_trace_dlclose.so -fPIC
// RUN: %clangxx_asan -DSO_DIR=\"%T\" %s -o %t
// RUN: ASAN_OPTIONS=exitcode=0 %run %t 2>&1 | FileCheck %s

#include <assert.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include <sanitizer/common_interface_defs.h>

#ifdef SHARED
extern "C" {
void *foo() {
return malloc(1);
}
}
#else
void *handle;

int main(int argc, char **argv) {
void *handle = dlopen(SO_DIR "/stack_trace_dlclose.so", RTLD_LAZY);
assert(handle);
void *(*foo)() = (void *(*)())dlsym(handle, "foo");
assert(foo);
void *p = foo();
assert(p);
dlclose(handle);

free(p);
free(p); // double-free

return 0;
}
#endif

// CHECK: {{ #0 0x.* in malloc}}
// CHECK: {{ #1 0x.* \(<unknown module>\)}}
// CHECK: {{ #2 0x.* in main}}

0 comments on commit 2be4a28

Please sign in to comment.