| 1 | //===-------- MachOObjectFormat.cpp -- MachO format details for ORC -------===// |
| 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 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // ORC-specific MachO object format details. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h" |
| 14 | |
| 15 | namespace llvm { |
| 16 | namespace orc { |
| 17 | |
| 18 | StringRef MachODataCommonSectionName = "__DATA,__common" ; |
| 19 | StringRef MachODataDataSectionName = "__DATA,__data" ; |
| 20 | StringRef MachOEHFrameSectionName = "__TEXT,__eh_frame" ; |
| 21 | StringRef MachOCompactUnwindSectionName = "__LD,__compact_unwind" ; |
| 22 | StringRef MachOCStringSectionName = "__TEXT,__cstring" ; |
| 23 | StringRef MachOModInitFuncSectionName = "__DATA,__mod_init_func" ; |
| 24 | StringRef MachOObjCCatListSectionName = "__DATA,__objc_catlist" ; |
| 25 | StringRef MachOObjCCatList2SectionName = "__DATA,__objc_catlist2" ; |
| 26 | StringRef MachOObjCClassListSectionName = "__DATA,__objc_classlist" ; |
| 27 | StringRef MachOObjCClassNameSectionName = "__TEXT,__objc_classname" ; |
| 28 | StringRef MachOObjCClassRefsSectionName = "__DATA,__objc_classrefs" ; |
| 29 | StringRef MachOObjCConstSectionName = "__DATA,__objc_const" ; |
| 30 | StringRef MachOObjCDataSectionName = "__DATA,__objc_data" ; |
| 31 | StringRef MachOObjCImageInfoSectionName = "__DATA,__objc_imageinfo" ; |
| 32 | StringRef MachOObjCMethNameSectionName = "__TEXT,__objc_methname" ; |
| 33 | StringRef MachOObjCMethTypeSectionName = "__TEXT,__objc_methtype" ; |
| 34 | StringRef MachOObjCNLCatListSectionName = "__DATA,__objc_nlcatlist" ; |
| 35 | StringRef MachOObjCNLClassListSectionName = "__DATA,__objc_nlclslist" ; |
| 36 | StringRef MachOObjCProtoListSectionName = "__DATA,__objc_protolist" ; |
| 37 | StringRef MachOObjCProtoRefsSectionName = "__DATA,__objc_protorefs" ; |
| 38 | StringRef MachOObjCSelRefsSectionName = "__DATA,__objc_selrefs" ; |
| 39 | StringRef MachOSwift5ProtoSectionName = "__TEXT,__swift5_proto" ; |
| 40 | StringRef MachOSwift5ProtosSectionName = "__TEXT,__swift5_protos" ; |
| 41 | StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types" ; |
| 42 | StringRef MachOSwift5TypeRefSectionName = "__TEXT,__swift5_typeref" ; |
| 43 | StringRef MachOSwift5FieldMetadataSectionName = "__TEXT,__swift5_fieldmd" ; |
| 44 | StringRef MachOSwift5EntrySectionName = "__TEXT,__swift5_entry" ; |
| 45 | StringRef MachOTextTextSectionName = "__TEXT,__text" ; |
| 46 | StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss" ; |
| 47 | StringRef MachOThreadDataSectionName = "__DATA,__thread_data" ; |
| 48 | StringRef = "__DATA,__thread_vars" ; |
| 49 | StringRef MachOUnwindInfoSectionName = "__TEXT,__unwind_info" ; |
| 50 | |
| 51 | StringRef MachOInitSectionNames[22] = { |
| 52 | MachOModInitFuncSectionName, MachOObjCCatListSectionName, |
| 53 | MachOObjCCatList2SectionName, MachOObjCClassListSectionName, |
| 54 | MachOObjCClassNameSectionName, MachOObjCClassRefsSectionName, |
| 55 | MachOObjCConstSectionName, MachOObjCDataSectionName, |
| 56 | MachOObjCImageInfoSectionName, MachOObjCMethNameSectionName, |
| 57 | MachOObjCMethTypeSectionName, MachOObjCNLCatListSectionName, |
| 58 | MachOObjCNLClassListSectionName, MachOObjCProtoListSectionName, |
| 59 | MachOObjCProtoRefsSectionName, MachOObjCSelRefsSectionName, |
| 60 | MachOSwift5ProtoSectionName, MachOSwift5ProtosSectionName, |
| 61 | MachOSwift5TypesSectionName, MachOSwift5TypeRefSectionName, |
| 62 | MachOSwift5FieldMetadataSectionName, MachOSwift5EntrySectionName, |
| 63 | }; |
| 64 | |
| 65 | bool isMachOInitializerSection(StringRef SegName, StringRef SecName) { |
| 66 | for (auto &InitSection : MachOInitSectionNames) { |
| 67 | // Loop below assumes all MachO init sectios have a length-6 |
| 68 | // segment name. |
| 69 | assert(InitSection[6] == ',' && "Init section seg name has length != 6" ); |
| 70 | if (InitSection.starts_with(Prefix: SegName) && InitSection.substr(Start: 7) == SecName) |
| 71 | return true; |
| 72 | } |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | } // namespace orc |
| 77 | } // namespace llvm |
| 78 | |