Skip to content

Commit 5c14376

Browse files
jsjisys-ce-bb
authored andcommitted
Revert "[HIP] Allow partial linking for -fgpu-rdc (#81700)"
This reverts commit 33a6ce1. There is bug in the implementation, John Lu suggested to revert it first.
1 parent cbe3792 commit 5c14376

File tree

11 files changed

+50
-469
lines changed

11 files changed

+50
-469
lines changed

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
762762
// to contain the fat binary but will be populated somewhere else,
763763
// e.g. by lld through link script.
764764
FatBinStr = new llvm::GlobalVariable(
765-
CGM.getModule(), CGM.Int8Ty,
766-
/*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
767-
"__hip_fatbin_" + CGM.getContext().getCUIDHash(), nullptr,
768-
llvm::GlobalVariable::NotThreadLocal);
765+
CGM.getModule(), CGM.Int8Ty,
766+
/*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
767+
"__hip_fatbin", nullptr,
768+
llvm::GlobalVariable::NotThreadLocal);
769769
cast<llvm::GlobalVariable>(FatBinStr)->setSection(FatbinConstantName);
770770
}
771771

@@ -818,8 +818,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
818818
// thread safety of the loaded program. Therefore we can assume sequential
819819
// execution of constructor functions here.
820820
if (IsHIP) {
821-
auto Linkage = CudaGpuBinary ? llvm::GlobalValue::InternalLinkage
822-
: llvm::GlobalValue::ExternalLinkage;
821+
auto Linkage = CudaGpuBinary ? llvm::GlobalValue::InternalLinkage :
822+
llvm::GlobalValue::LinkOnceAnyLinkage;
823823
llvm::BasicBlock *IfBlock =
824824
llvm::BasicBlock::Create(Context, "if", ModuleCtorFunc);
825825
llvm::BasicBlock *ExitBlock =
@@ -828,11 +828,11 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
828828
// of HIP ABI.
829829
GpuBinaryHandle = new llvm::GlobalVariable(
830830
TheModule, PtrTy, /*isConstant=*/false, Linkage,
831-
/*Initializer=*/
832-
CudaGpuBinary ? llvm::ConstantPointerNull::get(PtrTy) : nullptr,
833-
CudaGpuBinary
834-
? "__hip_gpubin_handle"
835-
: "__hip_gpubin_handle_" + CGM.getContext().getCUIDHash());
831+
/*Initializer=*/llvm::ConstantPointerNull::get(PtrTy),
832+
"__hip_gpubin_handle");
833+
if (Linkage == llvm::GlobalValue::LinkOnceAnyLinkage)
834+
GpuBinaryHandle->setComdat(
835+
CGM.getModule().getOrInsertComdat(GpuBinaryHandle->getName()));
836836
GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
837837
// Prevent the weak symbol in different shared libraries being merged.
838838
if (Linkage != llvm::GlobalValue::InternalLinkage)

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -959,15 +959,7 @@ void CodeGenModule::Release() {
959959
llvm::ConstantArray::get(ATy, UsedArray), "__clang_gpu_used_external");
960960
addCompilerUsedGlobal(GV);
961961
}
962-
if (LangOpts.HIP) {
963-
// Emit a unique ID so that host and device binaries from the same
964-
// compilation unit can be associated.
965-
auto *GV = new llvm::GlobalVariable(
966-
getModule(), Int8Ty, false, llvm::GlobalValue::ExternalLinkage,
967-
llvm::Constant::getNullValue(Int8Ty),
968-
"__hip_cuid_" + getContext().getCUIDHash());
969-
addCompilerUsedGlobal(GV);
970-
}
962+
971963
emitLLVMUsed();
972964
if (SanStats)
973965
SanStats->finish();

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -733,15 +733,8 @@ class ObjectFileHandler final : public FileHandler {
733733
StringRef Content = *ContentOrErr;
734734

735735
// Copy fat object contents to the output when extracting host bundle.
736-
std::string ModifiedContent;
737-
if (Content.size() == 1u && Content.front() == 0) {
738-
auto HostBundleOrErr = getHostBundle();
739-
if (!HostBundleOrErr)
740-
return HostBundleOrErr.takeError();
741-
742-
ModifiedContent = std::move(*HostBundleOrErr);
743-
Content = ModifiedContent;
744-
}
736+
if (Content.size() == 1u && Content.front() == 0)
737+
Content = StringRef(Input.getBufferStart(), Input.getBufferSize());
745738

746739
OS.write(Content.data(), Content.size());
747740
return Error::success();
@@ -863,35 +856,6 @@ class ObjectFileHandler final : public FileHandler {
863856
}
864857
return Error::success();
865858
}
866-
867-
Expected<std::string> getHostBundle() {
868-
TempFileHandlerRAII TempFiles;
869-
870-
auto ModifiedObjPathOrErr = TempFiles.Create(std::nullopt);
871-
if (!ModifiedObjPathOrErr)
872-
return ModifiedObjPathOrErr.takeError();
873-
StringRef ModifiedObjPath = *ModifiedObjPathOrErr;
874-
875-
BumpPtrAllocator Alloc;
876-
StringSaver SS{Alloc};
877-
SmallVector<StringRef, 16> ObjcopyArgs{"llvm-objcopy"};
878-
879-
ObjcopyArgs.push_back("--regex");
880-
ObjcopyArgs.push_back("--remove-section=__CLANG_OFFLOAD_BUNDLE__.*");
881-
ObjcopyArgs.push_back("--");
882-
ObjcopyArgs.push_back(BundlerConfig.InputFileNames.front());
883-
ObjcopyArgs.push_back(ModifiedObjPath);
884-
885-
if (Error Err = executeObjcopy(BundlerConfig.ObjcopyPath, ObjcopyArgs))
886-
return std::move(Err);
887-
888-
auto BufOrErr = MemoryBuffer::getFile(ModifiedObjPath);
889-
if (!BufOrErr)
890-
return createStringError(BufOrErr.getError(),
891-
"Failed to read back the modified object file");
892-
893-
return BufOrErr->get()->getBuffer().str();
894-
}
895859
};
896860

897861
/// Handler for text files. The bundled file will have the following format.

0 commit comments

Comments
 (0)