[PATCH] D110468: [AMDGPU] Do not internalize ASan functions.

Mahesha S via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 24 22:00:23 PDT 2021


hsmhsm created this revision.
hsmhsm added reviewers: arsenm, rampitec, t-tye, b-sumner, pvellien, yaxunl.
Herald added subscribers: foad, kerbowa, hiraditya, tpr, dstuttard, nhaehnle, jvesely, kzhuravl.
hsmhsm requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

ASan device library functions (those starts with the prefix __asan_)
are at the moment undergoing through undesired optimizations due to
internalization. Hence, in order avoid such undesired optimizations
on ASan device library functions, do not internalize them in the first
place.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110468

Files:
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/test/CodeGen/AMDGPU/internalize.ll


Index: llvm/test/CodeGen/AMDGPU/internalize.ll
===================================================================
--- llvm/test/CodeGen/AMDGPU/internalize.ll
+++ llvm/test/CodeGen/AMDGPU/internalize.ll
@@ -1,7 +1,7 @@
 ; RUN: opt -O0 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPTNONE %s
 ; RUN: opt -passes='default<O0>' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPTNONE %s
-; RUN: opt -O1 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT %s
-; RUN: opt -passes='default<O1>' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT %s
+; RUN: opt -O1 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT -check-prefix=ASAN_NO_INTERNALIZE %s
+; RUN: opt -passes='default<O1>' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT -check-prefix=ASAN_NO_INTERNALIZE %s
 
 ; OPT-NOT: gvar_unused
 ; OPTNONE: gvar_unused
@@ -10,6 +10,20 @@
 ; ALL: gvar_used
 @gvar_used = addrspace(1) global i32 undef, align 4
 
+; OPTNONE: define void @__asan_no_explicit_linkage(
+; ASAN_NO_INTERNALIZE: define void @__asan_no_explicit_linkage(
+define void @__asan_no_explicit_linkage() {
+entry:
+  ret void
+}
+
+; OPTNONE: define weak void @__asan_weak_linkage(
+; ASAN_NO_INTERNALIZE: define weak void @__asan_weak_linkage(
+define weak void @__asan_weak_linkage() {
+entry:
+  ret void
+}
+
 ; OPT: define internal fastcc void @func_used_noinline(
 ; OPT-NONE: define fastcc void @func_used_noinline(
 define fastcc void @func_used_noinline(i32 addrspace(1)* %out, i32 %tid) #1 {
Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -517,7 +517,8 @@
 /// Predicate for Internalize pass.
 static bool mustPreserveGV(const GlobalValue &GV) {
   if (const Function *F = dyn_cast<Function>(&GV))
-    return F->isDeclaration() || AMDGPU::isEntryFunctionCC(F->getCallingConv());
+    return F->isDeclaration() || F->getName().startswith("__asan_") ||
+           AMDGPU::isEntryFunctionCC(F->getCallingConv());
 
   GV.removeDeadConstantUsers();
   return !GV.use_empty();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110468.375013.patch
Type: text/x-patch
Size: 2516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210925/39be750c/attachment.bin>


More information about the llvm-commits mailing list