[llvm] [ASan] Add metadata to renamed instructions so ASan doesn't use the i… (PR #119387)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 07:06:55 PST 2024
https://github.com/gbMattN created https://github.com/llvm/llvm-project/pull/119387
…ncorrect name
>From 01be0deaf6854ae1fd8f27ed9a3cb691be041d91 Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Tue, 10 Dec 2024 15:01:37 +0000
Subject: [PATCH] [ASan] Add metadata to renamed instructions so ASan doesn't
use the incorrect name
---
llvm/lib/IR/ValueSymbolTable.cpp | 6 ++++++
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 7 ++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/IR/ValueSymbolTable.cpp b/llvm/lib/IR/ValueSymbolTable.cpp
index a020acf22a96c5..8d1babfeca0e2f 100644
--- a/llvm/lib/IR/ValueSymbolTable.cpp
+++ b/llvm/lib/IR/ValueSymbolTable.cpp
@@ -123,6 +123,12 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
}
// Otherwise, there is a naming conflict. Rename this value.
+ // If we are renaming an instruction, ASan needs to know for it to serialize properly
+ if(auto* I = dyn_cast<Instruction>(V)){
+ MDString* trueNameMetadata = MDString::get(V->getContext(), Name);
+ llvm::MDTuple* tuple = llvm::MDTuple::get(V->getContext(), trueNameMetadata);
+ I->setMetadata("OriginalName", tuple);
+ }
SmallString<256> UniqueName(Name.begin(), Name.end());
return makeUniqueName(V, UniqueName);
}
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index cb84588318496c..d7e91097b3d37c 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -3430,7 +3430,12 @@ void FunctionStackPoisoner::processStaticAllocas() {
SmallVector<ASanStackVariableDescription, 16> SVD;
SVD.reserve(AllocaVec.size());
for (AllocaInst *AI : AllocaVec) {
- ASanStackVariableDescription D = {AI->getName().data(),
+ std::string Name = AI->getName().data();
+ if(AI->hasMetadata("OriginalName")){
+ MDTuple* tuple = dyn_cast<MDTuple>(AI->getMetadata("OriginalName"));
+ Name = dyn_cast<MDString>(tuple->getOperand(0))->getString();
+ }
+ ASanStackVariableDescription D = {Name.c_str(),
ASan.getAllocaSizeInBytes(*AI),
0,
AI->getAlign().value(),
More information about the llvm-commits
mailing list