| 1 |
// Make sure dlerror is not classified as a leak even if we use dynamic TLS. |
| 2 |
// This is currently not implemented, so this test is XFAIL. |
| 3 |
|
| 4 |
// Android HWAsan does not support LSan. |
| 5 |
// UNSUPPORTED: android |
| 6 |
|
| 7 |
// RUN: %clangxx_hwasan -O0 %s -o %t && HWASAN_OPTIONS=detect_leaks=1 %run %t |
| 8 |
|
| 9 |
#include <assert.h> |
| 10 |
#include <dlfcn.h> |
| 11 |
#include <pthread.h> |
| 12 |
#include <sanitizer/hwasan_interface.h> |
| 13 |
#include <stdlib.h> |
| 14 |
#include <string.h> |
| 15 |
#include <unistd.h> |
| 16 |
|
| 17 |
// musl only has 128 keys |
| 18 |
constexpr auto kKeys = 100; |
| 19 |
|
| 20 |
int main(int argc, char **argv) { |
| 21 |
__hwasan_enable_allocator_tagging(); |
| 22 |
// Exhaust static TLS slots to force use of dynamic TLS. |
| 23 |
pthread_key_t keys[kKeys]; |
| 24 |
for (int i = 0; i < kKeys; ++i) { |
| 25 |
assert(pthread_key_create(&keys[i], nullptr) == 0); |
| 26 |
} |
| 27 |
void *o = dlopen("invalid_file_name.so", 0); |
| 28 |
const char *err = dlerror(); |
| 29 |
for (int i = 0; i < kKeys; ++i) { |
| 30 |
assert(pthread_key_delete(keys[i]) == 0); |
| 31 |
} |
| 32 |
return 0; |
| 33 |
} |