[clang] [Clang][Driver] Override Generic_ELF::buildLinker() to avoid calling gcc to link (PR #149681)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 19 15:30:58 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (mintsuki)
<details>
<summary>Changes</summary>
This change primarily makes it so that when targeting freestanding/unknown
OSes, the driver will not use `gcc` to link, but rather will link using
the chosen linker (`-fuse-ld=...`) directly.
If Clang is to be a cross compiler, there is no reason to assume that the
host's gcc is in any way capable of handling the linkage of programs for
targets that do not match the host's triple, especially for freestanding
targets.
---
Full diff: https://github.com/llvm/llvm-project/pull/149681.diff
2 Files Affected:
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+2)
- (modified) clang/lib/Driver/ToolChains/Gnu.h (+3)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index f5e2655857432..4beb67f888a7c 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -3375,3 +3375,5 @@ void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs,
options::OPT_fno_use_init_array, true))
CC1Args.push_back("-fno-use-init-array");
}
+
+Tool *Generic_ELF::buildLinker() const { return new tools::gnutools::Linker(*this); }
diff --git a/clang/lib/Driver/ToolChains/Gnu.h b/clang/lib/Driver/ToolChains/Gnu.h
index 3b8df71bbf9d3..152a7ab8d5289 100644
--- a/clang/lib/Driver/ToolChains/Gnu.h
+++ b/clang/lib/Driver/ToolChains/Gnu.h
@@ -382,6 +382,9 @@ class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
}
virtual void addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {}
+
+protected:
+ Tool *buildLinker() const override;
};
} // end namespace toolchains
``````````
</details>
https://github.com/llvm/llvm-project/pull/149681
More information about the cfe-commits
mailing list