[llvm] r273502 - [MachO] Finish moving fat header swap functions to MachO.h

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 15:19:08 PDT 2016


Author: cbieneman
Date: Wed Jun 22 17:19:08 2016
New Revision: 273502

URL: http://llvm.org/viewvc/llvm-project?rev=273502&view=rev
Log:
[MachO] Finish moving fat header swap functions to MachO.h

This is a follow-up to r273479. At the time I wrote r273479 I didn't connect the dots that the functions I was adding had to exist somewhere. Turns out, they do. This finishes moving the functions to MachO.h.

Existing MachO fat header tests like test/tools/llvm-readobj/Inputs/macho-universal-archive.x86_64.i386 execute this code.

Modified:
    llvm/trunk/include/llvm/Support/MachO.h
    llvm/trunk/lib/Object/MachOUniversal.cpp

Modified: llvm/trunk/include/llvm/Support/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MachO.h?rev=273502&r1=273501&r2=273502&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MachO.h (original)
+++ llvm/trunk/include/llvm/Support/MachO.h Wed Jun 22 17:19:08 2016
@@ -973,6 +973,14 @@ namespace llvm {
       sys::swapByteOrder(mh.align);
     }
 
+    inline void swapStruct(fat_arch_64 &mh) {
+      sys::swapByteOrder(mh.cputype);
+      sys::swapByteOrder(mh.cpusubtype);
+      sys::swapByteOrder(mh.offset);
+      sys::swapByteOrder(mh.size);
+      sys::swapByteOrder(mh.align);
+      sys::swapByteOrder(mh.reserved);
+    }
 
     inline void swapStruct(mach_header &mh) {
       sys::swapByteOrder(mh.magic);

Modified: llvm/trunk/lib/Object/MachOUniversal.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOUniversal.cpp?rev=273502&r1=273501&r2=273502&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOUniversal.cpp (original)
+++ llvm/trunk/lib/Object/MachOUniversal.cpp Wed Jun 22 17:19:08 2016
@@ -23,40 +23,12 @@ using namespace llvm;
 using namespace object;
 
 template<typename T>
-static void SwapStruct(T &Value);
-
-template<>
-void SwapStruct(MachO::fat_header &H) {
-  sys::swapByteOrder(H.magic);
-  sys::swapByteOrder(H.nfat_arch);
-}
-
-template<>
-void SwapStruct(MachO::fat_arch &H) {
-  sys::swapByteOrder(H.cputype);
-  sys::swapByteOrder(H.cpusubtype);
-  sys::swapByteOrder(H.offset);
-  sys::swapByteOrder(H.size);
-  sys::swapByteOrder(H.align);
-}
-
-template<>
-void SwapStruct(MachO::fat_arch_64 &H) {
-  sys::swapByteOrder(H.cputype);
-  sys::swapByteOrder(H.cpusubtype);
-  sys::swapByteOrder(H.offset);
-  sys::swapByteOrder(H.size);
-  sys::swapByteOrder(H.align);
-  sys::swapByteOrder(H.reserved);
-}
-
-template<typename T>
 static T getUniversalBinaryStruct(const char *Ptr) {
   T Res;
   memcpy(&Res, Ptr, sizeof(T));
   // Universal binary headers have big-endian byte order.
   if (sys::IsLittleEndianHost)
-    SwapStruct(Res);
+    swapStruct(Res);
   return Res;
 }
 




More information about the llvm-commits mailing list