Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 |
| 2 | // XFAIL: android |
| 3 | // |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 4 | // RUN: %clangxx_asan -DSHARED %s -shared -o %T/stack_trace_dlclose.so -fPIC |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 5 | // RUN: %clangxx_asan -DSO_DIR=\"%T\" %s %libdl -o %t |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 6 | // RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 7 | // XFAIL: arm-linux-gnueabi |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 8 | // XFAIL: armv7l-unknown-linux-gnueabihf |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | |
| 10 | #include <assert.h> |
| 11 | #include <dlfcn.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <stdio.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | #include <sanitizer/common_interface_defs.h> |
| 17 | |
| 18 | #ifdef SHARED |
| 19 | extern "C" { |
| 20 | void *foo() { |
| 21 | return malloc(1); |
| 22 | } |
| 23 | } |
| 24 | #else |
| 25 | void *handle; |
| 26 | |
| 27 | int main(int argc, char **argv) { |
| 28 | void *handle = dlopen(SO_DIR "/stack_trace_dlclose.so", RTLD_LAZY); |
| 29 | assert(handle); |
| 30 | void *(*foo)() = (void *(*)())dlsym(handle, "foo"); |
| 31 | assert(foo); |
| 32 | void *p = foo(); |
| 33 | assert(p); |
| 34 | dlclose(handle); |
| 35 | |
| 36 | free(p); |
| 37 | free(p); // double-free |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | #endif |
| 42 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 43 | // CHECK: {{ #0 0x.* in (__interceptor_)?malloc}} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 44 | // CHECK: {{ #1 0x.* \(<unknown module>\)}} |
| 45 | // CHECK: {{ #2 0x.* in main}} |