Skip to content

Commit 34a43f2

Browse files
author
Simon Moll
committed
[Clang] Ignore CLANG_DEFAULT_LINKER for custom-linker toolchains
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. Reviewed By: MaskRay, phosek Differential Revision: https://reviews.llvm.org/D115045
1 parent 954582c commit 34a43f2

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class ToolChain {
420420
}
421421

422422
/// GetDefaultLinker - Get the default linker to use.
423-
virtual const char *getDefaultLinker() const { return "ld"; }
423+
virtual const char *getDefaultLinker() const;
424424

425425
/// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
426426
virtual RuntimeLibType GetDefaultRuntimeLibType() const {

clang/lib/Driver/ToolChain.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,14 +541,20 @@ std::string ToolChain::GetProgramPath(const char *Name) const {
541541
return D.GetProgramPath(Name, *this);
542542
}
543543

544+
const char *ToolChain::getDefaultLinker() const {
545+
if (CLANG_DEFAULT_LINKER[0] == '\0')
546+
return "ld";
547+
return CLANG_DEFAULT_LINKER;
548+
}
549+
544550
std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const {
545551
if (LinkerIsLLD)
546552
*LinkerIsLLD = false;
547553

548554
// Get -fuse-ld= first to prevent -Wunused-command-line-argument. -fuse-ld= is
549555
// considered as the linker flavor, e.g. "bfd", "gold", or "lld".
550556
const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
551-
StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
557+
StringRef UseLinker = A ? A->getValue() : "";
552558

553559
// --ld-path= takes precedence over -fuse-ld= and specifies the executable
554560
// name. -B, COMPILER_PATH and PATH and consulted if the value does not

clang/test/Driver/ve-toolchain.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
/// Checking -fintegrated-as
6262

6363
// RUN: %clang -### -target ve \
64-
// RUN: -x assembler -fuse-ld=ld %s 2>&1 | \
64+
// RUN: -x assembler %s 2>&1 | \
6565
// RUN: FileCheck -check-prefix=AS %s
6666
// RUN: %clang -### -target ve \
67-
// RUN: -fno-integrated-as -fuse-ld=ld -x assembler %s 2>&1 | \
67+
// RUN: -fno-integrated-as -x assembler %s 2>&1 | \
6868
// RUN: FileCheck -check-prefix=NAS %s
6969

7070
// AS: clang{{.*}} "-cc1as"
@@ -83,7 +83,6 @@
8383
// RUN: %clang -### -target ve-unknown-linux-gnu \
8484
// RUN: --sysroot %S/Inputs/basic_ve_tree \
8585
// RUN: -resource-dir=%S/Inputs/basic_ve_tree/resource_dir \
86-
// RUN: -fuse-ld=ld \
8786
// RUN: %s 2>&1 | FileCheck -check-prefix=DEF %s
8887

8988
// DEF: clang{{.*}}" "-cc1"

clang/test/Driver/ve-toolchain.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@
110110
/// Checking -fintegrated-as
111111

112112
// RUN: %clangxx -### -target ve-unknown-linux-gnu \
113-
// RUN: -x assembler -fuse-ld=ld %s 2>&1 | \
113+
// RUN: -x assembler %s 2>&1 | \
114114
// RUN: FileCheck -check-prefix=AS %s
115115
// RUN: %clangxx -### -target ve-unknown-linux-gnu \
116-
// RUN: -fno-integrated-as -x assembler -fuse-ld=ld %s 2>&1 | \
116+
// RUN: -fno-integrated-as -x assembler %s 2>&1 | \
117117
// RUN: FileCheck -check-prefix=NAS %s
118118

119119
// AS: clang{{.*}} "-cc1as"
@@ -131,7 +131,6 @@
131131

132132
// RUN: %clangxx -### -target ve-unknown-linux-gnu \
133133
// RUN: --sysroot %S/Inputs/basic_ve_tree \
134-
// RUN: -fuse-ld=ld \
135134
// RUN: -resource-dir=%S/Inputs/basic_ve_tree/resource_dir \
136135
// RUN: --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=DEF %s
137136

0 commit comments

Comments
 (0)