Skip to content

Commit 7485d36

Browse files
authored
[LinkerWrapper] Correctly handle multiple image wrappers (#67679)
Summary: We use these image wrappers to do runtime specifica registration of variables and to load the device image that was compiled. This was intended to support multiple of these running at the same time, e.g. you can have a CUDA instance running with OpenMP and they should both function so long as you do not share state between the two. However, because we did not use a unique name for this file it would cause conflicts when included. This patch names the image based off of the language runtime it's using so that they remain separate. Fixes: #67583
1 parent c43aa46 commit 7485d36

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

clang/test/Driver/linker-wrapper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
// CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52
8888
// CUDA: clang{{.*}} -o [[IMG_SM70:.+]] --target=nvptx64-nvidia-cuda -march=sm_70
8989
// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]]
90+
// CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o {{.*}}.cuda.image.{{.*}}.o
9091

9192
// RUN: clang-offload-packager -o %t.out \
9293
// RUN: --image=file=%t.elf.o,kind=cuda,triple=nvptx64-nvidia-cuda,arch=sm_80 \

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ Expected<StringRef> writeOffloadFile(const OffloadFile &File) {
810810

811811
// Compile the module to an object file using the appropriate target machine for
812812
// the host triple.
813-
Expected<StringRef> compileModule(Module &M) {
813+
Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
814814
llvm::TimeTraceScope TimeScope("Compile module");
815815
std::string Msg;
816816
const Target *T = TargetRegistry::lookupTarget(M.getTargetTriple(), Msg);
@@ -829,8 +829,10 @@ Expected<StringRef> compileModule(Module &M) {
829829
M.setDataLayout(TM->createDataLayout());
830830

831831
int FD = -1;
832-
auto TempFileOrErr = createOutputFile(
833-
sys::path::filename(ExecutableName) + ".image.wrapper", "o");
832+
auto TempFileOrErr =
833+
createOutputFile(sys::path::filename(ExecutableName) + "." +
834+
getOffloadKindName(Kind) + ".image.wrapper",
835+
"o");
834836
if (!TempFileOrErr)
835837
return TempFileOrErr.takeError();
836838
if (std::error_code EC = sys::fs::openFileForWrite(*TempFileOrErr, FD))
@@ -902,7 +904,7 @@ wrapDeviceImages(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
902904
WriteBitcodeToFile(M, OS);
903905
}
904906

905-
auto FileOrErr = compileModule(M);
907+
auto FileOrErr = compileModule(M, Kind);
906908
if (!FileOrErr)
907909
return FileOrErr.takeError();
908910
return *FileOrErr;

0 commit comments

Comments
 (0)