diff options
| author | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2021-07-19 17:15:38 -0400 |
|---|---|---|
| committer | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2021-07-23 10:35:52 -0400 |
| commit | 44dbbe61060acac4d0991a15decac4c909e26844 (patch) | |
| tree | aefb64725654f2d08a6a4622270bb7cd93dd3b7e /clang/lib/CodeGen/CodeGenModule.cpp | |
| parent | dd70cd089a73bec5a8ec411ae307d65516ad70bc (diff) | |
[HIP] Preserve ASAN bitcode library functions
Address sanitizer passes may generate call of ASAN bitcode library
functions after bitcode linking in lld, therefore lld cannot add
those symbols since it does not know they will be used later.
To solve this issue, clang emits a reference to a bicode library
function which calls all ASAN functions which need to be
preserved. This basically force all ASAN functions to be
linked in.
Reviewed by: Artem Belevich
Differential Revision: https://reviews.llvm.org/D106315
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index fc1d8d924349..9b40b88ea3c9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -523,6 +523,22 @@ void CodeGenModule::Release() { !Context.getTargetInfo().getTriple().isOSEmscripten()) { EmitMainVoidAlias(); } + + // Emit reference of __amdgpu_device_library_preserve_asan_functions to + // preserve ASAN functions in bitcode libraries. + if (LangOpts.Sanitize.has(SanitizerKind::Address) && getTriple().isAMDGPU()) { + auto *FT = llvm::FunctionType::get(VoidTy, {}); + auto *F = llvm::Function::Create( + FT, llvm::GlobalValue::ExternalLinkage, + "__amdgpu_device_library_preserve_asan_functions", &getModule()); + auto *Var = new llvm::GlobalVariable( + getModule(), FT->getPointerTo(), + /*isConstant=*/true, llvm::GlobalValue::WeakAnyLinkage, F, + "__amdgpu_device_library_preserve_asan_functions_ptr", nullptr, + llvm::GlobalVariable::NotThreadLocal); + addCompilerUsedGlobal(Var); + } + emitLLVMUsed(); if (SanStats) SanStats->finish(); |
