[PATCH] D105414: Add x86 and x86_64 to the BareMetal toolchain

Alejandro G. Vallejo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 7 13:55:09 PDT 2021


agvallejo updated this revision to Diff 357070.
agvallejo added a comment.

Fulfill merge requirements

-Fixed clang-format complaint
-Added CLI processing tests for i686 and x86_64

  (freestanding+nostdlib only)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105414/new/

https://reviews.llvm.org/D105414

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===================================================================
--- clang/test/Driver/baremetal.cpp
+++ 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"
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===================================================================
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105414.357070.patch
Type: text/x-patch
Size: 3496 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210707/92d17565/attachment.bin>


More information about the cfe-commits mailing list