[macho] Allow CPUSubtype to contribute to architecture identification
authorDaniel Sanders <daniel_l_sanders@apple.com>
Fri, 15 Nov 2019 23:08:34 +0000 (15:08 -0800)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Mon, 18 Nov 2019 20:57:39 +0000 (12:57 -0800)
Summary:
Sometimes the CPUSubtype determines the Triple::ArchType that must be used.
Add the subtype to the API's to allow targets that need this to correctly
identify the contents of the binary.

Reviewers: pete

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70345

llvm/include/llvm/Object/MachO.h
llvm/lib/Object/MachOObjectFile.cpp

index 76be8049a7d4dd669016fcc9c086b63923f0c64d..c3ecdd93563f46fd9fb31791028ca23b05b78b4a 100644 (file)
@@ -567,7 +567,7 @@ public:
   static StringRef guessLibraryShortName(StringRef Name, bool &isFramework,
                                          StringRef &Suffix);
 
-  static Triple::ArchType getArch(uint32_t CPUType);
+  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);
index c0c873f973545d8371a597c0f8a1e6979d59ca6d..8540b7ab03cdfea90cf7b971e127d7e417c7c0bd 100644 (file)
@@ -128,6 +128,10 @@ static unsigned getCPUType(const MachOObjectFile &O) {
   return O.getHeader().cputype;
 }
 
+static unsigned getCPUSubType(const MachOObjectFile &O) {
+  return O.getHeader().cpusubtype;
+}
+
 static uint32_t
 getPlainRelocationAddress(const MachO::any_relocation_info &RE) {
   return RE.r_word0;
@@ -2565,7 +2569,7 @@ StringRef MachOObjectFile::getFileFormatName() const {
   }
 }
 
-Triple::ArchType MachOObjectFile::getArch(uint32_t CPUType) {
+Triple::ArchType MachOObjectFile::getArch(uint32_t CPUType, uint32_t CPUSubType) {
   switch (CPUType) {
   case MachO::CPU_TYPE_I386:
     return Triple::x86;
@@ -2737,7 +2741,7 @@ ArrayRef<StringRef> MachOObjectFile::getValidArchs() {
 }
 
 Triple::ArchType MachOObjectFile::getArch() const {
-  return getArch(getCPUType(*this));
+  return getArch(getCPUType(*this), getCPUSubType(*this));
 }
 
 Triple MachOObjectFile::getArchTriple(const char **McpuDefault) const {