[llvm] 25e02a4 - Revert "[MachO] Move getArchTriple implementation into BinaryFormat. (#161468)"
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 4 00:01:21 PDT 2025
Author: Lang Hames
Date: 2025-10-04T16:59:55+10:00
New Revision: 25e02a43fe6bf95c118d7c3862d7d7c4abe4dcde
URL: https://github.com/llvm/llvm-project/commit/25e02a43fe6bf95c118d7c3862d7d7c4abe4dcde
DIFF: https://github.com/llvm/llvm-project/commit/25e02a43fe6bf95c118d7c3862d7d7c4abe4dcde.diff
LOG: Revert "[MachO] Move getArchTriple implementation into BinaryFormat. (#161468)"
Reverts commit cd32b9b6c3b while I investigate some bot failures, e.g.
https://lab.llvm.org/buildbot/#/builders/10/builds/14784.
Added:
Modified:
llvm/include/llvm/BinaryFormat/MachO.h
llvm/include/llvm/Object/MachO.h
llvm/lib/BinaryFormat/MachO.cpp
llvm/lib/Object/MachOObjectFile.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h b/llvm/include/llvm/BinaryFormat/MachO.h
index ad6b27f61ec91..5dbdfb13d1a5f 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -17,9 +17,11 @@
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/SwapByteOrder.h"
-#include "llvm/TargetParser/Triple.h"
namespace llvm {
+
+class Triple;
+
namespace MachO {
// Enums from <mach-o/loader.h>
enum : uint32_t {
@@ -1708,11 +1710,6 @@ LLVM_ABI Expected<uint32_t> getCPUSubType(const Triple &T,
unsigned PtrAuthABIVersion,
bool PtrAuthKernelABIVersion);
-LLVM_ABI Triple::ArchType getArch(uint32_t CPUType, uint32_t CPUSubType);
-LLVM_ABI Triple getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
- const char **McpuDefault = nullptr,
- const char **ArchFlag = nullptr);
-
struct x86_thread_state32_t {
uint32_t eax;
uint32_t ebx;
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 0dfe9802009a2..3f4a21d2d1bac 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -752,14 +752,10 @@ class LLVM_ABI MachOObjectFile : public ObjectFile {
static StringRef guessLibraryShortName(StringRef Name, bool &isFramework,
StringRef &Suffix);
- static Triple::ArchType getArch(uint32_t CPUType, uint32_t CPUSubType) {
- return MachO::getArch(CPUType, CPUSubType);
- }
+ static Triple::ArchType getArch(uint32_t CPUType, uint32_t CPUSubType);
static Triple getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
const char **McpuDefault = nullptr,
- const char **ArchFlag = nullptr) {
- return MachO::getArchTriple(CPUType, CPUSubType, McpuDefault, ArchFlag);
- }
+ const char **ArchFlag = nullptr);
static bool isValidArch(StringRef ArchFlag);
static ArrayRef<StringRef> getValidArchs();
static Triple getHostArch();
diff --git a/llvm/lib/BinaryFormat/MachO.cpp b/llvm/lib/BinaryFormat/MachO.cpp
index b2af2434f3518..f46b9d5147ff1 100644
--- a/llvm/lib/BinaryFormat/MachO.cpp
+++ b/llvm/lib/BinaryFormat/MachO.cpp
@@ -123,160 +123,3 @@ Expected<uint32_t> MachO::getCPUSubType(const Triple &T,
return CPU_SUBTYPE_ARM64E_WITH_PTRAUTH_VERSION(PtrAuthABIVersion,
PtrAuthKernelABIVersion);
}
-
-Triple::ArchType MachO::getArch(uint32_t CPUType, uint32_t CPUSubType) {
- switch (CPUType) {
- case MachO::CPU_TYPE_I386:
- return Triple::x86;
- case MachO::CPU_TYPE_X86_64:
- return Triple::x86_64;
- case MachO::CPU_TYPE_ARM:
- return Triple::arm;
- case MachO::CPU_TYPE_ARM64:
- return Triple::aarch64;
- case MachO::CPU_TYPE_ARM64_32:
- return Triple::aarch64_32;
- case MachO::CPU_TYPE_POWERPC:
- return Triple::ppc;
- case MachO::CPU_TYPE_POWERPC64:
- return Triple::ppc64;
- default:
- return Triple::UnknownArch;
- }
-}
-
-Triple MachO::getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
- const char **McpuDefault, const char **ArchFlag) {
- if (McpuDefault)
- *McpuDefault = nullptr;
- if (ArchFlag)
- *ArchFlag = nullptr;
-
- switch (CPUType) {
- case MachO::CPU_TYPE_I386:
- switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
- case MachO::CPU_SUBTYPE_I386_ALL:
- if (ArchFlag)
- *ArchFlag = "i386";
- return Triple("i386-apple-darwin");
- default:
- return Triple();
- }
- case MachO::CPU_TYPE_X86_64:
- switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
- case MachO::CPU_SUBTYPE_X86_64_ALL:
- if (ArchFlag)
- *ArchFlag = "x86_64";
- return Triple("x86_64-apple-darwin");
- case MachO::CPU_SUBTYPE_X86_64_H:
- if (ArchFlag)
- *ArchFlag = "x86_64h";
- return Triple("x86_64h-apple-darwin");
- default:
- return Triple();
- }
- case MachO::CPU_TYPE_ARM:
- switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
- case MachO::CPU_SUBTYPE_ARM_V4T:
- if (ArchFlag)
- *ArchFlag = "armv4t";
- return Triple("armv4t-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V5TEJ:
- if (ArchFlag)
- *ArchFlag = "armv5e";
- return Triple("armv5e-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_XSCALE:
- if (ArchFlag)
- *ArchFlag = "xscale";
- return Triple("xscale-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V6:
- if (ArchFlag)
- *ArchFlag = "armv6";
- return Triple("armv6-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V6M:
- if (McpuDefault)
- *McpuDefault = "cortex-m0";
- if (ArchFlag)
- *ArchFlag = "armv6m";
- return Triple("armv6m-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V7:
- if (ArchFlag)
- *ArchFlag = "armv7";
- return Triple("armv7-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V7EM:
- if (McpuDefault)
- *McpuDefault = "cortex-m4";
- if (ArchFlag)
- *ArchFlag = "armv7em";
- return Triple("thumbv7em-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V7K:
- if (McpuDefault)
- *McpuDefault = "cortex-a7";
- if (ArchFlag)
- *ArchFlag = "armv7k";
- return Triple("armv7k-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V7M:
- if (McpuDefault)
- *McpuDefault = "cortex-m3";
- if (ArchFlag)
- *ArchFlag = "armv7m";
- return Triple("thumbv7m-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM_V7S:
- if (McpuDefault)
- *McpuDefault = "cortex-a7";
- if (ArchFlag)
- *ArchFlag = "armv7s";
- return Triple("armv7s-apple-darwin");
- default:
- return Triple();
- }
- case MachO::CPU_TYPE_ARM64:
- switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
- case MachO::CPU_SUBTYPE_ARM64_ALL:
- if (McpuDefault)
- *McpuDefault = "cyclone";
- if (ArchFlag)
- *ArchFlag = "arm64";
- return Triple("arm64-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM64E:
- if (McpuDefault)
- *McpuDefault = "apple-a12";
- if (ArchFlag)
- *ArchFlag = "arm64e";
- return Triple("arm64e-apple-darwin");
- default:
- return Triple();
- }
- case MachO::CPU_TYPE_ARM64_32:
- switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
- case MachO::CPU_SUBTYPE_ARM64_32_V8:
- if (McpuDefault)
- *McpuDefault = "cyclone";
- if (ArchFlag)
- *ArchFlag = "arm64_32";
- return Triple("arm64_32-apple-darwin");
- default:
- return Triple();
- }
- case MachO::CPU_TYPE_POWERPC:
- switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
- case MachO::CPU_SUBTYPE_POWERPC_ALL:
- if (ArchFlag)
- *ArchFlag = "ppc";
- return Triple("ppc-apple-darwin");
- default:
- return Triple();
- }
- case MachO::CPU_TYPE_POWERPC64:
- switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
- case MachO::CPU_SUBTYPE_POWERPC_ALL:
- if (ArchFlag)
- *ArchFlag = "ppc64";
- return Triple("ppc64-apple-darwin");
- default:
- return Triple();
- }
- default:
- return Triple();
- }
-}
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index abadb047ef521..e09dc947c2779 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -2685,6 +2685,164 @@ StringRef MachOObjectFile::getFileFormatName() const {
}
}
+Triple::ArchType MachOObjectFile::getArch(uint32_t CPUType, uint32_t CPUSubType) {
+ switch (CPUType) {
+ case MachO::CPU_TYPE_I386:
+ return Triple::x86;
+ case MachO::CPU_TYPE_X86_64:
+ return Triple::x86_64;
+ case MachO::CPU_TYPE_ARM:
+ return Triple::arm;
+ case MachO::CPU_TYPE_ARM64:
+ return Triple::aarch64;
+ case MachO::CPU_TYPE_ARM64_32:
+ return Triple::aarch64_32;
+ case MachO::CPU_TYPE_POWERPC:
+ return Triple::ppc;
+ case MachO::CPU_TYPE_POWERPC64:
+ return Triple::ppc64;
+ default:
+ return Triple::UnknownArch;
+ }
+}
+
+Triple MachOObjectFile::getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
+ const char **McpuDefault,
+ const char **ArchFlag) {
+ if (McpuDefault)
+ *McpuDefault = nullptr;
+ if (ArchFlag)
+ *ArchFlag = nullptr;
+
+ switch (CPUType) {
+ case MachO::CPU_TYPE_I386:
+ switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
+ case MachO::CPU_SUBTYPE_I386_ALL:
+ if (ArchFlag)
+ *ArchFlag = "i386";
+ return Triple("i386-apple-darwin");
+ default:
+ return Triple();
+ }
+ case MachO::CPU_TYPE_X86_64:
+ switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
+ case MachO::CPU_SUBTYPE_X86_64_ALL:
+ if (ArchFlag)
+ *ArchFlag = "x86_64";
+ return Triple("x86_64-apple-darwin");
+ case MachO::CPU_SUBTYPE_X86_64_H:
+ if (ArchFlag)
+ *ArchFlag = "x86_64h";
+ return Triple("x86_64h-apple-darwin");
+ default:
+ return Triple();
+ }
+ case MachO::CPU_TYPE_ARM:
+ switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
+ case MachO::CPU_SUBTYPE_ARM_V4T:
+ if (ArchFlag)
+ *ArchFlag = "armv4t";
+ return Triple("armv4t-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V5TEJ:
+ if (ArchFlag)
+ *ArchFlag = "armv5e";
+ return Triple("armv5e-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_XSCALE:
+ if (ArchFlag)
+ *ArchFlag = "xscale";
+ return Triple("xscale-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V6:
+ if (ArchFlag)
+ *ArchFlag = "armv6";
+ return Triple("armv6-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V6M:
+ if (McpuDefault)
+ *McpuDefault = "cortex-m0";
+ if (ArchFlag)
+ *ArchFlag = "armv6m";
+ return Triple("armv6m-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V7:
+ if (ArchFlag)
+ *ArchFlag = "armv7";
+ return Triple("armv7-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V7EM:
+ if (McpuDefault)
+ *McpuDefault = "cortex-m4";
+ if (ArchFlag)
+ *ArchFlag = "armv7em";
+ return Triple("thumbv7em-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V7K:
+ if (McpuDefault)
+ *McpuDefault = "cortex-a7";
+ if (ArchFlag)
+ *ArchFlag = "armv7k";
+ return Triple("armv7k-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V7M:
+ if (McpuDefault)
+ *McpuDefault = "cortex-m3";
+ if (ArchFlag)
+ *ArchFlag = "armv7m";
+ return Triple("thumbv7m-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM_V7S:
+ if (McpuDefault)
+ *McpuDefault = "cortex-a7";
+ if (ArchFlag)
+ *ArchFlag = "armv7s";
+ return Triple("armv7s-apple-darwin");
+ default:
+ return Triple();
+ }
+ case MachO::CPU_TYPE_ARM64:
+ switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
+ case MachO::CPU_SUBTYPE_ARM64_ALL:
+ if (McpuDefault)
+ *McpuDefault = "cyclone";
+ if (ArchFlag)
+ *ArchFlag = "arm64";
+ return Triple("arm64-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM64E:
+ if (McpuDefault)
+ *McpuDefault = "apple-a12";
+ if (ArchFlag)
+ *ArchFlag = "arm64e";
+ return Triple("arm64e-apple-darwin");
+ default:
+ return Triple();
+ }
+ case MachO::CPU_TYPE_ARM64_32:
+ switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
+ case MachO::CPU_SUBTYPE_ARM64_32_V8:
+ if (McpuDefault)
+ *McpuDefault = "cyclone";
+ if (ArchFlag)
+ *ArchFlag = "arm64_32";
+ return Triple("arm64_32-apple-darwin");
+ default:
+ return Triple();
+ }
+ case MachO::CPU_TYPE_POWERPC:
+ switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
+ case MachO::CPU_SUBTYPE_POWERPC_ALL:
+ if (ArchFlag)
+ *ArchFlag = "ppc";
+ return Triple("ppc-apple-darwin");
+ default:
+ return Triple();
+ }
+ case MachO::CPU_TYPE_POWERPC64:
+ switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
+ case MachO::CPU_SUBTYPE_POWERPC_ALL:
+ if (ArchFlag)
+ *ArchFlag = "ppc64";
+ return Triple("ppc64-apple-darwin");
+ default:
+ return Triple();
+ }
+ default:
+ return Triple();
+ }
+}
+
Triple MachOObjectFile::getHostArch() {
return Triple(sys::getDefaultTargetTriple());
}
More information about the llvm-commits
mailing list