diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -8462,6 +8462,12 @@ } Args.ClaimAllArgs(options::OPT_Xoffload_linker); + // Forward `-mllvm` arguments to the LLVM invocations if present. + for (auto *Arg : Args.filtered(options::OPT_mllvm)) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back(Arg->getValue()); + } + // Add the linker arguments to be forwarded by the wrapper. CmdArgs.push_back(Args.MakeArgString(Twine("--linker-path=") + LinkCommand->getExecutable())); diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c --- a/clang/test/Driver/linker-wrapper.c +++ b/clang/test/Driver/linker-wrapper.c @@ -39,10 +39,11 @@ // CPU_LINK: ld.lld{{.*}}-m elf_x86_64 -shared -Bsymbolic -o {{.*}}.out {{.*}}.o {{.*}}.o // 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 \ +// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -abc \ // RUN: --linker-path=/usr/bin/ld.lld -- -a -b -c %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=HOST_LINK // HOST_LINK: ld.lld{{.*}}-a -b -c {{.*}}.o -o a.out +// HOST_LINK-NOT: ld.lld{{.*}}-abc // RUN: clang-offload-packager -o %t.out \ // RUN: --image=file=%S/Inputs/dummy-bc.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ diff --git a/clang/test/Driver/openmp-offload.c b/clang/test/Driver/openmp-offload.c --- a/clang/test/Driver/openmp-offload.c +++ b/clang/test/Driver/openmp-offload.c @@ -664,7 +664,13 @@ // CHK-NEW-DRIVER: clang-linker-wrapper{{.*}}"--host-triple=powerpc64le-unknown-linux"{{.*}}--{{.*}}"-lomp"{{.*}}"-lomptarget" /// Check arguments to the linker wrapper -// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -g -fopenmp-new-driver %s 2>&1 \ +// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -g %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-NEW-DRIVER-DEBUG %s // CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}}"--device-debug + +/// Check arguments to the linker wrapper +// RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \ +// RUN: -mllvm -abc %s 2>&1 | FileCheck -check-prefix=CHK-NEW-DRIVER-MLLVM %s + +// CHK-NEW-DRIVER-MLLVM: clang-linker-wrapper{{.*}}"-abc diff --git a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td --- a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td +++ b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td @@ -70,6 +70,10 @@ def separator : Flag<["--"], "">, Flags<[WrapperOnlyOption]>, HelpText<"The separator for the wrapped linker arguments">; +// Arguments for the LLVM backend. +def mllvm : Separate<["--", "-"], "mllvm">, Flags<[WrapperOnlyOption]>, + MetaVarName<"">, HelpText<"Arguments passed to the LLVM invocation">; + // Standard linker flags also used by the linker wrapper. def sysroot_EQ : Joined<["--"], "sysroot">, HelpText<"Set the system root">;