瀏覽代碼

[HIP] Make __hip_gpubin_handle hidden to avoid being merged across different shared libraries

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
Yaxun Liu 7 年之前
父節點
當前提交
c912e867c0
共有 2 個文件被更改,包括 3 次插入1 次删除
  1. 2 0
      lib/CodeGen/CGCUDANV.cpp
  2. 1 1
      test/CodeGenCUDA/device-stub.cu

+ 2 - 0
lib/CodeGen/CGCUDANV.cpp

@@ -459,6 +459,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
         /*Initializer=*/llvm::ConstantPointerNull::get(VoidPtrPtrTy),
         /*Initializer=*/llvm::ConstantPointerNull::get(VoidPtrPtrTy),
         "__hip_gpubin_handle");
         "__hip_gpubin_handle");
     GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getQuantity());
     GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getQuantity());
+    // Prevent the weak symbol in different shared libraries being merged.
+    GpuBinaryHandle->setVisibility(llvm::GlobalValue::HiddenVisibility);
     Address GpuBinaryAddr(
     Address GpuBinaryAddr(
         GpuBinaryHandle,
         GpuBinaryHandle,
         CharUnits::fromQuantity(GpuBinaryHandle->getAlignment()));
         CharUnits::fromQuantity(GpuBinaryHandle->getAlignment()));

+ 1 - 1
test/CodeGenCUDA/device-stub.cu

@@ -80,7 +80,7 @@ void use_pointers() {
 // HIP-SAME: section ".hipFatBinSegment"
 // HIP-SAME: section ".hipFatBinSegment"
 // * variable to save GPU binary handle after initialization
 // * variable to save GPU binary handle after initialization
 // CUDANORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
 // 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
 // * constant unnamed string with NVModuleID
 // RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32