Skip to content

Commit 73fb969

Browse files
committed
[asan][test] Several Posix/unpoison-alternate-stack.cpp fixes
`Posix/unpoison-alternate-stack.cpp` currently `FAIL`s on Solaris/i386. Some of the problems are generic: - `clang` warns compiling the testcase: compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp:83:7: warning: nested designators are a C99 extension [-Wc99-designator] .sa_sigaction = signalHandler, ^~~~~~~~~~~~~ compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp:84:7: warning: ISO C++ requires field designators to be specified in declaration order; field '_funcptr' will be initialized after field 'sa_flags' [-Wreorder-init-list] .sa_flags = SA_SIGINFO | SA_NODEFER | SA_ONSTACK, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ and some more instances. This can all easily be avoided by initializing each field separately. - The test `SEGV`s in `__asan_memcpy`. The default Solaris/i386 stack size is only 4 kB, while `__asan_memcpy` tries to allocate either 5436 (32-bit) or 10688 bytes (64-bit) on the stack. This patch avoids this by requiring at least 16 kB stack size. - Even without `-fsanitize=address` I get an assertion failure: Assertion failed: !isOnSignalStack(), file compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp, line 117 The fundamental problem with this testcase is that `longjmp` from a signal handler is highly unportable; XPG7 strongly warns against it and it is thus unspecified which stack is used when `longjmp`ing from a signal handler running on an alternative stack. So I'm `XFAIL`ing this testcase on Solaris. Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D88501
1 parent 2ab8770 commit 73fb969

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
// RUN: %run %t
88

99
// XFAIL: ios && !iossim
10+
// longjmp from signal handler is unportable.
11+
// XFAIL: solaris
1012

13+
#include <algorithm>
1114
#include <cassert>
1215
#include <cerrno>
1316
#include <csetjmp>
@@ -83,10 +86,9 @@ void signalHandler(int, siginfo_t *, void *) {
8386
void setSignalAlternateStack(void *AltStack) {
8487
sigaltstack((stack_t const *)AltStack, nullptr);
8588

86-
struct sigaction Action = {
87-
.sa_sigaction = signalHandler,
88-
.sa_flags = SA_SIGINFO | SA_NODEFER | SA_ONSTACK,
89-
};
89+
struct sigaction Action = {};
90+
Action.sa_sigaction = signalHandler;
91+
Action.sa_flags = SA_SIGINFO | SA_NODEFER | SA_ONSTACK;
9092
sigemptyset(&Action.sa_mask);
9193

9294
sigaction(SIGUSR1, &Action, nullptr);
@@ -137,9 +139,11 @@ void *threadFun(void *AltStack) {
137139
// reports when the stack is reused.
138140
int main() {
139141
size_t const PageSize = sysconf(_SC_PAGESIZE);
142+
// The Solaris defaults of 4k (32-bit) and 8k (64-bit) are too small.
143+
size_t const MinStackSize = std::max(PTHREAD_STACK_MIN, 16 * 1024);
140144
// To align the alternate stack, we round this up to page_size.
141145
size_t const DefaultStackSize =
142-
(PTHREAD_STACK_MIN - 1 + PageSize) & ~(PageSize - 1);
146+
(MinStackSize - 1 + PageSize) & ~(PageSize - 1);
143147
// The alternate stack needs a certain size, or the signal handler segfaults.
144148
size_t const AltStackSize = 10 * PageSize;
145149
size_t const MappingSize = DefaultStackSize + AltStackSize;
@@ -149,11 +153,10 @@ int main() {
149153
MAP_PRIVATE | MAP_ANONYMOUS,
150154
-1, 0);
151155

152-
stack_t const AltStack = {
153-
.ss_sp = (char *)Mapping + DefaultStackSize,
154-
.ss_flags = 0,
155-
.ss_size = AltStackSize,
156-
};
156+
stack_t AltStack = {};
157+
AltStack.ss_sp = (char *)Mapping + DefaultStackSize;
158+
AltStack.ss_flags = 0;
159+
AltStack.ss_size = AltStackSize;
157160

158161
pthread_t Thread;
159162
pthread_attr_t ThreadAttr;

0 commit comments

Comments
 (0)