util/crossgcc: Patch clang to enable linking x86 bare metal targets

This allows clang to link x86 bare metal targets.

TESTED: Qemu i440fx and q35 boot to payload with both 32 and 64bit code
compiled with clang and LTO enabled with updated linker script.

Change-Id: I943215c8714e392e52ea35667f2bf21e517c4255
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/84032
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <service+coreboot-gerrit@felixsinger.de>
This commit is contained in:
Arthur Heymans 2024-08-22 20:00:42 +02:00 committed by Felix Singer
commit 0abdb8b8a9

View file

@ -0,0 +1,29 @@
diff --git a/lib/Driver/ToolChains/BareMetal.cpp b/lib/Driver/ToolChains/BareMetal.cpp
index 852e0442..eb84a785 100644
--- a/lib/Driver/ToolChains/BareMetal.cpp
+++ b/lib/Driver/ToolChains/BareMetal.cpp
@@ -169,6 +169,12 @@ static bool isPPCBareMetal(const llvm::Triple &Triple) {
Triple.getEnvironment() == llvm::Triple::EABI;
}
+/// Is the triple x86_32 or x86_64 -*-none-elf?
+static bool isX86BareMetal(const llvm::Triple &Triple) {
+ return Triple.isX86() && Triple.getOS() == llvm::Triple::UnknownOS &&
+ Triple.getEnvironmentName() == "elf";
+}
+
static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D,
StringRef MultilibPath, const ArgList &Args,
DetectedMultilibs &Result) {
@@ -234,9 +240,10 @@ void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
bool BareMetal::handlesTarget(const llvm::Triple &Triple) {
return isARMBareMetal(Triple) || isAArch64BareMetal(Triple) ||
- isRISCVBareMetal(Triple) || isPPCBareMetal(Triple);
+ isRISCVBareMetal(Triple) || isPPCBareMetal(Triple) || isX86BareMetal(Triple);
}
+
Tool *BareMetal::buildLinker() const {
return new tools::baremetal::Linker(*this);
}