xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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 MachOObjCCatListSectionName = "__DATA,__objc_catlist";
24 StringRef MachOObjCCatList2SectionName = "__DATA,__objc_catlist2";
25 StringRef MachOObjCClassListSectionName = "__DATA,__objc_classlist";
26 StringRef MachOObjCClassNameSectionName = "__TEXT,__objc_classname";
27 StringRef MachOObjCClassRefsSectionName = "__DATA,__objc_classrefs";
28 StringRef MachOObjCConstSectionName = "__DATA,__objc_const";
29 StringRef MachOObjCDataSectionName = "__DATA,__objc_data";
30 StringRef MachOObjCImageInfoSectionName = "__DATA,__objc_imageinfo";
31 StringRef MachOObjCMethNameSectionName = "__TEXT,__objc_methname";
32 StringRef MachOObjCMethTypeSectionName = "__TEXT,__objc_methtype";
33 StringRef MachOObjCNLCatListSectionName = "__DATA,__objc_nlcatlist";
34 StringRef MachOObjCSelRefsSectionName = "__DATA,__objc_selrefs";
35 StringRef MachOSwift5ProtoSectionName = "__TEXT,__swift5_proto";
36 StringRef MachOSwift5ProtosSectionName = "__TEXT,__swift5_protos";
37 StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types";
38 StringRef MachOSwift5TypeRefSectionName = "__TEXT,__swift5_typeref";
39 StringRef MachOSwift5FieldMetadataSectionName = "__TEXT,__swift5_fieldmd";
40 StringRef MachOSwift5EntrySectionName = "__TEXT,__swift5_entry";
41 StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss";
42 StringRef MachOThreadDataSectionName = "__DATA,__thread_data";
43 StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars";
44 
45 StringRef MachOInitSectionNames[19] = {
46     MachOModInitFuncSectionName,   MachOObjCCatListSectionName,
47     MachOObjCCatList2SectionName,  MachOObjCClassListSectionName,
48     MachOObjCClassNameSectionName, MachOObjCClassRefsSectionName,
49     MachOObjCConstSectionName,     MachOObjCDataSectionName,
50     MachOObjCImageInfoSectionName, MachOObjCMethNameSectionName,
51     MachOObjCMethTypeSectionName,  MachOObjCNLCatListSectionName,
52     MachOObjCSelRefsSectionName,   MachOSwift5ProtoSectionName,
53     MachOSwift5ProtosSectionName,  MachOSwift5TypesSectionName,
54     MachOSwift5TypeRefSectionName, MachOSwift5FieldMetadataSectionName,
55     MachOSwift5EntrySectionName,
56 };
57 
58 StringRef ELFEHFrameSectionName = ".eh_frame";
59 StringRef ELFInitArrayFuncSectionName = ".init_array";
60 
61 StringRef ELFThreadBSSSectionName = ".tbss";
62 StringRef ELFThreadDataSectionName = ".tdata";
63 
64 bool isMachOInitializerSection(StringRef SegName, StringRef SecName) {
65   for (auto &InitSection : MachOInitSectionNames) {
66     // Loop below assumes all MachO init sectios have a length-6
67     // segment name.
68     assert(InitSection[6] == ',' && "Init section seg name has length != 6");
69     if (InitSection.starts_with(SegName) && InitSection.substr(7) == SecName)
70       return true;
71   }
72   return false;
73 }
74 
75 bool isMachOInitializerSection(StringRef QualifiedName) {
76   for (auto &InitSection : MachOInitSectionNames)
77     if (InitSection == QualifiedName)
78       return true;
79   return false;
80 }
81 
82 bool isELFInitializerSection(StringRef SecName) {
83   if (SecName.consume_front(ELFInitArrayFuncSectionName) &&
84       (SecName.empty() || SecName[0] == '.'))
85     return true;
86   return false;
87 }
88 
89 bool isCOFFInitializerSection(StringRef SecName) {
90   return SecName.startswith(".CRT");
91 }
92 
93 } // namespace orc
94 } // namespace llvm
95