[PATCH] D26927: [asan] Specialize the initialization-bug.cc testcase for Darwin (it needs a deployment target of 10.11+)
Kuba Brecka via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 21 12:54:19 PST 2016
kubabrecka created this revision.
kubabrecka added reviewers: kcc, zaks.anna, rnk, eugenis.
kubabrecka added a subscriber: llvm-commits.
kubabrecka set the repository for this revision to rL LLVM.
kubabrecka added a project: Sanitizers.
The ODR detection in initialization-bug.cc now works on Darwin (due to the recently enabled "live globals" on-by-default), but only if the deployment target is 10.11 or higher. Let's adjust the testcases.
Repository:
rL LLVM
https://reviews.llvm.org/D26927
Files:
test/asan/TestCases/Darwin/initialization-bug-darwin.cc
test/asan/TestCases/initialization-bug.cc
Index: test/asan/TestCases/initialization-bug.cc
===================================================================
--- test/asan/TestCases/initialization-bug.cc
+++ test/asan/TestCases/initialization-bug.cc
@@ -8,8 +8,8 @@
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186
// XFAIL: win32
-// The test is expected to fail on OS X Yosemite and older
-// UNSUPPORTED: osx-no-ld64-live_support
+// On macOS, this only works when targeting 10.11+. See TestCases/Darwin/initialization-bug-darwin.cc.
+// UNSUPPORTED: darwin
#include <cstdio>
Index: test/asan/TestCases/Darwin/initialization-bug-darwin.cc
===================================================================
--- test/asan/TestCases/Darwin/initialization-bug-darwin.cc
+++ test/asan/TestCases/Darwin/initialization-bug-darwin.cc
@@ -0,0 +1,43 @@
+// Darwin-specific variant of TestCases/initialization-bug.cc.
+// REQUIRES: osx-ld64-live_support
+
+// RUN: %clangxx_asan -mmacosx-version-min=10.11 -O0 %s %p/../Helpers/initialization-bug-extra2.cc -o %t-INIT-ORDER-EXE
+// RUN: %env_asan_opts=check_initialization_order=true not %run %t-INIT-ORDER-EXE 2>&1 | FileCheck %s
+
+#include <cstdio>
+
+// The structure of the test is:
+// "x", "y", "z" are dynamically initialized globals.
+// Value of "x" depends on "y", value of "y" depends on "z".
+// "x" and "z" are defined in this TU, "y" is defined in another one.
+// Thus we shoud stably report initialization order fiasco independently of
+// the translation unit order.
+
+int initZ() {
+ return 5;
+}
+int z = initZ();
+
+// 'y' is a dynamically initialized global residing in a different TU. This
+// dynamic initializer will read the value of 'y' before main starts. The
+// result is undefined behavior, which should be caught by initialization order
+// checking.
+extern int y;
+int __attribute__((noinline)) initX() {
+ return y + 1;
+ // CHECK: {{AddressSanitizer: initialization-order-fiasco}}
+ // CHECK: {{READ of size .* at 0x.* thread T0}}
+ // CHECK: {{0x.* is located 0 bytes inside of global variable .*(y|z).*}}
+ // CHECK: registered at:
+ // CHECK: 0x{{.*}} in __asan_register_globals
+}
+
+// This initializer begins our initialization order problems.
+static int x = initX();
+
+int main() {
+ // ASan should have caused an exit before main runs.
+ printf("PASS\n");
+ // CHECK-NOT: PASS
+ return 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26927.78758.patch
Type: text/x-patch
Size: 2388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161121/cb1c2f2d/attachment.bin>
More information about the llvm-commits
mailing list