Skip to content

Commit dbee0d5

Browse files
authored
[NFCI] [hwasan] Add test demonstrating hwasan lsan false positive (#142874)
1 parent f6260da commit dbee0d5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// RUN: %clangxx_hwasan -O0 %s -o %t && HWASAN_OPTIONS=detect_leaks=1 %run %t
5+
// XFAIL: *
6+
7+
#include <assert.h>
8+
#include <dlfcn.h>
9+
#include <pthread.h>
10+
#include <sanitizer/hwasan_interface.h>
11+
#include <stdlib.h>
12+
#include <string.h>
13+
#include <unistd.h>
14+
15+
constexpr auto kKeys = 500;
16+
17+
int main(int argc, char **argv) {
18+
__hwasan_enable_allocator_tagging();
19+
// Exhaust static TLS slots to force use of dynamic TLS.
20+
pthread_key_t keys[kKeys];
21+
for (int i = 0; i < kKeys; ++i) {
22+
assert(pthread_key_create(&keys[i], nullptr) == 0);
23+
}
24+
void *o = dlopen("invalid_file_name.so", 0);
25+
const char *err = dlerror();
26+
for (int i = 0; i < kKeys; ++i) {
27+
assert(pthread_key_delete(keys[i]) == 0);
28+
}
29+
return 0;
30+
}

0 commit comments

Comments
 (0)