[llvm] [WIP][AMDGPU] Adjust asan instrumented GlobalVariable size to not include redzone (PR #66666)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 03:58:58 PDT 2023
https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/66666
>From 9f01af0bb47fd0adaaba7ebf81af1cee30c0de40 Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Mon, 18 Sep 2023 21:42:19 +0530
Subject: [PATCH] [ASAN] Adjust asan instrumented GlobalVariable size to not
include redzone.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 11 +++++++++++
.../Transforms/Instrumentation/AddressSanitizer.cpp | 5 +++++
2 files changed, 16 insertions(+)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 2ce08a2ff43955b..dee1459351a7ea9 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -758,6 +758,17 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
// sections and expected to be contiguous (e.g. ObjC metadata).
const Align Alignment = getGVAlignment(GV, DL);
+ if (GV->hasSanitizerMetadata() &&
+ !GV->getSanitizerMetadata().NoAddress) {
+ StructType* ST = dyn_cast<StructType>(GV->getValueType());
+ if (ST && ST->getNumElements() == 2) {
+ auto *ET0 = ST->getElementType(0);
+ if (ET0 && isa<ArrayType>(ST->getElementType(1))) {
+ Size = DL.getTypeAllocSize(ET0);
+ }
+ }
+ }
+
for (const HandlerInfo &HI : Handlers) {
NamedRegionTimer T(HI.TimerName, HI.TimerDescription,
HI.TimerGroupName, HI.TimerGroupDescription,
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index bde5fba20f3b7a6..4aa8a3eeea9a9ef 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2445,6 +2445,11 @@ bool ModuleAddressSanitizer::InstrumentGlobals(IRBuilder<> &IRB, Module &M,
// zero so we can copy the metadata over as is.
NewGlobal->copyMetadata(G, 0);
+ // Set sanitizer metadata for newly created global,
+ // if it doesn't have it.
+ if (!NewGlobal->hasSanitizerMetadata())
+ NewGlobal->setSanitizerMetadata(MD);
+
Value *Indices2[2];
Indices2[0] = IRB.getInt32(0);
Indices2[1] = IRB.getInt32(0);
More information about the llvm-commits
mailing list