]> granicus.if.org Git - clang/commitdiff
[HIP] Make __hip_gpubin_handle hidden to avoid being merged across different shared...
authorYaxun Liu <Yaxun.Liu@amd.com>
Fri, 17 Aug 2018 17:47:31 +0000 (17:47 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Fri, 17 Aug 2018 17:47:31 +0000 (17:47 +0000)
Different shared libraries contain different fat binary, which is stored in a global variable
__hip_gpubin_handle. Since different compilation units share the same fat binary, this
variable has linkonce linkage. However, it should not be merged across different shared
libraries.

This patch set the visibility of the global variable to be hidden, which will make it invisible
in the shared library, therefore preventing it from being merged.

Differential Revision: https://reviews.llvm.org/D50596

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340056 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCUDANV.cpp
test/CodeGenCUDA/device-stub.cu

index 5fcc9e011bcbee71c961e9138d98b210402e9fbe..3f3f2c5e43c409ce51a22f9a16ea1403f7c99ea9 100644 (file)
@@ -459,6 +459,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
         /*Initializer=*/llvm::ConstantPointerNull::get(VoidPtrPtrTy),
         "__hip_gpubin_handle");
     GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getQuantity());
+    // Prevent the weak symbol in different shared libraries being merged.
+    GpuBinaryHandle->setVisibility(llvm::GlobalValue::HiddenVisibility);
     Address GpuBinaryAddr(
         GpuBinaryHandle,
         CharUnits::fromQuantity(GpuBinaryHandle->getAlignment()));
index 716381b7a82649cf9894ba1027fb591c6c857d82..06877da8588f406c54030f66d763027813ba04e7 100644 (file)
@@ -80,7 +80,7 @@ void use_pointers() {
 // HIP-SAME: section ".hipFatBinSegment"
 // * variable to save GPU binary handle after initialization
 // CUDANORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
-// HIP: @__[[PREFIX]]_gpubin_handle = linkonce global i8** null
+// HIP: @__[[PREFIX]]_gpubin_handle = linkonce hidden global i8** null
 // * constant unnamed string with NVModuleID
 // RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32