- Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang] Add information about lld presence in RISCVToolchain. #68904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Bushev Dmitry (dybv-sc) ChangesWhen compiling for target riscv64/32-uknown-elf clang assumes that it do not use lld linker even if explicitly told ('-fuse-ld=lld'). Full diff: https://github.com/llvm/llvm-project/pull/68904.diff 3 Files Affected:
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 \ |
You can test this locally with the following command:git-clang-format --diff 8b73be5f57106348a622e36ad3aa0734c6038a8d 3c33c4b902a41a414769be7079e8847e41fb5912 -- clang/lib/Driver/ToolChains/RISCVToolchain.cpp clang/lib/Driver/ToolChains/RISCVToolchain.h clang/test/Driver/riscv64-toolchain.cView the diff from clang-format here.diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp index d87af6b4cb..931d3f4922 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -49,9 +49,9 @@ 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), UseLLD{Args.getLastArgValue( - options::OPT_fuse_ld_EQ) - .equals_insensitive("lld")} { + : 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(); |
eca69cd to 087d229 Compare | Encountered code formatting check failure seems to be not reproducible locally: |
51a150e to d61eacc Compare d61eacc to d1ceb32 Compare | @MaskRay, could you please look into this? |
Sorry for my late reply. I am still adapting to the github pr workflow. Related to the linker question you have, I am puzzled by RISCVToolChain's choices: #71803 (comment) |
d1ceb32 to 3c33c4b Compare
When compiling for target riscv64/32-uknown-elf clang assumes that it do not use lld linker even if explicitly told ('-fuse-ld=lld').