From 373cb301ad226ab33fdd65212ca0c5c78542f504 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 24 May 2019 13:45:36 -0700 Subject: [PATCH] memunreachable_test: don't use `write` to escape addresses A recent change (https://android-review.googlesource.com/c/platform/bionic/+/961601) caused this test to fail. This change allowed LLVM to optimize what was previously `__write_chk` into a standard call to `write`. LLVM knows things about `write`. In particular, it knows that `write` doesn't capture its buffer param, which `Ref` assumes isn't possible. LLVM can't reason much about `volatile` operations; storing this to a `volatile` ptr should be good enough. If not, there are a few other tricks we can play here. Bug: 133479661 Test: `atest memunreachable_test:memunreachable_test.MemunreachableTest#stack -- --abi x86` on internal-master Change-Id: I905e510210cafdf83fa1b50f2f090d4f8b9653da --- libmemunreachable/tests/MemUnreachable_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libmemunreachable/tests/MemUnreachable_test.cpp b/libmemunreachable/tests/MemUnreachable_test.cpp index bba0c6d11..024b6bc21 100644 --- a/libmemunreachable/tests/MemUnreachable_test.cpp +++ b/libmemunreachable/tests/MemUnreachable_test.cpp @@ -47,7 +47,8 @@ class HiddenPointer { // Trick the compiler into thinking a value on the stack is still referenced. static void Ref(void** ptr) { - write(0, ptr, 0); + void** volatile storage; + storage = ptr; } class MemunreachableTest : public ::testing::Test {