[compiler-rt] r209522 - [sanitizer] Make stack traces from dlclose()'d modules more meaningful.
Sergey Matveev
earthdok at google.com
Fri May 23 09:04:42 PDT 2014
Author: smatveev
Date: Fri May 23 11:04:41 2014
New Revision: 209522
URL: http://llvm.org/viewvc/llvm-project?rev=209522&view=rev
Log:
[sanitizer] Make stack traces from dlclose()'d modules more meaningful.
Previously, they silently omitted PCs belonging to unknown modules. Now we print
(<unknown module>) instead.
Added:
compiler-rt/trunk/test/asan/TestCases/Linux/stack-trace-dlclose.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc?rev=209522&r1=209521&r2=209522&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc Fri May 23 11:04:41 2014
@@ -37,6 +37,14 @@ void StackTrace::PrintStack(const uptr *
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();
Added: compiler-rt/trunk/test/asan/TestCases/Linux/stack-trace-dlclose.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/stack-trace-dlclose.cc?rev=209522&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/stack-trace-dlclose.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/stack-trace-dlclose.cc Fri May 23 11:04:41 2014
@@ -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}}
More information about the llvm-commits
mailing list