Skip to content

Commit b0fc517

Browse files
committed
Fix issue about mutiple source files
HIP now uses llvm_offload_entries as section name.
1 parent 1179477 commit b0fc517

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

clang/test/Driver/linker-wrapper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ __attribute__((visibility("protected"), used)) int x;
223223
// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx90a -input={{/dev/null|NUL}} -input={{.*}} -output={{.*}}
224224
// RELOCATABLE-LINK-HIP: /usr/bin/ld.lld{{.*}}-r
225225
// RELOCATABLE-LINK-HIP: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading
226+
// RELOCATABLE-LINK-HIP: --rename-section llvm_offload_entries
226227

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

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,21 @@ Error relocateOffloadSection(const ArgList &Args, StringRef Output) {
310310
// Remove the old .llvm.offloading section to prevent further linking.
311311
ObjcopyArgs.emplace_back("--remove-section");
312312
ObjcopyArgs.emplace_back(".llvm.offloading");
313-
for (StringRef Prefix : {"omp", "cuda", "hip"}) {
314-
auto Section = (Prefix + "_offloading_entries").str();
315-
// Rename the offloading entires to make them private to this link unit.
316-
ObjcopyArgs.emplace_back("--rename-section");
317-
ObjcopyArgs.emplace_back(
318-
Args.MakeArgString(Section + "=" + Section + Suffix));
319-
320-
// Rename the __start_ / __stop_ symbols appropriately to iterate over the
321-
// newly renamed section containing the offloading entries.
322-
ObjcopyArgs.emplace_back("--redefine-sym");
323-
ObjcopyArgs.emplace_back(Args.MakeArgString("__start_" + Section + "=" +
324-
"__start_" + Section + Suffix));
325-
ObjcopyArgs.emplace_back("--redefine-sym");
326-
ObjcopyArgs.emplace_back(Args.MakeArgString("__stop_" + Section + "=" +
327-
"__stop_" + Section + Suffix));
328-
}
313+
StringRef Prefix = "llvm";
314+
auto Section = (Prefix + "llvm_offload_entries").str();
315+
// Rename the offloading entires to make them private to this link unit.
316+
ObjcopyArgs.emplace_back("--rename-section");
317+
ObjcopyArgs.emplace_back(
318+
Args.MakeArgString(Section + "=" + Section + Suffix));
319+
320+
// Rename the __start_ / __stop_ symbols appropriately to iterate over the
321+
// newly renamed section containing the offloading entries.
322+
ObjcopyArgs.emplace_back("--redefine-sym");
323+
ObjcopyArgs.emplace_back(Args.MakeArgString("__start_" + Section + "=" +
324+
"__start_" + Section + Suffix));
325+
ObjcopyArgs.emplace_back("--redefine-sym");
326+
ObjcopyArgs.emplace_back(Args.MakeArgString("__stop_" + Section + "=" +
327+
"__stop_" + Section + Suffix));
329328

330329
if (Error Err = executeCommands(*ObjcopyPath, ObjcopyArgs))
331330
return Err;

0 commit comments

Comments
 (0)