llvm.org GIT mirror llvm / 1a713c6
[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 Chris Bieneman 3 years ago
2 changed file(s) with 9 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
972972 sys::swapByteOrder(mh.align);
973973 }
974974
975 inline void swapStruct(fat_arch_64 &mh) {
976 sys::swapByteOrder(mh.cputype);
977 sys::swapByteOrder(mh.cpusubtype);
978 sys::swapByteOrder(mh.offset);
979 sys::swapByteOrder(mh.size);
980 sys::swapByteOrder(mh.align);
981 sys::swapByteOrder(mh.reserved);
982 }
975983
976984 inline void swapStruct(mach_header &mh) {
977985 sys::swapByteOrder(mh.magic);
2222 using namespace object;
2323
2424 template
25 static void SwapStruct(T &Value);
26
27 template<>
28 void SwapStruct(MachO::fat_header &H) {
29 sys::swapByteOrder(H.magic);
30 sys::swapByteOrder(H.nfat_arch);
31 }
32
33 template<>
34 void SwapStruct(MachO::fat_arch &H) {
35 sys::swapByteOrder(H.cputype);
36 sys::swapByteOrder(H.cpusubtype);
37 sys::swapByteOrder(H.offset);
38 sys::swapByteOrder(H.size);
39 sys::swapByteOrder(H.align);
40 }
41
42 template<>
43 void SwapStruct(MachO::fat_arch_64 &H) {
44 sys::swapByteOrder(H.cputype);
45 sys::swapByteOrder(H.cpusubtype);
46 sys::swapByteOrder(H.offset);
47 sys::swapByteOrder(H.size);
48 sys::swapByteOrder(H.align);
49 sys::swapByteOrder(H.reserved);
50 }
51
52 template
5325 static T getUniversalBinaryStruct(const char *Ptr) {
5426 T Res;
5527 memcpy(&Res, Ptr, sizeof(T));
5628 // Universal binary headers have big-endian byte order.
5729 if (sys::IsLittleEndianHost)
58 SwapStruct(Res);
30 swapStruct(Res);
5931 return Res;
6032 }
6133