1 //===---------- ObjectFormats.cpp - Object 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 object format details. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.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 MachOCompactUnwindInfoSectionName = "__TEXT,__unwind_info"; 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 MachOObjCSelRefsSectionName = "__DATA,__objc_selrefs"; 36 StringRef MachOSwift5ProtoSectionName = "__TEXT,__swift5_proto"; 37 StringRef MachOSwift5ProtosSectionName = "__TEXT,__swift5_protos"; 38 StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types"; 39 StringRef MachOSwift5TypeRefSectionName = "__TEXT,__swift5_typeref"; 40 StringRef MachOSwift5FieldMetadataSectionName = "__TEXT,__swift5_fieldmd"; 41 StringRef MachOSwift5EntrySectionName = "__TEXT,__swift5_entry"; 42 StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss"; 43 StringRef MachOThreadDataSectionName = "__DATA,__thread_data"; 44 StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars"; 45 46 StringRef MachOInitSectionNames[19] = { 47 MachOModInitFuncSectionName, MachOObjCCatListSectionName, 48 MachOObjCCatList2SectionName, MachOObjCClassListSectionName, 49 MachOObjCClassNameSectionName, MachOObjCClassRefsSectionName, 50 MachOObjCConstSectionName, MachOObjCDataSectionName, 51 MachOObjCImageInfoSectionName, MachOObjCMethNameSectionName, 52 MachOObjCMethTypeSectionName, MachOObjCNLCatListSectionName, 53 MachOObjCSelRefsSectionName, MachOSwift5ProtoSectionName, 54 MachOSwift5ProtosSectionName, MachOSwift5TypesSectionName, 55 MachOSwift5TypeRefSectionName, MachOSwift5FieldMetadataSectionName, 56 MachOSwift5EntrySectionName, 57 }; 58 59 StringRef ELFEHFrameSectionName = ".eh_frame"; 60 61 StringRef ELFInitArrayFuncSectionName = ".init_array"; 62 StringRef ELFInitFuncSectionName = ".init"; 63 StringRef ELFFiniArrayFuncSectionName = ".fini_array"; 64 StringRef ELFFiniFuncSectionName = ".fini"; 65 StringRef ELFCtorArrayFuncSectionName = ".ctors"; 66 StringRef ELFDtorArrayFuncSectionName = ".dtors"; 67 68 StringRef ELFInitSectionNames[3]{ 69 ELFInitArrayFuncSectionName, 70 ELFInitFuncSectionName, 71 ELFCtorArrayFuncSectionName, 72 }; 73 74 StringRef ELFThreadBSSSectionName = ".tbss"; 75 StringRef ELFThreadDataSectionName = ".tdata"; 76 77 bool isMachOInitializerSection(StringRef SegName, StringRef SecName) { 78 for (auto &InitSection : MachOInitSectionNames) { 79 // Loop below assumes all MachO init sectios have a length-6 80 // segment name. 81 assert(InitSection[6] == ',' && "Init section seg name has length != 6"); 82 if (InitSection.starts_with(SegName) && InitSection.substr(7) == SecName) 83 return true; 84 } 85 return false; 86 } 87 88 bool isMachOInitializerSection(StringRef QualifiedName) { 89 for (auto &InitSection : MachOInitSectionNames) 90 if (InitSection == QualifiedName) 91 return true; 92 return false; 93 } 94 95 bool isELFInitializerSection(StringRef SecName) { 96 for (StringRef InitSection : ELFInitSectionNames) { 97 StringRef Name = SecName; 98 if (Name.consume_front(InitSection) && (Name.empty() || Name[0] == '.')) 99 return true; 100 } 101 return false; 102 } 103 104 bool isCOFFInitializerSection(StringRef SecName) { 105 return SecName.starts_with(".CRT"); 106 } 107 108 } // namespace orc 109 } // namespace llvm 110