[AArch64] Default to SEH exception handling on MinGW
[llvm-complete.git] / unittests / BinaryFormat / MachOTest.cpp
blob5acffc4e166eb11a55b6de2b9bf231c18b6b1abe
1 //===- unittest/BinaryFormat/MachOTest.cpp - MachO support tests ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/BinaryFormat/MachO.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
13 using namespace llvm::MachO;
15 TEST(MachOTest, UnalignedLC) {
16 unsigned char Valid32BitMachO[] = {
17 0xCE, 0xFA, 0xED, 0xFE, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
18 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
19 0x85, 0x80, 0x21, 0x01, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
20 0x5F, 0x5F, 0x50, 0x41, 0x47, 0x45, 0x5A, 0x45, 0x52, 0x4F, 0x00, 0x00,
21 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
22 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x5F, 0x5F, 0x4C, 0x49,
25 0x4E, 0x4B, 0x45, 0x44, 0x49, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
27 0x8C, 0x0B, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
30 mach_header *Header =
31 reinterpret_cast<mach_header *>(Valid32BitMachO);
32 if (!sys::IsLittleEndianHost)
33 swapStruct(*Header);
34 ASSERT_EQ(Header->magic, MH_MAGIC);
35 unsigned char *Current = Valid32BitMachO + sizeof(mach_header);
36 unsigned char *BufferEnd =
37 Valid32BitMachO + sizeof(mach_header) + Header->sizeofcmds;
38 while (Current < BufferEnd) {
39 macho_load_command *LC =
40 reinterpret_cast<macho_load_command *>(Current);
41 if (!sys::IsLittleEndianHost)
42 swapStruct(LC->load_command_data);
43 ASSERT_EQ(LC->load_command_data.cmd, LC_SEGMENT);
44 Current += LC->load_command_data.cmdsize;