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
15namespace llvm {
16namespace orc {
17
18StringRef MachODataCommonSectionName = "__DATA,__common";
19StringRef MachODataDataSectionName = "__DATA,__data";
20StringRef MachOEHFrameSectionName = "__TEXT,__eh_frame";
21StringRef MachOCompactUnwindInfoSectionName = "__TEXT,__unwind_info";
22StringRef MachOCStringSectionName = "__TEXT,__cstring";
23StringRef MachOModInitFuncSectionName = "__DATA,__mod_init_func";
24StringRef MachOObjCCatListSectionName = "__DATA,__objc_catlist";
25StringRef MachOObjCCatList2SectionName = "__DATA,__objc_catlist2";
26StringRef MachOObjCClassListSectionName = "__DATA,__objc_classlist";
27StringRef MachOObjCClassNameSectionName = "__TEXT,__objc_classname";
28StringRef MachOObjCClassRefsSectionName = "__DATA,__objc_classrefs";
29StringRef MachOObjCConstSectionName = "__DATA,__objc_const";
30StringRef MachOObjCDataSectionName = "__DATA,__objc_data";
31StringRef MachOObjCImageInfoSectionName = "__DATA,__objc_imageinfo";
32StringRef MachOObjCMethNameSectionName = "__TEXT,__objc_methname";
33StringRef MachOObjCMethTypeSectionName = "__TEXT,__objc_methtype";
34StringRef MachOObjCNLCatListSectionName = "__DATA,__objc_nlcatlist";
35StringRef MachOObjCNLClassListSectionName = "__DATA,__objc_nlclslist";
36StringRef MachOObjCProtoListSectionName = "__DATA,__objc_protolist";
37StringRef MachOObjCProtoRefsSectionName = "__DATA,__objc_protorefs";
38StringRef MachOObjCSelRefsSectionName = "__DATA,__objc_selrefs";
39StringRef MachOSwift5ProtoSectionName = "__TEXT,__swift5_proto";
40StringRef MachOSwift5ProtosSectionName = "__TEXT,__swift5_protos";
41StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types";
42StringRef MachOSwift5TypeRefSectionName = "__TEXT,__swift5_typeref";
43StringRef MachOSwift5FieldMetadataSectionName = "__TEXT,__swift5_fieldmd";
44StringRef MachOSwift5EntrySectionName = "__TEXT,__swift5_entry";
45StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss";
46StringRef MachOThreadDataSectionName = "__DATA,__thread_data";
47StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars";
48
49StringRef MachOInitSectionNames[22] = {
50 MachOModInitFuncSectionName, MachOObjCCatListSectionName,
51 MachOObjCCatList2SectionName, MachOObjCClassListSectionName,
52 MachOObjCClassNameSectionName, MachOObjCClassRefsSectionName,
53 MachOObjCConstSectionName, MachOObjCDataSectionName,
54 MachOObjCImageInfoSectionName, MachOObjCMethNameSectionName,
55 MachOObjCMethTypeSectionName, MachOObjCNLCatListSectionName,
56 MachOObjCNLClassListSectionName, MachOObjCProtoListSectionName,
57 MachOObjCProtoRefsSectionName, MachOObjCSelRefsSectionName,
58 MachOSwift5ProtoSectionName, MachOSwift5ProtosSectionName,
59 MachOSwift5TypesSectionName, MachOSwift5TypeRefSectionName,
60 MachOSwift5FieldMetadataSectionName, MachOSwift5EntrySectionName,
61};
62
63StringRef ELFEHFrameSectionName = ".eh_frame";
64
65StringRef ELFInitArrayFuncSectionName = ".init_array";
66StringRef ELFInitFuncSectionName = ".init";
67StringRef ELFFiniArrayFuncSectionName = ".fini_array";
68StringRef ELFFiniFuncSectionName = ".fini";
69StringRef ELFCtorArrayFuncSectionName = ".ctors";
70StringRef ELFDtorArrayFuncSectionName = ".dtors";
71
72StringRef ELFInitSectionNames[3]{
73 ELFInitArrayFuncSectionName,
74 ELFInitFuncSectionName,
75 ELFCtorArrayFuncSectionName,
76};
77
78StringRef ELFThreadBSSSectionName = ".tbss";
79StringRef ELFThreadDataSectionName = ".tdata";
80
81bool isMachOInitializerSection(StringRef SegName, StringRef SecName) {
82 for (auto &InitSection : MachOInitSectionNames) {
83 // Loop below assumes all MachO init sectios have a length-6
84 // segment name.
85 assert(InitSection[6] == ',' && "Init section seg name has length != 6");
86 if (InitSection.starts_with(Prefix: SegName) && InitSection.substr(Start: 7) == SecName)
87 return true;
88 }
89 return false;
90}
91
92bool isMachOInitializerSection(StringRef QualifiedName) {
93 for (auto &InitSection : MachOInitSectionNames)
94 if (InitSection == QualifiedName)
95 return true;
96 return false;
97}
98
99bool isELFInitializerSection(StringRef SecName) {
100 for (StringRef InitSection : ELFInitSectionNames) {
101 StringRef Name = SecName;
102 if (Name.consume_front(Prefix: InitSection) && (Name.empty() || Name[0] == '.'))
103 return true;
104 }
105 return false;
106}
107
108bool isCOFFInitializerSection(StringRef SecName) {
109 return SecName.starts_with(Prefix: ".CRT");
110}
111
112} // namespace orc
113} // namespace llvm
114