[PATCH] D111710: [AMDGPU][ASAN][OPENMP] Size Mismatch issue occurs when a global entry used in the target region is instrumented with ASAN specifically on AMDGPU occurs at Libomptarget level. There are trailing red zone for global variables mapped on the target...

Amit Kumar Pandey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 13 05:39:24 PDT 2021


ampandey-AMD created this revision.
ampandey-AMD added a reviewer: gregrodgers.
Herald added subscribers: guansong, hiraditya, t-tye, tpr, dstuttard, yaxunl, kzhuravl.
ampandey-AMD requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1, wdng.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.

...region when instrumentation is enabled for AMDGPU. This global variable has entry as a struct global of type __tgt_offload_entry as an instance of struct omp_offloading_entry which stores the size info in bytes for mapped globals on the target device. This patch aims to fix the trailing redzones added for mapped globals so the the host code has correct information of global with trailing redzones.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111710

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2422,6 +2422,27 @@
   for (auto &G : M.globals()) {
     if (!AliasedGlobalExclusions.count(&G) && shouldInstrumentGlobal(&G))
       GlobalsToChange.push_back(&G);
+		StringRef off_ent_str = G.getSection();
+		const StringRef sectionName = "omp_offloading_entries";
+		if(off_ent_str.compare(sectionName) == 0 && (G.getOperand(0)->getType()->isStructTy())) {
+		StringRef GName = G.getOperand(0)->getType()->getStructName();
+		const APInt &UI = G.getInitializer()->getAggregateElement(unsigned(2))->getUniqueInteger();
+		const uint64_t SizeInBytes = UI.getSExtValue();
+		if(SizeInBytes != 0) {
+		const uint64_t RightRedzoneSize = getRedzoneSizeForGlobal(SizeInBytes);
+		Constant *val = ConstantInt::get(IRB.getInt64Ty(),SizeInBytes+RightRedzoneSize,true);
+		StructType *sttype = StructType::getTypeByName(M.getContext(),GName);
+		SmallVector<Constant*,5> indices(5);
+		indices[0] = G.getInitializer()->getAggregateElement(unsigned(0));
+		indices[1] = G.getInitializer()->getAggregateElement(unsigned(1));
+		indices[2] = val;
+		indices[3] = G.getInitializer()->getAggregateElement(unsigned(3));
+		indices[4] = G.getInitializer()->getAggregateElement(unsigned(4));
+		Constant *NewInit = ConstantStruct::get(sttype,indices);
+		NewInit->takeName(G.getInitializer());
+		G.setInitializer(NewInit);
+		}
+	}
   }
 
   size_t n = GlobalsToChange.size();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111710.379355.patch
Type: text/x-patch
Size: 1620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211013/6b98f6f4/attachment.bin>


More information about the llvm-commits mailing list