[PATCH] D15108: [asan] Fix dynamic allocas unpoisoning on PowerPC{64}.
Maxim Ostapenko via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 1 06:17:20 PST 2015
m.ostepenko created this revision.
m.ostepenko added reviewers: kcc, samsonov.
m.ostepenko added subscribers: hfinkel, foad, ygribov, llvm-commits.
m.ostepenko set the repository for this revision to rL LLVM.
Hi!
As discussed in llvm-dev ML (https://groups.google.com/forum/m/#!topic/llvm-dev/42tNzaHISdk), for PowerPC{64} we cannot just pass SP extracted from @llvm.stackrestore to _asan_allocas_unpoison due to specific ABI requirements (http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#DYNAM-STACK). In particular, to get the pointer to the most recent dynamic alloca, we should add a compile-time-known offset to SP. This offset becomes to be known only on the frame index elimination stage, so we have introduced a special @llvm.get.dynamic.area.offset intrinsic (http://reviews.llvm.org/D14983) to reference it in LLVM. For most targets, this intrinsic is just lowered to zero in backend.
This patch just adds the value returned by @llvm.get.dynamic.area.offset to extracted from @llvm.stackrestore SP, so dynamic allocas unpoisoning stuff would work correctly on PowerPC{64}.
Tested on x86_64-unknown-linux-gnu. Jay, could you please check it on your PPC box?
Repository:
rL LLVM
http://reviews.llvm.org/D15108
Files:
lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/asan/TestCases/alloca_vla_interact.cc
Index: test/asan/TestCases/alloca_vla_interact.cc
===================================================================
--- test/asan/TestCases/alloca_vla_interact.cc
+++ test/asan/TestCases/alloca_vla_interact.cc
@@ -2,7 +2,6 @@
// RUN: %run %t 2>&1
//
// REQUIRES: stable-runtime
-// XFAIL: powerpc64
// This testcase checks correct interaction between VLAs and allocas.
Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -624,9 +624,24 @@
void unpoisonDynamicAllocasBeforeInst(Instruction *InstBefore,
Value *SavedStack) {
IRBuilder<> IRB(InstBefore);
+ Value *DynamicAreaPtr = IRB.CreatePtrToInt(SavedStack, IntptrTy);
+ // When we insert _asan_allocas_unpoison before @llvm.stackrestore, we
+ // need to adjust extracted SP to compute the address of the most recent
+ // alloca. We have a special @llvm.get.dynamic.area.offset intrinsic for
+ // this purpose.
+ if (!isa<ReturnInst>(InstBefore)) {
+ Function *DynamicAreaOffsetFunc = Intrinsic::getDeclaration(
+ InstBefore->getModule(), Intrinsic::get_dynamic_area_offset,
+ {IntptrTy});
+
+ Value *DynamicAreaOffset = IRB.CreateCall(DynamicAreaOffsetFunc, {});
+
+ DynamicAreaPtr = IRB.CreateAdd(IRB.CreatePtrToInt(SavedStack, IntptrTy),
+ DynamicAreaOffset);
+ }
+
IRB.CreateCall(AsanAllocasUnpoisonFunc,
- {IRB.CreateLoad(DynamicAllocaLayout),
- IRB.CreatePtrToInt(SavedStack, IntptrTy)});
+ {IRB.CreateLoad(DynamicAllocaLayout), DynamicAreaPtr});
}
// Unpoison dynamic allocas redzones.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15108.41497.patch
Type: text/x-patch
Size: 1851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151201/a1a1239c/attachment.bin>
More information about the llvm-commits
mailing list