From 0abdb8b8a9498369dde32f55792e6bf9cd8c8dc0 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Thu, 22 Aug 2024 20:00:42 +0200 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/84032 Reviewed-by: Nico Huber Tested-by: build bot (Jenkins) Reviewed-by: Felix Singer --- .../clang-18.1.8.src_x86_baremetal.patch | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 util/crossgcc/patches/clang-18.1.8.src_x86_baremetal.patch diff --git a/util/crossgcc/patches/clang-18.1.8.src_x86_baremetal.patch b/util/crossgcc/patches/clang-18.1.8.src_x86_baremetal.patch new file mode 100644 index 0000000000..61c608cbbe --- /dev/null +++ b/util/crossgcc/patches/clang-18.1.8.src_x86_baremetal.patch @@ -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); + }