Skip to content

Commit 0661533

Browse files
committed
[AMDGPU] Prepend --no-undefined option for linker instead of append
Previously, for linking in amdgpu contexts, the --no-undefined was appended to the options passed to lld, overriding any user-supplied options via "-Wl," or "-Xlinker". We now prepend --no-undefined so that the user options are respected. Differential Revision: https://reviews.llvm.org/D158582
1 parent 81792de commit 0661533

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
551551

552552
std::string Linker = getToolChain().GetProgramPath(getShortName());
553553
ArgStringList CmdArgs;
554+
CmdArgs.push_back("--no-undefined");
555+
CmdArgs.push_back("-shared");
556+
554557
addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
555558
Args.AddAllArgs(CmdArgs, options::OPT_L);
556559
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
@@ -560,8 +563,6 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
560563
else if (Args.hasArg(options::OPT_mcpu_EQ))
561564
CmdArgs.push_back(Args.MakeArgString(
562565
"-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
563-
CmdArgs.push_back("--no-undefined");
564-
CmdArgs.push_back("-shared");
565566
CmdArgs.push_back("-o");
566567
CmdArgs.push_back(Output.getFilename());
567568
C.addCommand(std::make_unique<Command>(

clang/test/Driver/amdgpu-toolchain-opencl.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@
2828

2929
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s
3030
// CHK-LINK: ld.lld{{.*}} "--no-undefined" "-shared"
31+
32+
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
33+
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Xlinker --unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
34+
// CHK-LINK_UR: ld.lld{{.*}} "--no-undefined"{{.*}} "--unresolved-symbols=ignore-all"

clang/test/Driver/amdgpu-toolchain.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
// DWARF_VER: "-dwarf-version=5"
1212

13+
// RUN: %clang -### --target=amdgcn--amdhsa -x assembler \
14+
// RUN: -Wl,--unresolved-symbols=ignore-all %s 2>&1 | FileCheck -check-prefix=AS_LINK_UR %s
15+
// RUN: %clang -### --target=amdgcn--amdhsa -x assembler \
16+
// RUN: -Xlinker --unresolved-symbols=ignore-all %s 2>&1 | FileCheck -check-prefix=AS_LINK_UR %s
17+
18+
// AS_LINK_UR: "-cc1as"
19+
// AS_LINK_UR: ld.lld{{.*}} "--no-undefined"{{.*}} "--unresolved-symbols=ignore-all"
20+
1321
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
1422
// RUN: -L. -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefixes=LTO,MCPU %s
1523
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \

0 commit comments

Comments
 (0)