[llvm] [WIP][AMDGPU] Adjust asan instrumented GlobalVaribale size to not include redzone (PR #66666)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 18 09:16:00 PDT 2023
https://github.com/skc7 created https://github.com/llvm/llvm-project/pull/66666
None
>From 462b35ad5bcbf289d24afb38b168f72d30cf793b 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] [AMDGPU] Adjust asan instrumented GlobalVaribale size to not
include redzone
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 12 ++++++++++++
.../Transforms/Instrumentation/AddressSanitizer.cpp | 3 +++
2 files changed, 15 insertions(+)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 2ce08a2ff43955b..5d6dc3ea419fc02 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -758,6 +758,18 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
// sections and expected to be contiguous (e.g. ObjC metadata).
const Align Alignment = getGVAlignment(GV, DL);
+ if (TM.getTargetTriple().isAMDGPU() &&
+ 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..f9abdd293869054 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2401,6 +2401,9 @@ bool ModuleAddressSanitizer::InstrumentGlobals(IRBuilder<> &IRB, Module &M,
if (G->hasSanitizerMetadata())
MD = G->getSanitizerMetadata();
+ if (TargetTriple.isAMDGPU() && !G->hasSanitizerMetadata())
+ G->setSanitizerMetadata(MD);
+
// The runtime library tries demangling symbol names in the descriptor but
// functionality like __cxa_demangle may be unavailable (e.g.
// -static-libstdc++). So we demangle the symbol names here.
More information about the llvm-commits
mailing list