Skip to content

Commit aa4dfd3

Browse files
authored
[hwasan] Fix and re-enable deep-recursion.c (#69265)
deep-recursion.c was disabled (c007e0f) because the test may get unlucky and end up with a zero-tagged variable, leading to a false negative (#69221). This patch re-enables the test and adds a workaround: it checks if the variable is zero-tagged, and if so, it will instead use the neighboring variable, which must have a different (hence non-zero) tag. Fixing the stack allocation tagging is left as an exercise for the reader. It is non-trivial because, even if the stackTagBase is non-zero, tags for subsequent allocations in the stack frame may wrap around to zero; working around this would require adding multiple instructions to each alloca. --------- Co-authored-by: Thurston Dang <thurston@google.com>
1 parent 4b8b70a commit aa4dfd3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

compiler-rt/test/hwasan/TestCases/deep-recursion.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
// Stack histories are currently not recorded on x86.
1818
// XFAIL: target=x86_64{{.*}}
1919

20-
// Flaky on AArch64 Linux, see https://github.com/llvm/llvm-project/issues/69221.
21-
// UNSUPPORTED: target=aarch64{{.*}}
22-
2320
#include <stdlib.h>
2421
// At least -O1 is needed for this function to not have a stack frame on
2522
// AArch64.
@@ -29,7 +26,23 @@ void USE(void *x) { // pretend_to_do_something(void *x)
2926

3027
volatile int four = 4;
3128

32-
__attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); }
29+
__attribute__((noinline)) void OOB() {
30+
int x[4];
31+
int y[4];
32+
33+
// Tags for stack-allocated variables can occasionally be zero, resulting in
34+
// a false negative for this test. This is not easy to fix, hence we work
35+
// around it: if the tag is zero, we use the neighboring variable instead,
36+
// which must have a different (hence non-zero) tag.
37+
// This tag check assumes aarch64.
38+
if (((uintptr_t)&x) >> 56 == 0) {
39+
y[four] = 0;
40+
} else {
41+
x[four] = 0;
42+
}
43+
USE(&x[0]);
44+
USE(&y[0]);
45+
}
3346
__attribute__((noinline)) void FUNC1() { int x; USE(&x); OOB(); }
3447
__attribute__((noinline)) void FUNC2() { int x; USE(&x); FUNC1(); }
3548
__attribute__((noinline)) void FUNC3() { int x; USE(&x); FUNC2(); }

0 commit comments

Comments
 (0)