Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hwasan] Allow stack traces even when fixed shadow is used #109344

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

thurstond
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 19, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Thurston Dang (thurstond)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/109344.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+10-7)
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;

Copy link

github-actions bot commented Sep 19, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 1335a11176f99cc54f423fe173708bd2373b59f7 ad9acd0085a9166bda420ed6aeba6dcadac899fb --extensions cpp -- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 4c4ad7ee9e..479961a72f 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1925,4 +1925,3 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
     WithFrameRecord = false;
   }
 }
-

Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

advance copy of nit, will think about the PR tomorrow

} else if (ClEnableKhwasan || InstrumentWithCalls) {
InGlobal = false;
InTls = false;
Offset = 0;
if (ClMappingOffset.getNumOccurrences() > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optOr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants