diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -139,6 +139,20 @@ return Triple.getEnvironmentName() == "elf"; } +static bool isX86BareMetal(const llvm::Triple &Triple) { + if (Triple.getArch() != llvm::Triple::x86 && + Triple.getArch() != llvm::Triple::x86_64) + return false; + + if (Triple.getVendor() != llvm::Triple::UnknownVendor) + return false; + + if (Triple.getOS() != llvm::Triple::UnknownOS) + return false; + + return Triple.getEnvironmentName() == "elf"; +} + void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) { DetectedMultilibs Result; @@ -151,7 +165,8 @@ } bool BareMetal::handlesTarget(const llvm::Triple &Triple) { - return isARMBareMetal(Triple) || isRISCVBareMetal(Triple); + return isARMBareMetal(Triple) || isRISCVBareMetal(Triple) || + isX86BareMetal(Triple); } Tool *BareMetal::buildLinker() const { diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp --- a/clang/test/Driver/baremetal.cpp +++ b/clang/test/Driver/baremetal.cpp @@ -355,3 +355,33 @@ // CHECK-RV32IMAFC-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" // CHECK-RV32IMAFC-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}rv32imafc{{[/\\]+}}ilp32f{{[/\\]+}}lib" // CHECK-RV32IMAFC-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal{{[/\\]+}}rv32imafc{{[/\\]+}}ilp32f" + +//----------------------------------------------------------------------------------------------- +// freestanding+nostdlib i686-unknown-elf doesn't use gcc for linking nor adds any libraries +//----------------------------------------------------------------------------------------------- +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -target i686-unknown-elf \ +// RUN: -ffreestanding \ +// RUN: -nostdlib \ +// RUN: | FileCheck --check-prefix=CHECK-X86 %s +// CHECK-X86: "[[PREFIX_DIR:.*]]{{[/\\]+}}{{[^/^\\]+}}{{[/\\]+}}clang{{.*}}" "-cc1" "-triple" "i686-unknown-unknown-elf" +// CHECK-X86-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-X86-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" +// CHECK-X86-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal" +// CHECK-X86-NOT: "-l{{.*}}" +// CHECK-X86-SAME: "-o" "{{.*}}.o" + +//----------------------------------------------------------------------------------------------- +// freestanding+nostdlib x86_64-unknown-elf doesn't use gcc for linking nor adds any libraries +//----------------------------------------------------------------------------------------------- +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -target x86_64-unknown-elf \ +// RUN: -ffreestanding \ +// RUN: -nostdlib \ +// RUN: | FileCheck --check-prefix=CHECK-X86_64 %s +// CHECK-X86_64: "[[PREFIX_DIR:.*]]{{[/\\]+}}{{[^/^\\]+}}{{[/\\]+}}clang{{.*}}" "-cc1" "-triple" "x86_64-unknown-unknown-elf" +// CHECK-X86_64-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-X86_64-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" +// CHECK-X86_64-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal" +// CHECK-X86_64-NOT: "-l{{.*}}" +// CHECK-X86_64-SAME: "-o" "{{.*}}.o"