-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[NFC] [HWASan] factor out debug record annotation #90252
Merged
fmayer
merged 1 commit into
main
from
users/fmayer/spr/nfc-hwasan-factor-out-debug-record-annotation
Apr 26, 2024
Merged
[NFC] [HWASan] factor out debug record annotation #90252
fmayer
merged 1 commit into
main
from
users/fmayer/spr/nfc-hwasan-factor-out-debug-record-annotation
Apr 26, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.4
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-compiler-rt-sanitizer Author: Florian Mayer (fmayer) ChangesThis will also be used by stack MTE Full diff: https://github.com/llvm/llvm-project/pull/90252.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
index fb3ab33a0629da..16589a605e609b 100644
--- a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
+++ b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
@@ -86,6 +86,8 @@ Value *getFP(IRBuilder<> &IRB);
Value *getPC(const Triple &TargetTriple, IRBuilder<> &IRB);
Value *getAndroidSlotPtr(IRBuilder<> &IRB, int Slot);
+void annotateDebugRecords(AllocaInfo &Info, unsigned int Tag);
+
} // namespace memtag
} // namespace llvm
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 88b85234034038..fa661b17c13a90 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1385,14 +1385,6 @@ bool HWAddressSanitizer::instrumentLandingPads(
return true;
}
-static DbgAssignIntrinsic *DynCastToDbgAssign(DbgVariableIntrinsic *DVI) {
- return dyn_cast<DbgAssignIntrinsic>(DVI);
-}
-
-static DbgVariableRecord *DynCastToDbgAssign(DbgVariableRecord *DVR) {
- return DVR->isDbgAssign() ? DVR : nullptr;
-}
-
bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
Value *StackTag, Value *UARTag,
const DominatorTree &DT,
@@ -1448,28 +1440,7 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
!memtag::isLifetimeIntrinsic(User);
});
- // Helper utility for adding DW_OP_LLVM_tag_offset to debug-info records,
- // abstracted over whether they're intrinsic-stored or DbgVariableRecord
- // stored.
- auto AnnotateDbgRecord = [&](auto *DPtr) {
- // Prepend "tag_offset, N" to the dwarf expression.
- // Tag offset logically applies to the alloca pointer, and it makes sense
- // to put it at the beginning of the expression.
- SmallVector<uint64_t, 8> NewOps = {dwarf::DW_OP_LLVM_tag_offset,
- retagMask(N)};
- for (size_t LocNo = 0; LocNo < DPtr->getNumVariableLocationOps(); ++LocNo)
- if (DPtr->getVariableLocationOp(LocNo) == AI)
- DPtr->setExpression(DIExpression::appendOpsToArg(
- DPtr->getExpression(), NewOps, LocNo));
- if (auto *DAI = DynCastToDbgAssign(DPtr)) {
- if (DAI->getAddress() == AI)
- DAI->setAddressExpression(DIExpression::prependOpcodes(
- DAI->getAddressExpression(), NewOps));
- }
- };
-
- llvm::for_each(Info.DbgVariableIntrinsics, AnnotateDbgRecord);
- llvm::for_each(Info.DbgVariableRecords, AnnotateDbgRecord);
+ memtag::annotateDebugRecords(Info, retagMask(N));
auto TagEnd = [&](Instruction *Node) {
IRB.SetInsertPoint(Node);
diff --git a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
index 7b1eb70168d894..0464ba5e181178 100644
--- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
@@ -17,6 +17,7 @@
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/StackSafetyAnalysis.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -283,5 +284,37 @@ Value *getAndroidSlotPtr(IRBuilder<> &IRB, int Slot) {
IRB.CreateCall(ThreadPointerFunc), 8 * Slot);
}
+static DbgAssignIntrinsic *DynCastToDbgAssign(DbgVariableIntrinsic *DVI) {
+ return dyn_cast<DbgAssignIntrinsic>(DVI);
+}
+
+static DbgVariableRecord *DynCastToDbgAssign(DbgVariableRecord *DVR) {
+ return DVR->isDbgAssign() ? DVR : nullptr;
+}
+
+void annotateDebugRecords(AllocaInfo &Info, unsigned int Tag) {
+ // Helper utility for adding DW_OP_LLVM_tag_offset to debug-info records,
+ // abstracted over whether they're intrinsic-stored or DbgVariableRecord
+ // stored.
+ auto AnnotateDbgRecord = [&](auto *DPtr) {
+ // Prepend "tag_offset, N" to the dwarf expression.
+ // Tag offset logically applies to the alloca pointer, and it makes sense
+ // to put it at the beginning of the expression.
+ SmallVector<uint64_t, 8> NewOps = {dwarf::DW_OP_LLVM_tag_offset, Tag};
+ for (size_t LocNo = 0; LocNo < DPtr->getNumVariableLocationOps(); ++LocNo)
+ if (DPtr->getVariableLocationOp(LocNo) == Info.AI)
+ DPtr->setExpression(
+ DIExpression::appendOpsToArg(DPtr->getExpression(), NewOps, LocNo));
+ if (auto *DAI = DynCastToDbgAssign(DPtr)) {
+ if (DAI->getAddress() == Info.AI)
+ DAI->setAddressExpression(
+ DIExpression::prependOpcodes(DAI->getAddressExpression(), NewOps));
+ }
+ };
+
+ llvm::for_each(Info.DbgVariableIntrinsics, AnnotateDbgRecord);
+ llvm::for_each(Info.DbgVariableRecords, AnnotateDbgRecord);
+}
+
} // namespace memtag
} // namespace llvm
|
vitalybuka
approved these changes
Apr 26, 2024
fmayer
deleted the
users/fmayer/spr/nfc-hwasan-factor-out-debug-record-annotation
branch
April 26, 2024 20:11
This was referenced Apr 29, 2024
Closed
fmayer
added a commit
to fmayer/llvm-project
that referenced
this pull request
Sep 13, 2024
This will also be used by stack MTE Pull Request: llvm#90252
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will also be used by stack MTE