From 361455eb370933273285906708ff895615774e55 Mon Sep 17 00:00:00 2001 From: Evgenii Stepanov Date: Thu, 13 Oct 2022 16:23:08 -0700 Subject: [PATCH] Harden CrasherTest::Trap under sanitizers. The use of __builtin_abort in CrasherTest::Trap breaks with -ftrap-function=abort, because then the argument of Trap is no longer in the first argument register at the time of crash. This flag is added when *any* sanitizer is enabled on the target, even harmless ones like memtag-heap. See sanitize.go:769. Fix CrasherTest::Trap to be a little more reliable. Test: debuggerd_test with SANITIZE_TARGET=memtag_heap Change-Id: I150f1c0355bd6f2bfabfa5a7bba125acdde1120e --- debuggerd/debuggerd_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index aca476f68..c08721b46 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -406,10 +406,10 @@ TEST_F(CrasherTest, tagged_fault_addr) { result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0x[01]00000000000dead)"); } -// Marked as weak to prevent the compiler from removing the malloc in the caller. In theory, the -// compiler could still clobber the argument register before trapping, but that's unlikely. -__attribute__((weak)) void CrasherTest::Trap(void* ptr ATTRIBUTE_UNUSED) { - __builtin_trap(); +void CrasherTest::Trap(void* ptr) { + void (*volatile f)(void*) = nullptr; + __asm__ __volatile__("" : : "r"(f) : "memory"); + f(ptr); } TEST_F(CrasherTest, heap_addr_in_register) { @@ -828,7 +828,7 @@ TEST_F(CrasherTest, mte_register_tag_dump) { StartIntercept(&output_fd); FinishCrasher(); - AssertDeath(SIGTRAP); + AssertDeath(SIGSEGV); FinishIntercept(&intercept_result); ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";