xref: /llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/MachOObjectFormat.cpp (revision 6128ff6630762310f6ae4eb61adda02cb4ad5260)
1470a5991SLang Hames //===-------- MachOObjectFormat.cpp -- MachO format details for ORC -------===//
2470a5991SLang Hames //
3470a5991SLang Hames // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4470a5991SLang Hames // See https://llvm.org/LICENSE.txt for license information.
5470a5991SLang Hames // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6470a5991SLang Hames //
7470a5991SLang Hames //===----------------------------------------------------------------------===//
8470a5991SLang Hames //
9470a5991SLang Hames // ORC-specific MachO object format details.
10470a5991SLang Hames //
11470a5991SLang Hames //===----------------------------------------------------------------------===//
12470a5991SLang Hames 
13470a5991SLang Hames #include "llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h"
14470a5991SLang Hames 
15470a5991SLang Hames namespace llvm {
16470a5991SLang Hames namespace orc {
17470a5991SLang Hames 
18470a5991SLang Hames StringRef MachODataCommonSectionName = "__DATA,__common";
19470a5991SLang Hames StringRef MachODataDataSectionName = "__DATA,__data";
20470a5991SLang Hames StringRef MachOEHFrameSectionName = "__TEXT,__eh_frame";
21470a5991SLang Hames StringRef MachOCompactUnwindInfoSectionName = "__TEXT,__unwind_info";
22470a5991SLang Hames StringRef MachOCStringSectionName = "__TEXT,__cstring";
23470a5991SLang Hames StringRef MachOModInitFuncSectionName = "__DATA,__mod_init_func";
24470a5991SLang Hames StringRef MachOObjCCatListSectionName = "__DATA,__objc_catlist";
25470a5991SLang Hames StringRef MachOObjCCatList2SectionName = "__DATA,__objc_catlist2";
26470a5991SLang Hames StringRef MachOObjCClassListSectionName = "__DATA,__objc_classlist";
27470a5991SLang Hames StringRef MachOObjCClassNameSectionName = "__TEXT,__objc_classname";
28470a5991SLang Hames StringRef MachOObjCClassRefsSectionName = "__DATA,__objc_classrefs";
29470a5991SLang Hames StringRef MachOObjCConstSectionName = "__DATA,__objc_const";
30470a5991SLang Hames StringRef MachOObjCDataSectionName = "__DATA,__objc_data";
31470a5991SLang Hames StringRef MachOObjCImageInfoSectionName = "__DATA,__objc_imageinfo";
32470a5991SLang Hames StringRef MachOObjCMethNameSectionName = "__TEXT,__objc_methname";
33470a5991SLang Hames StringRef MachOObjCMethTypeSectionName = "__TEXT,__objc_methtype";
34470a5991SLang Hames StringRef MachOObjCNLCatListSectionName = "__DATA,__objc_nlcatlist";
35470a5991SLang Hames StringRef MachOObjCNLClassListSectionName = "__DATA,__objc_nlclslist";
36470a5991SLang Hames StringRef MachOObjCProtoListSectionName = "__DATA,__objc_protolist";
37470a5991SLang Hames StringRef MachOObjCProtoRefsSectionName = "__DATA,__objc_protorefs";
38470a5991SLang Hames StringRef MachOObjCSelRefsSectionName = "__DATA,__objc_selrefs";
39470a5991SLang Hames StringRef MachOSwift5ProtoSectionName = "__TEXT,__swift5_proto";
40470a5991SLang Hames StringRef MachOSwift5ProtosSectionName = "__TEXT,__swift5_protos";
41470a5991SLang Hames StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types";
42470a5991SLang Hames StringRef MachOSwift5TypeRefSectionName = "__TEXT,__swift5_typeref";
43470a5991SLang Hames StringRef MachOSwift5FieldMetadataSectionName = "__TEXT,__swift5_fieldmd";
44470a5991SLang Hames StringRef MachOSwift5EntrySectionName = "__TEXT,__swift5_entry";
45*6128ff66SLang Hames StringRef MachOTextTextSectionName = "__TEXT,__text";
46470a5991SLang Hames StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss";
47470a5991SLang Hames StringRef MachOThreadDataSectionName = "__DATA,__thread_data";
48470a5991SLang Hames StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars";
49470a5991SLang Hames 
50470a5991SLang Hames StringRef MachOInitSectionNames[22] = {
51470a5991SLang Hames     MachOModInitFuncSectionName,         MachOObjCCatListSectionName,
52470a5991SLang Hames     MachOObjCCatList2SectionName,        MachOObjCClassListSectionName,
53470a5991SLang Hames     MachOObjCClassNameSectionName,       MachOObjCClassRefsSectionName,
54470a5991SLang Hames     MachOObjCConstSectionName,           MachOObjCDataSectionName,
55470a5991SLang Hames     MachOObjCImageInfoSectionName,       MachOObjCMethNameSectionName,
56470a5991SLang Hames     MachOObjCMethTypeSectionName,        MachOObjCNLCatListSectionName,
57470a5991SLang Hames     MachOObjCNLClassListSectionName,     MachOObjCProtoListSectionName,
58470a5991SLang Hames     MachOObjCProtoRefsSectionName,       MachOObjCSelRefsSectionName,
59470a5991SLang Hames     MachOSwift5ProtoSectionName,         MachOSwift5ProtosSectionName,
60470a5991SLang Hames     MachOSwift5TypesSectionName,         MachOSwift5TypeRefSectionName,
61470a5991SLang Hames     MachOSwift5FieldMetadataSectionName, MachOSwift5EntrySectionName,
62470a5991SLang Hames };
63470a5991SLang Hames 
64470a5991SLang Hames bool isMachOInitializerSection(StringRef SegName, StringRef SecName) {
65470a5991SLang Hames   for (auto &InitSection : MachOInitSectionNames) {
66470a5991SLang Hames     // Loop below assumes all MachO init sectios have a length-6
67470a5991SLang Hames     // segment name.
68470a5991SLang Hames     assert(InitSection[6] == ',' && "Init section seg name has length != 6");
69470a5991SLang Hames     if (InitSection.starts_with(SegName) && InitSection.substr(7) == SecName)
70470a5991SLang Hames       return true;
71470a5991SLang Hames   }
72470a5991SLang Hames   return false;
73470a5991SLang Hames }
74470a5991SLang Hames 
75470a5991SLang Hames } // namespace orc
76470a5991SLang Hames } // namespace llvm
77