[llvm] [hwasan] Allow stack traces even when fixed shadow is used (PR #109344)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 15:43:15 PDT 2024
https://github.com/thurstond created https://github.com/llvm/llvm-project/pull/109344
Previously, fixed shadow implied !InTls, and !InTls implied no stack traces, but InTls implied it would not use a fixed shadow. This patch changes fixed shadow to be compatible with stack traces.
It maintains the legacy behavior for KHWAsan || InstrumentWithCalls.
>From 934770dc4d978e57620ac539d473ca422b3a501a Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 19 Sep 2024 22:39:11 +0000
Subject: [PATCH] [hwasan] Allow stack traces even when fixed shadow is used
Previously, fixed shadow implied !InTls, and !InTls implied no stack traces, but InTls implied it would not use a fixed shadow.
This patch changes fixed shadow to be compatible with stack traces.
It maintains the legacy behavior for KHWAsan || InstrumentWithCalls.
---
.../Instrumentation/HWAddressSanitizer.cpp | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 7a5c690c7ea512..4bdf5b97aeb704 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1340,7 +1340,7 @@ Value *HWAddressSanitizer::getFrameRecordInfo(IRBuilder<> &IRB) {
}
void HWAddressSanitizer::emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord) {
- if (!Mapping.InTls)
+ if (!Mapping.InTls || (Mapping.Offset != 0 && Mapping.Offset != kDynamicShadowSentinel))
ShadowBase = getShadowNonTls(IRB);
else if (!WithFrameRecord && TargetTriple.isAndroid())
ShadowBase = getDynamicShadowIfunc(IRB);
@@ -1897,16 +1897,19 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
InTls = false;
Offset = 0;
WithFrameRecord = true;
- } else if (ClMappingOffset.getNumOccurrences() > 0) {
- InGlobal = false;
- InTls = false;
- Offset = ClMappingOffset;
- WithFrameRecord = false;
} else if (ClEnableKhwasan || InstrumentWithCalls) {
InGlobal = false;
InTls = false;
- Offset = 0;
+ if (ClMappingOffset.getNumOccurrences() > 0)
+ Offset = ClMappingOffset;
+ else
+ Offset = 0;
WithFrameRecord = false;
+ } else if (ClMappingOffset.getNumOccurrences() > 0) {
+ InGlobal = false;
+ InTls = true;
+ Offset = ClMappingOffset;
+ WithFrameRecord = true;
} else if (ClWithIfunc) {
InGlobal = true;
InTls = false;
More information about the llvm-commits
mailing list