[compiler-rt] d458f37 - [GWP-ASan] Change unreachable -> trap to work around DCE bug.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 8 13:07:09 PDT 2021


Author: Mitch Phillips
Date: 2021-07-08T13:06:42-07:00
New Revision: d458f379324967c3c408be06e21aad9bc92c54cb

URL: https://github.com/llvm/llvm-project/commit/d458f379324967c3c408be06e21aad9bc92c54cb
DIFF: https://github.com/llvm/llvm-project/commit/d458f379324967c3c408be06e21aad9bc92c54cb.diff

LOG: [GWP-ASan] Change unreachable -> trap to work around DCE bug.

trapOnAddress is designed to SEGV on a specific address. Unfortunately,
with an IR change, __builtin_unreachable() ends up doing DCE on things
that have side effects, like the load that causes the trap.

Change to __builtin_trap() to avoid the optimisation.

Root cause is still an LLVM bug, and tracked in
https://bugs.llvm.org/show_bug.cgi?id=47480.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D105654

Added: 
    

Modified: 
    compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
index d7849274b16b0..8ce5fc9c4dfcc 100644
--- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
+++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
@@ -258,7 +258,10 @@ void GuardedPoolAllocator::trapOnAddress(uintptr_t Address, Error E) {
   // Raise a SEGV by touching first guard page.
   volatile char *p = reinterpret_cast<char *>(State.GuardedPagePool);
   *p = 0;
-  __builtin_unreachable();
+  // Normally, would be __builtin_unreachable(), but because of
+  // https://bugs.llvm.org/show_bug.cgi?id=47480, unreachable will DCE the
+  // volatile store above, even though it has side effects.
+  __builtin_trap();
 }
 
 void GuardedPoolAllocator::stop() {


        


More information about the llvm-commits mailing list