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 MachOModInitFuncSectionName = "__DATA,__mod_init_func"; 23 StringRef MachOObjCClassListSectionName = "__DATA,__objc_classlist"; 24 StringRef MachOObjCImageInfoSectionName = "__DATA,__objc_imageinfo"; 25 StringRef MachOObjCSelRefsSectionName = "__DATA,__objc_selrefs"; 26 StringRef MachOSwift5ProtoSectionName = "__TEXT,__swift5_proto"; 27 StringRef MachOSwift5ProtosSectionName = "__TEXT,__swift5_protos"; 28 StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types"; 29 StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss"; 30 StringRef MachOThreadDataSectionName = "__DATA,__thread_data"; 31 StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars"; 32 33 StringRef MachOInitSectionNames[6] = { 34 MachOModInitFuncSectionName, MachOObjCSelRefsSectionName, 35 MachOObjCClassListSectionName, MachOSwift5ProtosSectionName, 36 MachOSwift5ProtoSectionName, MachOSwift5TypesSectionName}; 37 38 StringRef ELFEHFrameSectionName = ".eh_frame"; 39 StringRef ELFInitArrayFuncSectionName = ".init_array"; 40 41 StringRef ELFThreadBSSSectionName = ".tbss"; 42 StringRef ELFThreadDataSectionName = ".tdata"; 43 44 bool isMachOInitializerSection(StringRef SegName, StringRef SecName) { 45 for (auto &InitSection : MachOInitSectionNames) { 46 // Loop below assumes all MachO init sectios have a length-6 47 // segment name. 48 assert(InitSection[6] == ',' && "Init section seg name has length != 6"); 49 if (InitSection.starts_with(SegName) && InitSection.substr(7) == SecName) 50 return true; 51 } 52 return false; 53 } 54 55 bool isMachOInitializerSection(StringRef QualifiedName) { 56 for (auto &InitSection : MachOInitSectionNames) 57 if (InitSection == QualifiedName) 58 return true; 59 return false; 60 } 61 62 bool isELFInitializerSection(StringRef SecName) { 63 if (SecName.consume_front(ELFInitArrayFuncSectionName) && 64 (SecName.empty() || SecName[0] == '.')) 65 return true; 66 return false; 67 } 68 69 bool isCOFFInitializerSection(StringRef SecName) { 70 return SecName.startswith(".CRT"); 71 } 72 73 } // namespace orc 74 } // namespace llvm 75