diff options
author | Kamil Rytarowski <n54@gmx.com> | 2017-11-08 22:34:17 +0000 |
---|---|---|
committer | Kamil Rytarowski <n54@gmx.com> | 2017-11-08 22:34:17 +0000 |
commit | 43930933f7e78b57276ddda133ef1952398a882c (patch) | |
tree | 6179df280fb080259cd347ba8db4d0f1ee53358c /test | |
parent | 15532ad8e9d85186c2d96135ca45fff893ee8cd7 (diff) |
Correct atexit(3) support in TSan/NetBSD
Summary:
The NetBSD specific implementation of cxa_atexit() does not
preserve the 2nd argument if dso is equal to NULL.
Changes:
- Split paths of handling intercepted __cxa_atexit() and atexit(3).
This affects all supported Operating Systems.
- Add a local stack-like structure to hold the __cxa_atexit() context.
atexit(3) is documented in the C standard as calling callback from the
earliest to the oldest entry. This path also fixes potential ABI
problem of passing an argument to a function from the atexit(3)
callback mechanism.
- Add new test to ensure LIFO style of atexit(3) callbacks: atexit3.cc
Proposal to change the behavior of __cxa_atexit() in NetBSD has been rejected.
With the above changes TSan/NetBSD with the current tsan_interceptors.cc
can bootstrap into operation.
Sponsored by <The NetBSD Foundation>
Reviewers: vitalybuka, dvyukov, joerg, kcc, eugenis
Reviewed By: dvyukov
Subscribers: kubamracek, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D39619
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/tsan/atexit3.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/tsan/atexit3.cc b/test/tsan/atexit3.cc new file mode 100644 index 000000000..43ba5bbf6 --- /dev/null +++ b/test/tsan/atexit3.cc @@ -0,0 +1,41 @@ +// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <stdio.h> +#include <stdlib.h> + +static void atexit5() { + fprintf(stderr, "5"); +} + +static void atexit4() { + fprintf(stderr, "4"); +} + +static void atexit3() { + fprintf(stderr, "3"); +} + +static void atexit2() { + fprintf(stderr, "2"); +} + +static void atexit1() { + fprintf(stderr, "1"); +} + +static void atexit0() { + fprintf(stderr, "\n"); +} + +int main() { + atexit(atexit0); + atexit(atexit1); + atexit(atexit2); + atexit(atexit3); + atexit(atexit4); + atexit(atexit5); +} + +// CHECK-NOT: FATAL: ThreadSanitizer +// CHECK-NOT: WARNING: ThreadSanitizer +// CHECK: 54321 |