Skip to content

Commit 470a599

Browse files
committed
[ORC] Move MachO object format details into their own header (NFC).
1 parent 53a8a7c commit 470a599

File tree

5 files changed

+141
-94
lines changed

5 files changed

+141
-94
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//===---- MachOObjectFormat.h - MachO format details for ORC ----*- C++ -*-===//
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+
#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_MACHOOBJECTFORMAT_H
14+
#define LLVM_EXECUTIONENGINE_ORC_SHARED_MACHOOBJECTFORMAT_H
15+
16+
#include "llvm/ADT/StringRef.h"
17+
18+
namespace llvm {
19+
namespace orc {
20+
21+
// FIXME: Move these to BinaryFormat?
22+
23+
// MachO section names.
24+
25+
extern StringRef MachODataCommonSectionName;
26+
extern StringRef MachODataDataSectionName;
27+
extern StringRef MachOEHFrameSectionName;
28+
extern StringRef MachOCompactUnwindInfoSectionName;
29+
extern StringRef MachOCStringSectionName;
30+
extern StringRef MachOModInitFuncSectionName;
31+
extern StringRef MachOObjCCatListSectionName;
32+
extern StringRef MachOObjCCatList2SectionName;
33+
extern StringRef MachOObjCClassListSectionName;
34+
extern StringRef MachOObjCClassNameSectionName;
35+
extern StringRef MachOObjCClassRefsSectionName;
36+
extern StringRef MachOObjCConstSectionName;
37+
extern StringRef MachOObjCDataSectionName;
38+
extern StringRef MachOObjCImageInfoSectionName;
39+
extern StringRef MachOObjCMethNameSectionName;
40+
extern StringRef MachOObjCMethTypeSectionName;
41+
extern StringRef MachOObjCNLCatListSectionName;
42+
extern StringRef MachOObjCNLClassListSectionName;
43+
extern StringRef MachOObjCProtoListSectionName;
44+
extern StringRef MachOObjCProtoRefsSectionName;
45+
extern StringRef MachOObjCSelRefsSectionName;
46+
extern StringRef MachOSwift5ProtoSectionName;
47+
extern StringRef MachOSwift5ProtosSectionName;
48+
extern StringRef MachOSwift5TypesSectionName;
49+
extern StringRef MachOSwift5TypeRefSectionName;
50+
extern StringRef MachOSwift5FieldMetadataSectionName;
51+
extern StringRef MachOSwift5EntrySectionName;
52+
extern StringRef MachOThreadBSSSectionName;
53+
extern StringRef MachOThreadDataSectionName;
54+
extern StringRef MachOThreadVarsSectionName;
55+
56+
extern StringRef MachOInitSectionNames[22];
57+
58+
bool isMachOInitializerSection(StringRef SegName, StringRef SecName);
59+
bool isMachOInitializerSection(StringRef QualifiedName);
60+
61+
} // end namespace orc
62+
} // end namespace llvm
63+
64+
#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_MACHOOBJECTFORMAT_H

llvm/include/llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,11 @@
1414
#define LLVM_EXECUTIONENGINE_ORC_SHARED_OBJECTFORMATS_H
1515

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h"
1718

1819
namespace llvm {
1920
namespace orc {
2021

21-
// MachO section names.
22-
23-
extern StringRef MachODataCommonSectionName;
24-
extern StringRef MachODataDataSectionName;
25-
extern StringRef MachOEHFrameSectionName;
26-
extern StringRef MachOCompactUnwindInfoSectionName;
27-
extern StringRef MachOCStringSectionName;
28-
extern StringRef MachOModInitFuncSectionName;
29-
extern StringRef MachOObjCCatListSectionName;
30-
extern StringRef MachOObjCCatList2SectionName;
31-
extern StringRef MachOObjCClassListSectionName;
32-
extern StringRef MachOObjCClassNameSectionName;
33-
extern StringRef MachOObjCClassRefsSectionName;
34-
extern StringRef MachOObjCConstSectionName;
35-
extern StringRef MachOObjCDataSectionName;
36-
extern StringRef MachOObjCImageInfoSectionName;
37-
extern StringRef MachOObjCMethNameSectionName;
38-
extern StringRef MachOObjCMethTypeSectionName;
39-
extern StringRef MachOObjCNLCatListSectionName;
40-
extern StringRef MachOObjCNLClassListSectionName;
41-
extern StringRef MachOObjCProtoListSectionName;
42-
extern StringRef MachOObjCProtoRefsSectionName;
43-
extern StringRef MachOObjCSelRefsSectionName;
44-
extern StringRef MachOSwift5ProtoSectionName;
45-
extern StringRef MachOSwift5ProtosSectionName;
46-
extern StringRef MachOSwift5TypesSectionName;
47-
extern StringRef MachOSwift5TypeRefSectionName;
48-
extern StringRef MachOSwift5FieldMetadataSectionName;
49-
extern StringRef MachOSwift5EntrySectionName;
50-
extern StringRef MachOThreadBSSSectionName;
51-
extern StringRef MachOThreadDataSectionName;
52-
extern StringRef MachOThreadVarsSectionName;
53-
54-
extern StringRef MachOInitSectionNames[22];
55-
5622
// ELF section names.
5723
extern StringRef ELFEHFrameSectionName;
5824

@@ -68,9 +34,6 @@ extern StringRef ELFInitSectionNames[3];
6834
extern StringRef ELFThreadBSSSectionName;
6935
extern StringRef ELFThreadDataSectionName;
7036

71-
bool isMachOInitializerSection(StringRef SegName, StringRef SecName);
72-
bool isMachOInitializerSection(StringRef QualifiedName);
73-
7437
bool isELFInitializerSection(StringRef SecName);
7538

7639
bool isCOFFInitializerSection(StringRef Name);

llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_llvm_component_library(LLVMOrcShared
22
AllocationActions.cpp
3+
MachOObjectFormat.cpp
34
ObjectFormats.cpp
45
OrcError.cpp
56
OrcRTBridge.cpp
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 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 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 MachOThreadBSSSectionName = "__DATA,__thread_bss";
46+
StringRef MachOThreadDataSectionName = "__DATA,__thread_data";
47+
StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars";
48+
49+
StringRef 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+
63+
bool isMachOInitializerSection(StringRef SegName, StringRef SecName) {
64+
for (auto &InitSection : MachOInitSectionNames) {
65+
// Loop below assumes all MachO init sectios have a length-6
66+
// segment name.
67+
assert(InitSection[6] == ',' && "Init section seg name has length != 6");
68+
if (InitSection.starts_with(SegName) && InitSection.substr(7) == SecName)
69+
return true;
70+
}
71+
return false;
72+
}
73+
74+
} // namespace orc
75+
} // namespace llvm

llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,6 @@
1515
namespace llvm {
1616
namespace orc {
1717

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 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 MachOThreadBSSSectionName = "__DATA,__thread_bss";
46-
StringRef MachOThreadDataSectionName = "__DATA,__thread_data";
47-
StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars";
48-
49-
StringRef 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-
6318
StringRef ELFEHFrameSectionName = ".eh_frame";
6419

6520
StringRef ELFInitArrayFuncSectionName = ".init_array";
@@ -78,17 +33,6 @@ StringRef ELFInitSectionNames[3]{
7833
StringRef ELFThreadBSSSectionName = ".tbss";
7934
StringRef ELFThreadDataSectionName = ".tdata";
8035

81-
bool 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(SegName) && InitSection.substr(7) == SecName)
87-
return true;
88-
}
89-
return false;
90-
}
91-
9236
bool isMachOInitializerSection(StringRef QualifiedName) {
9337
for (auto &InitSection : MachOInitSectionNames)
9438
if (InitSection == QualifiedName)

0 commit comments

Comments
 (0)