diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -89,6 +89,10 @@ /// ToolChain - Access to tools for a single platform. class ToolChain { +protected: + /// Return -DCLANG_DEFAULT_LINKER, if specified, else return + /// StandardDefaultLinker. + static const char *getConfiguredDefaultLinker(const char *StandardDefaultLinker); public: using path_list = SmallVector; @@ -420,7 +424,7 @@ } /// GetDefaultLinker - Get the default linker to use. - virtual const char *getDefaultLinker() const { return "ld"; } + virtual const char *getDefaultLinker() const; /// GetDefaultRuntimeLibType - Get the default runtime library variant to use. virtual RuntimeLibType GetDefaultRuntimeLibType() const { diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -541,6 +541,16 @@ return D.GetProgramPath(Name, *this); } +const char *ToolChain::getConfiguredDefaultLinker(const char *StandardLinker) { + if (CLANG_DEFAULT_LINKER[0] == '\0') + return StandardLinker; + return CLANG_DEFAULT_LINKER; +} + +const char *ToolChain::getDefaultLinker() const { + return getConfiguredDefaultLinker("ld"); +} + std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const { if (LinkerIsLLD) *LinkerIsLLD = false; @@ -548,7 +558,7 @@ // Get -fuse-ld= first to prevent -Wunused-command-line-argument. -fuse-ld= is // considered as the linker flavor, e.g. "bfd", "gold", or "lld". const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ); - StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER; + StringRef UseLinker = A ? A->getValue() : ""; // --ld-path= takes precedence over -fuse-ld= and specifies the executable // name. -B, COMPILER_PATH and PATH and consulted if the value does not diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h --- a/clang/lib/Driver/ToolChains/AMDGPU.h +++ b/clang/lib/Driver/ToolChains/AMDGPU.h @@ -97,7 +97,9 @@ } /// Needed for translating LTO options. - const char *getDefaultLinker() const override { return "ld.lld"; } + const char *getDefaultLinker() const override { + return getConfiguredDefaultLinker("ld.lld"); + } /// Should skip argument. bool shouldSkipArgument(const llvm::opt::Arg *Arg) const; diff --git a/clang/lib/Driver/ToolChains/BareMetal.h b/clang/lib/Driver/ToolChains/BareMetal.h --- a/clang/lib/Driver/ToolChains/BareMetal.h +++ b/clang/lib/Driver/ToolChains/BareMetal.h @@ -59,7 +59,9 @@ return ToolChain::CST_Libcxx; } - const char *getDefaultLinker() const override { return "ld.lld"; } + const char *getDefaultLinker() const override { + return getConfiguredDefaultLinker("ld.lld"); + } std::string getRuntimesDir() const; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, diff --git a/clang/lib/Driver/ToolChains/Fuchsia.h b/clang/lib/Driver/ToolChains/Fuchsia.h --- a/clang/lib/Driver/ToolChains/Fuchsia.h +++ b/clang/lib/Driver/ToolChains/Fuchsia.h @@ -91,7 +91,7 @@ llvm::opt::ArgStringList &CmdArgs) const override; const char *getDefaultLinker() const override { - return "ld.lld"; + return getConfiguredDefaultLinker("ld.lld"); } protected: diff --git a/clang/lib/Driver/ToolChains/Hexagon.h b/clang/lib/Driver/ToolChains/Hexagon.h --- a/clang/lib/Driver/ToolChains/Hexagon.h +++ b/clang/lib/Driver/ToolChains/Hexagon.h @@ -85,7 +85,8 @@ llvm::opt::ArgStringList &CC1Args) const override; const char *getDefaultLinker() const override { - return getTriple().isMusl() ? "ld.lld" : "hexagon-link"; + return getConfiguredDefaultLinker(getTriple().isMusl() ? "ld.lld" + : "hexagon-link"); } CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; diff --git a/clang/lib/Driver/ToolChains/MipsLinux.h b/clang/lib/Driver/ToolChains/MipsLinux.h --- a/clang/lib/Driver/ToolChains/MipsLinux.h +++ b/clang/lib/Driver/ToolChains/MipsLinux.h @@ -49,7 +49,7 @@ } const char *getDefaultLinker() const override { - return "ld.lld"; + return getConfiguredDefaultLinker("ld.lld"); } private: diff --git a/clang/lib/Driver/ToolChains/Solaris.h b/clang/lib/Driver/ToolChains/Solaris.h --- a/clang/lib/Driver/ToolChains/Solaris.h +++ b/clang/lib/Driver/ToolChains/Solaris.h @@ -67,7 +67,7 @@ const char *getDefaultLinker() const override { // clang currently uses Solaris ld-only options. - return "/usr/bin/ld"; + return getConfiguredDefaultLinker("/usr/bin/ld"); } protected: diff --git a/clang/lib/Driver/ToolChains/WebAssembly.h b/clang/lib/Driver/ToolChains/WebAssembly.h --- a/clang/lib/Driver/ToolChains/WebAssembly.h +++ b/clang/lib/Driver/ToolChains/WebAssembly.h @@ -67,7 +67,9 @@ llvm::opt::ArgStringList &CmdArgs) const override; SanitizerMask getSupportedSanitizers() const override; - const char *getDefaultLinker() const override { return "wasm-ld"; } + const char *getDefaultLinker() const override { + return getConfiguredDefaultLinker("wasm-ld"); + } Tool *buildLinker() const override; diff --git a/clang/test/Driver/ve-toolchain.c b/clang/test/Driver/ve-toolchain.c --- a/clang/test/Driver/ve-toolchain.c +++ b/clang/test/Driver/ve-toolchain.c @@ -61,10 +61,10 @@ /// Checking -fintegrated-as // RUN: %clang -### -target ve \ -// RUN: -x assembler -fuse-ld=ld %s 2>&1 | \ +// RUN: -x assembler %s 2>&1 | \ // RUN: FileCheck -check-prefix=AS %s // RUN: %clang -### -target ve \ -// RUN: -fno-integrated-as -fuse-ld=ld -x assembler %s 2>&1 | \ +// RUN: -fno-integrated-as -x assembler %s 2>&1 | \ // RUN: FileCheck -check-prefix=NAS %s // AS: clang{{.*}} "-cc1as" @@ -83,7 +83,6 @@ // RUN: %clang -### -target ve-unknown-linux-gnu \ // RUN: --sysroot %S/Inputs/basic_ve_tree \ // RUN: -resource-dir=%S/Inputs/basic_ve_tree/resource_dir \ -// RUN: -fuse-ld=ld \ // RUN: %s 2>&1 | FileCheck -check-prefix=DEF %s // DEF: clang{{.*}}" "-cc1" diff --git a/clang/test/Driver/ve-toolchain.cpp b/clang/test/Driver/ve-toolchain.cpp --- a/clang/test/Driver/ve-toolchain.cpp +++ b/clang/test/Driver/ve-toolchain.cpp @@ -110,10 +110,10 @@ /// Checking -fintegrated-as // RUN: %clangxx -### -target ve-unknown-linux-gnu \ -// RUN: -x assembler -fuse-ld=ld %s 2>&1 | \ +// RUN: -x assembler %s 2>&1 | \ // RUN: FileCheck -check-prefix=AS %s // RUN: %clangxx -### -target ve-unknown-linux-gnu \ -// RUN: -fno-integrated-as -x assembler -fuse-ld=ld %s 2>&1 | \ +// RUN: -fno-integrated-as -x assembler %s 2>&1 | \ // RUN: FileCheck -check-prefix=NAS %s // AS: clang{{.*}} "-cc1as" @@ -131,7 +131,6 @@ // RUN: %clangxx -### -target ve-unknown-linux-gnu \ // RUN: --sysroot %S/Inputs/basic_ve_tree \ -// RUN: -fuse-ld=ld \ // RUN: -resource-dir=%S/Inputs/basic_ve_tree/resource_dir \ // RUN: --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=DEF %s