[PATCH] D70345: [macho] Allow CPUSubtype to contribute to architecture identification

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 15:16:10 PST 2019


dsanders created this revision.
dsanders added a reviewer: pete.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70345

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


Index: llvm/lib/Object/MachOObjectFile.cpp
===================================================================
--- llvm/lib/Object/MachOObjectFile.cpp
+++ llvm/lib/Object/MachOObjectFile.cpp
@@ -128,6 +128,10 @@
   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 @@
   }
 }
 
-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 @@
 }
 
 Triple::ArchType MachOObjectFile::getArch() const {
-  return getArch(getCPUType(*this));
+  return getArch(getCPUType(*this), getCPUSubType(*this));
 }
 
 Triple MachOObjectFile::getArchTriple(const char **McpuDefault) const {
Index: llvm/include/llvm/Object/MachO.h
===================================================================
--- llvm/include/llvm/Object/MachO.h
+++ llvm/include/llvm/Object/MachO.h
@@ -567,7 +567,7 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70345.229650.patch
Type: text/x-patch
Size: 1642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191115/d262efea/attachment-0001.bin>


More information about the llvm-commits mailing list