From: Chris Bieneman Date: Wed, 22 Jun 2016 22:19:08 +0000 (+0000) Subject: [MachO] Finish moving fat header swap functions to MachO.h X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a713c6e051f7bb19e35f3c6c3ea52c8ca7fef87;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273502 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/MachO.h b/include/llvm/Support/MachO.h index dd885eaf083..9a03722d250 100644 --- a/include/llvm/Support/MachO.h +++ b/include/llvm/Support/MachO.h @@ -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); diff --git a/lib/Object/MachOUniversal.cpp b/lib/Object/MachOUniversal.cpp index 8ccf4de50e0..b3b0c251c10 100644 --- a/lib/Object/MachOUniversal.cpp +++ b/lib/Object/MachOUniversal.cpp @@ -22,41 +22,13 @@ using namespace llvm; using namespace object; -template -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 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; }