[clang] [clang] Add information about lld presence in RISCVToolchain. (PR #68904)
Bushev Dmitry via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 12 08:50:55 PDT 2023
https://github.com/dybv-sc created https://github.com/llvm/llvm-project/pull/68904
When compiling for target riscv64/32-uknown-elf clang assumes that it do not use lld linker even if explicitly told ('-fuse-ld=lld').
>From 8512bbcee108751776591160797af32885377587 Mon Sep 17 00:00:00 2001
From: Dmitry Bushev <dmitry.bushev at syntacore.com>
Date: Mon, 9 Oct 2023 19:49:09 +0300
Subject: [PATCH] [clang] Add information about lld presence in RISCVToolchain.
---
.../lib/Driver/ToolChains/RISCVToolchain.cpp | 5 +++-
clang/lib/Driver/ToolChains/RISCVToolchain.h | 3 +++
clang/test/Driver/riscv64-toolchain.c | 25 +++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index c98f43f6e05eb4b..b5685eaeed7b275 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -49,8 +49,11 @@ bool RISCVToolChain::hasGCCToolchain(const Driver &D,
/// RISC-V Toolchain
RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
- : Generic_ELF(D, Triple, Args) {
+ : Generic_ELF(D, Triple, Args), UseLLD{Args.getLastArgValue(
+ options::OPT_fuse_ld_EQ)
+ .equals_insensitive("lld")} {
GCCInstallation.init(Triple, Args);
+
if (GCCInstallation.isValid()) {
Multilibs = GCCInstallation.getMultilibs();
SelectedMultilibs.assign({GCCInstallation.getMultilib()});
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index de6960726f1cd77..afe98968ecd8616 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -35,11 +35,14 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public Generic_ELF {
addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
+ bool HasNativeLLVMSupport() const override { return UseLLD; }
+
protected:
Tool *buildLinker() const override;
private:
std::string computeSysRoot() const override;
+ bool UseLLD;
};
} // end namespace toolchains
diff --git a/clang/test/Driver/riscv64-toolchain.c b/clang/test/Driver/riscv64-toolchain.c
index f177bff33dd4d72..275cd8dde419218 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -121,6 +121,31 @@
// C-RV64IMAC-BAREMETAL-MULTI-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
// C-RV64IMAC-BAREMETAL-MULTI-LP64: "{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtend.o"
+// Check that lto works in riscv-toolchain when explicitly specified lld as linker.
+// RUN: env "PATH=" %clang -### %s -fuse-ld=lld -flto \
+// RUN: --target=riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN: -march=rv64imac -mabi=lp64\
+// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN: | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "{{.*}}lld"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "-m" "elf64lriscv"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|\\\\}}..{{/|\\\\}}riscv64-unknown-elf/lib/crt0.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtbegin.o"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "-L{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|\\\\}}..{{/|\\\\}}riscv64-unknown-elf/lib"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
+// C-RV64IMAC-BAREMETAL-LTO-LP64: "{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtend.o"
+
+// Check driver error when lto is used without specified lld linker.
+// RUN: env "PATH=" %clang -### %s -flto \
+// RUN: --target=riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN: -march=rv64imac -mabi=lp64\
+// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN: | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64 %s
+
+// C-RV64IMAC-BAREMETAL-LTO-FAIL-LP64: clang-16: error: 'riscv64-unknown-unknown-elf': unable to pass LLVM bit-code files to linker
+
// RUN: env "PATH=" %clang -### %s -fuse-ld=ld \
// RUN: --target=riscv64-unknown-elf --rtlib=platform --unwindlib=platform --sysroot= \
// RUN: -march=rv64imafdc -mabi=lp64d \
More information about the cfe-commits
mailing list