diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -222,6 +222,14 @@ Target Specific Changes ----------------------- +AMDGPU Support +^^^^^^^^^^^^^^ + +- Linking for AMDGPU now uses ``--no-undefined`` by default. This causes + undefined symbols in the created module to be a linker error. To prevent this, + pass ``-Wl,--undefined`` if compiling directly, or ``-Xoffload-linker + --undefined`` if using an offloading language. + X86 Support ^^^^^^^^^^^ diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -543,6 +543,7 @@ if (C.getDriver().isUsingLTO()) addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0], C.getDriver().getLTOMode() == LTOK_Thin); + CmdArgs.push_back("--no-undefined"); CmdArgs.push_back("-shared"); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); diff --git a/clang/test/Driver/amdgpu-toolchain-opencl.cl b/clang/test/Driver/amdgpu-toolchain-opencl.cl --- a/clang/test/Driver/amdgpu-toolchain-opencl.cl +++ b/clang/test/Driver/amdgpu-toolchain-opencl.cl @@ -25,3 +25,6 @@ // CHK-INC: "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cl" // CHK-INC-NOT: "-cc1" {{.*}}"-finclude-default-header" "-fdeclare-opencl-builtins" {{.*}}"-x" "cpp-output" + +// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -emit-llvm -mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s +// CHK-LINK: ld.lld{{.*}} "--no-undefined" "-shared" diff --git a/clang/test/Driver/amdgpu-toolchain.c b/clang/test/Driver/amdgpu-toolchain.c --- a/clang/test/Driver/amdgpu-toolchain.c +++ b/clang/test/Driver/amdgpu-toolchain.c @@ -6,7 +6,7 @@ // RUN: %clang -### -g --target=amdgcn-mesa-mesa3d -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s // AS_LINK: "-cc1as" -// AS_LINK: ld.lld{{.*}} "-shared" +// AS_LINK: ld.lld{{.*}} "--no-undefined" "-shared" // DWARF_VER: "-dwarf-version=5"