[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
This commit is contained in:
Chris Bieneman 2016-06-22 22:19:08 +00:00
parent 700dff7358
commit 1a713c6e05
2 changed files with 9 additions and 29 deletions

View File

@ -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);

View File

@ -22,41 +22,13 @@
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;
}