|
| 1 | +//===- unittest/BinaryFormat/MachOTest.cpp - MachO support tests ----------===// |
| 2 | +// |
| 3 | +// The LLVM Compiler Infrastructure |
| 4 | +// |
| 5 | +// This file is distributed under the University of Illinois Open Source |
| 6 | +// License. See LICENSE.TXT for details. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#include "llvm/BinaryFormat/MachO.h" |
| 11 | +#include "gtest/gtest.h" |
| 12 | + |
| 13 | +using namespace llvm; |
| 14 | +using namespace llvm::MachO; |
| 15 | + |
| 16 | +TEST(MachOTest, UnalignedLC) { |
| 17 | + unsigned char Valid32BitMachO[] = { |
| 18 | + 0xCE, 0xFA, 0xED, 0xFE, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 19 | + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, |
| 20 | + 0x85, 0x80, 0x21, 0x01, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, |
| 21 | + 0x5F, 0x5F, 0x50, 0x41, 0x47, 0x45, 0x5A, 0x45, 0x52, 0x4F, 0x00, 0x00, |
| 22 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, |
| 23 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 24 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 25 | + 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x5F, 0x5F, 0x4C, 0x49, |
| 26 | + 0x4E, 0x4B, 0x45, 0x44, 0x49, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 27 | + 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, |
| 28 | + 0x8C, 0x0B, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 29 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 30 | + |
| 31 | + mach_header *Header = |
| 32 | + reinterpret_cast<mach_header *>(Valid32BitMachO); |
| 33 | + if (!sys::IsLittleEndianHost) |
| 34 | + sys::swapByteOrder(Header->magic); |
| 35 | + ASSERT_EQ(Header->magic, MH_MAGIC); |
| 36 | + unsigned char *Current = Valid32BitMachO + sizeof(mach_header); |
| 37 | + unsigned char *BufferEnd = |
| 38 | + Valid32BitMachO + sizeof(mach_header) + Header->sizeofcmds; |
| 39 | + while (Current < BufferEnd) { |
| 40 | + macho_load_command *LC = |
| 41 | + reinterpret_cast<macho_load_command *>(Current); |
| 42 | + if (!sys::IsLittleEndianHost) |
| 43 | + swapStruct(LC->load_command_data); |
| 44 | + ASSERT_EQ(LC->load_command_data.cmd, LC_SEGMENT); |
| 45 | + Current += LC->load_command_data.cmdsize; |
| 46 | + } |
| 47 | +} |
0 commit comments