-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[Clang][Driver] Override Generic_ELF::buildLinker() to avoid calling gcc to link #149681
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
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: None (mintsuki) ChangesThis change primarily makes it so that when targeting freestanding/unknown If Clang is to be a cross compiler, there is no reason to assume that the Full diff: https://github.com/llvm/llvm-project/pull/149681.diff 2 Files Affected:
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
|
cc @MaskRay |
Can you add a test to clang/test/Driver to show the behavior difference ? |
7401452
to
468635d
Compare
@MaskRay done. Does this work? |
…gcc to link 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.
468635d
to
491a834
Compare
A bunch of tests fail now... I feel like this change is too invasive for what I can possibly do on my own, but I hope that the original commit message is helpful in describing the problem at hand. |
This change primarily makes it so that when targeting freestanding/unknown
OSes, the driver will not use
gcc
to link, but rather will link usingthe 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.