Skip to content

[LinkerWrapper] Forward more arguments to the CPU offloading linker #75757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/test/Driver/linker-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out
// RUN: llvm-ar rcs %t.a %t.o
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
// RUN: --linker-path=/usr/bin/ld.lld -- %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
// RUN: --linker-path=/usr/bin/ld.lld -- --whole-archive %t.a --no-whole-archive \
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK

// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared
// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive

// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -openmp-opt-disable \
Expand Down
30 changes: 25 additions & 5 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,31 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
CmdArgs.push_back("-Wl,-Bsymbolic");
CmdArgs.push_back("-shared");
ArgStringList LinkerArgs;
for (const opt::Arg *Arg : Args.filtered(OPT_library, OPT_library_path))
Arg->render(Args, LinkerArgs);
for (const opt::Arg *Arg : Args.filtered(OPT_rpath))
LinkerArgs.push_back(
Args.MakeArgString("-Wl,-rpath," + StringRef(Arg->getValue())));
for (const opt::Arg *Arg :
Args.filtered(OPT_INPUT, OPT_library, OPT_library_path, OPT_rpath,
OPT_whole_archive, OPT_no_whole_archive)) {
// Sometimes needed libraries are passed by name, such as when using
// sanitizers. We need to check the file magic for any libraries.
if (Arg->getOption().matches(OPT_INPUT)) {
if (!sys::fs::exists(Arg->getValue()) ||
sys::fs::is_directory(Arg->getValue()))
continue;

file_magic Magic;
if (auto EC = identify_magic(Arg->getValue(), Magic))
return createStringError(inconvertibleErrorCode(),
"Failed to open %s", Arg->getValue());
if (Magic != file_magic::archive &&
Magic != file_magic::elf_shared_object)
continue;
}
if (Arg->getOption().matches(OPT_whole_archive))
LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
else if (Arg->getOption().matches(OPT_no_whole_archive))
LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
else
Arg->render(Args, LinkerArgs);
}
llvm::copy(LinkerArgs, std::back_inserter(CmdArgs));
}

Expand Down