This is an archive of the discontinued LLVM Phabricator instance.

[HWASan] Added no-FP unit test for register dump.
ClosedPublic

Authored by hctim on Apr 16 2019, 5:02 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

hctim created this revision.Apr 16 2019, 5:02 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 16 2019, 5:02 PM
Herald added subscribers: llvm-commits, Restricted Project, kubamracek. · View Herald Transcript
pcc added inline comments.Apr 16 2019, 5:14 PM
compiler-rt/test/hwasan/TestCases/register-dump-no-fp.cc
44 ↗(On Diff #195491)

Maybe don't try to match this part since you're already matching for them in register-dump-read.c.

eugenis added inline comments.Apr 16 2019, 5:21 PM
compiler-rt/test/hwasan/TestCases/register-dump-no-fp.cc
2 ↗(On Diff #195491)

You are testing the case when f() does NOT have a frame pointer - why add these flags?

44 ↗(On Diff #195491)

Right. Just test that main() is in the stack trace, nothing more.

hctim updated this revision to Diff 195496.Apr 16 2019, 5:48 PM
hctim marked 4 inline comments as done.

Address @pcc and @eugenis comments.

compiler-rt/test/hwasan/TestCases/register-dump-no-fp.cc
2 ↗(On Diff #195491)

Is this in reference to the -ffixed-* flags? Assuming it is, have removed.

eugenis added inline comments.Apr 18 2019, 2:50 PM
compiler-rt/test/hwasan/TestCases/register-dump-no-fp.cc
2 ↗(On Diff #195491)

No, I meant *no-omit* flags. You are testing the case then f() does NOT have a frame pointer. These flags ADD frame pointer to all functions. The test case only works because they fail to apply to f() for unknown reason.

hctim updated this revision to Diff 195840.Apr 18 2019, 4:24 PM
hctim marked 2 inline comments as done.

/s/no-omit/omit

compiler-rt/test/hwasan/TestCases/register-dump-no-fp.cc
2 ↗(On Diff #195491)

Ack. Missed the double negative on the flag :)

eugenis accepted this revision.Apr 18 2019, 4:32 PM

LGTM

This revision is now accepted and ready to land.Apr 18 2019, 4:32 PM
This revision was automatically updated to reflect the committed changes.

Fyi - I accidentally committed using the wrong branch, just means that all of my local commits are going up one-by-one.

See d43dc9e78b2cd9ba7c578f25e47c54cf532c5ef4, 371f43a6c0f542eb20150c90341aaed09b78fc92, 371f43a6c0f542eb20150c90341aaed09b78fc92, 026781c96200c9afad31847a5f3cced947520604.

The final committed diff from all of these patches is (as was reviewed):

--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/register-dump-no-fp.cc
@@ -0,0 +1,28 @@
+// RUN: %clangxx_hwasan -fomit-frame-pointer -momit-leaf-frame-pointer \
+// RUN:   -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clangxx_hwasan -fomit-frame-pointer -momit-leaf-frame-pointer \
+// RUN:   -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clangxx_hwasan -fomit-frame-pointer -momit-leaf-frame-pointer \
+// RUN:   -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clangxx_hwasan -fomit-frame-pointer -momit-leaf-frame-pointer \
+// RUN:   -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+
+// This test ensures that the CFA is implemented properly for slow
+// (non-frame-pointer) unwinding.
+#include <sanitizer/hwasan_interface.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+__attribute__((noinline)) void f(int *p) { *p = 3; }
+
+// CHECK: ERROR: HWAddressSanitizer:
+// CHECK: #0 {{.*}} in f(int*) {{.*}}register-dump-no-fp.cc:[[@LINE-3]]
+
+int main() {
+  __hwasan_enable_allocator_tagging();
+
+  int *volatile a = new int;
+  a = (int *)__hwasan_tag_pointer(a, 0);
+  f(a);
+  // CHECK: #1 {{.*}} in main {{.*}}register-dump-no-fp.cc:[[@LINE-1]]
+}