simoll created this revision. simoll added reviewers: kaz7, MaskRay, phosek. simoll requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Before, the CLANG_DEFAULT_LINKER cmake option was a global override for the linker that shall be used on all toolchains. The linker binary specified that way may not be available on toolchains with custom linkers. Eg, the only linker for VE is named 'nld' - any other linker invalidates the toolchain. This patch removes the hard override and instead lets the generic toolchain implementation default to CLANG_DEFAULT_LINKER. Toolchains can now deviate with a custom linker name or deliberatly default to CLANG_DEFAULT_LINKER. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D115045 Files: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp clang/test/Driver/ve-toolchain.c clang/test/Driver/ve-toolchain.cpp Index: clang/test/Driver/ve-toolchain.cpp =================================================================== --- clang/test/Driver/ve-toolchain.cpp +++ clang/test/Driver/ve-toolchain.cpp @@ -92,10 +92,10 @@ /// Checking -fintegrated-as // RUN: %clangxx -### -target ve \ -// 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 \ -// 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" @@ -113,7 +113,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 Index: clang/test/Driver/ve-toolchain.c =================================================================== --- clang/test/Driver/ve-toolchain.c +++ 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" Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -541,6 +541,12 @@ return D.GetProgramPath(Name, *this); } +const char *ToolChain::getDefaultLinker() const { + if (StringRef(CLANG_DEFAULT_LINKER).empty()) + return "ld"; + return CLANG_DEFAULT_LINKER; +} + std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const { if (LinkerIsLLD) *LinkerIsLLD = false; @@ -548,7 +554,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 Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -420,7 +420,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 {
Index: clang/test/Driver/ve-toolchain.cpp =================================================================== --- clang/test/Driver/ve-toolchain.cpp +++ clang/test/Driver/ve-toolchain.cpp @@ -92,10 +92,10 @@ /// Checking -fintegrated-as // RUN: %clangxx -### -target ve \ -// 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 \ -// 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" @@ -113,7 +113,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 Index: clang/test/Driver/ve-toolchain.c =================================================================== --- clang/test/Driver/ve-toolchain.c +++ 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" Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -541,6 +541,12 @@ return D.GetProgramPath(Name, *this); } +const char *ToolChain::getDefaultLinker() const { + if (StringRef(CLANG_DEFAULT_LINKER).empty()) + return "ld"; + return CLANG_DEFAULT_LINKER; +} + std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const { if (LinkerIsLLD) *LinkerIsLLD = false; @@ -548,7 +554,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 Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -420,7 +420,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 {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits