xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/Linux/stack-trace-dlclose.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2*7c3d14c8STreehugger Robot // XFAIL: android
3*7c3d14c8STreehugger Robot //
4*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -DSHARED %s -shared -o %T/stack_trace_dlclose.so -fPIC
5*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -DSO_DIR=\"%T\" %s %libdl -o %t
6*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s
7*7c3d14c8STreehugger Robot // XFAIL: arm-linux-gnueabi
8*7c3d14c8STreehugger Robot // XFAIL: armv7l-unknown-linux-gnueabihf
9*7c3d14c8STreehugger Robot 
10*7c3d14c8STreehugger Robot #include <assert.h>
11*7c3d14c8STreehugger Robot #include <dlfcn.h>
12*7c3d14c8STreehugger Robot #include <stdlib.h>
13*7c3d14c8STreehugger Robot #include <stdio.h>
14*7c3d14c8STreehugger Robot #include <unistd.h>
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot #include <sanitizer/common_interface_defs.h>
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot #ifdef SHARED
19*7c3d14c8STreehugger Robot extern "C" {
foo()20*7c3d14c8STreehugger Robot void *foo() {
21*7c3d14c8STreehugger Robot   return malloc(1);
22*7c3d14c8STreehugger Robot }
23*7c3d14c8STreehugger Robot }
24*7c3d14c8STreehugger Robot #else
25*7c3d14c8STreehugger Robot void *handle;
26*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)27*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
28*7c3d14c8STreehugger Robot   void *handle = dlopen(SO_DIR "/stack_trace_dlclose.so", RTLD_LAZY);
29*7c3d14c8STreehugger Robot   assert(handle);
30*7c3d14c8STreehugger Robot   void *(*foo)() = (void *(*)())dlsym(handle, "foo");
31*7c3d14c8STreehugger Robot   assert(foo);
32*7c3d14c8STreehugger Robot   void *p = foo();
33*7c3d14c8STreehugger Robot   assert(p);
34*7c3d14c8STreehugger Robot   dlclose(handle);
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot   free(p);
37*7c3d14c8STreehugger Robot   free(p);  // double-free
38*7c3d14c8STreehugger Robot 
39*7c3d14c8STreehugger Robot   return 0;
40*7c3d14c8STreehugger Robot }
41*7c3d14c8STreehugger Robot #endif
42*7c3d14c8STreehugger Robot 
43*7c3d14c8STreehugger Robot // CHECK: {{    #0 0x.* in (__interceptor_)?malloc}}
44*7c3d14c8STreehugger Robot // CHECK: {{    #1 0x.* \(<unknown module>\)}}
45*7c3d14c8STreehugger Robot // CHECK: {{    #2 0x.* in main}}
46