Skip to content

Commit 465204d

Browse files
committed
[lld-macho][NFC] define more strings in section_names:: and segment_names::
As preparation for a subsequent diff that implements builtin section renaming, define more `constexpr` strings in namespaces `lld::macho::segment_names` and `lld::macho::section_names`, and use them to replace string literals. Differential Revision: https://reviews.llvm.org/D101393
1 parent 7fe2063 commit 465204d

File tree

7 files changed

+65
-35
lines changed

7 files changed

+65
-35
lines changed

lld/MachO/Dwarf.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) {
2626
// emit in our STABS symbols, so we don't need to process & emit them
2727
// ourselves.
2828
for (const InputSection *isec : obj->debugSections) {
29-
if (StringRef *s = StringSwitch<StringRef *>(isec->name)
30-
.Case("__debug_info", &dObj->infoSection.Data)
31-
.Case("__debug_abbrev", &dObj->abbrevSection)
32-
.Case("__debug_str", &dObj->strSection)
33-
.Default(nullptr)) {
29+
if (StringRef *s =
30+
StringSwitch<StringRef *>(isec->name)
31+
.Case(section_names::debugInfo, &dObj->infoSection.Data)
32+
.Case(section_names::debugAbbrev, &dObj->abbrevSection)
33+
.Case(section_names::debugStr, &dObj->strSection)
34+
.Default(nullptr)) {
3435
*s = toStringRef(isec->data);
3536
hasDwarfInfo = true;
3637
}

lld/MachO/InputSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bool macho::isCodeSection(InputSection *isec) {
101101

102102
if (isec->segname == segment_names::text)
103103
return StringSwitch<bool>(isec->name)
104-
.Cases("__textcoal_nt", "__StaticInit", true)
104+
.Cases(section_names::textCoalNt, section_names::staticInit, true)
105105
.Default(false);
106106

107107
return false;

lld/MachO/InputSection.h

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,53 @@ extern std::vector<InputSection *> inputSections;
7878

7979
namespace section_names {
8080

81-
constexpr const char pageZero[] = "__pagezero";
82-
constexpr const char common[] = "__common";
83-
constexpr const char header[] = "__mach_header";
84-
constexpr const char rebase[] = "__rebase";
81+
constexpr const char authGot[] = "__auth_got";
82+
constexpr const char authPtr[] = "__auth_ptr";
8583
constexpr const char binding[] = "__binding";
86-
constexpr const char weakBinding[] = "__weak_binding";
87-
constexpr const char lazyBinding[] = "__lazy_binding";
84+
constexpr const char bitcodeBundle[] = "__bundle";
85+
constexpr const char cfString[] = "__cfstring";
86+
constexpr const char codeSignature[] = "__code_signature";
87+
constexpr const char common[] = "__common";
88+
constexpr const char compactUnwind[] = "__compact_unwind";
89+
constexpr const char data[] = "__data";
90+
constexpr const char debugAbbrev[] = "__debug_abbrev";
91+
constexpr const char debugInfo[] = "__debug_info";
92+
constexpr const char debugStr[] = "__debug_str";
93+
constexpr const char ehFrame[] = "__eh_frame";
8894
constexpr const char export_[] = "__export";
8995
constexpr const char functionStarts[] = "__func_starts";
90-
constexpr const char symbolTable[] = "__symbol_table";
96+
constexpr const char got[] = "__got";
97+
constexpr const char header[] = "__mach_header";
9198
constexpr const char indirectSymbolTable[] = "__ind_sym_tab";
99+
constexpr const char const_[] = "__const";
100+
constexpr const char lazySymbolPtr[] = "__la_symbol_ptr";
101+
constexpr const char lazyBinding[] = "__lazy_binding";
102+
constexpr const char moduleInitFunc[] = "__mod_init_func";
103+
constexpr const char moduleTermFunc[] = "__mod_term_func";
104+
constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr";
105+
constexpr const char objcCatList[] = "__objc_catlist";
106+
constexpr const char objcClassList[] = "__objc_classlist";
107+
constexpr const char objcConst[] = "__objc_const";
108+
constexpr const char objcImageInfo[] = "__objc_imageinfo";
109+
constexpr const char objcNonLazyCatList[] = "__objc_nlcatlist";
110+
constexpr const char objcNonLazyClassList[] = "__objc_nlclslist";
111+
constexpr const char objcProtoList[] = "__objc_protolist";
112+
constexpr const char pageZero[] = "__pagezero";
113+
constexpr const char pointers[] = "__pointers";
114+
constexpr const char rebase[] = "__rebase";
115+
constexpr const char staticInit[] = "__StaticInit";
92116
constexpr const char stringTable[] = "__string_table";
93-
constexpr const char codeSignature[] = "__code_signature";
94-
constexpr const char got[] = "__got";
117+
constexpr const char stubHelper[] = "__stub_helper";
118+
constexpr const char stubs[] = "__stubs";
119+
constexpr const char swift[] = "__swift";
120+
constexpr const char symbolTable[] = "__symbol_table";
121+
constexpr const char textCoalNt[] = "__textcoal_nt";
122+
constexpr const char text[] = "__text";
95123
constexpr const char threadPtrs[] = "__thread_ptrs";
124+
constexpr const char threadVars[] = "__thread_vars";
96125
constexpr const char unwindInfo[] = "__unwind_info";
97-
constexpr const char compactUnwind[] = "__compact_unwind";
98-
constexpr const char ehFrame[] = "__eh_frame";
99-
constexpr const char text[] = "__text";
100-
constexpr const char stubs[] = "__stubs";
101-
constexpr const char stubHelper[] = "__stub_helper";
102-
constexpr const char laSymbolPtr[] = "__la_symbol_ptr";
103-
constexpr const char data[] = "__data";
104-
constexpr const char bitcodeBundle[] = "__bundle";
126+
constexpr const char weakBinding[] = "__weak_binding";
127+
constexpr const char zeroFill[] = "__zerofill";
105128

106129
} // namespace section_names
107130

lld/MachO/ObjC.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "ObjC.h"
1010
#include "InputFiles.h"
11+
#include "InputSection.h"
1112
#include "OutputSegment.h"
1213
#include "Target.h"
1314

@@ -31,8 +32,10 @@ template <class LP> static bool hasObjCSection(MemoryBufferRef mb) {
3132
StringRef sectname(sec.sectname,
3233
strnlen(sec.sectname, sizeof(sec.sectname)));
3334
StringRef segname(sec.segname, strnlen(sec.segname, sizeof(sec.segname)));
34-
if ((segname == segment_names::data && sectname == "__objc_catlist") ||
35-
(segname == segment_names::text && sectname == "__swift")) {
35+
if ((segname == segment_names::data &&
36+
sectname == section_names::objcCatList) ||
37+
(segname == segment_names::text &&
38+
sectname == section_names::swift)) {
3639
return true;
3740
}
3841
}

lld/MachO/OutputSegment.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ namespace macho {
1717

1818
namespace segment_names {
1919

20-
constexpr const char pageZero[] = "__PAGEZERO";
21-
constexpr const char text[] = "__TEXT";
22-
constexpr const char data[] = "__DATA";
23-
constexpr const char linkEdit[] = "__LINKEDIT";
2420
constexpr const char dataConst[] = "__DATA_CONST";
25-
constexpr const char ld[] = "__LD"; // output only with -r
21+
constexpr const char dataDirty[] = "__DATA_DIRTY";
22+
constexpr const char data[] = "__DATA";
2623
constexpr const char dwarf[] = "__DWARF";
24+
constexpr const char import[] = "__IMPORT";
25+
constexpr const char ld[] = "__LD"; // output only with -r
26+
constexpr const char linkEdit[] = "__LINKEDIT";
2727
constexpr const char llvm[] = "__LLVM";
28+
constexpr const char pageZero[] = "__PAGEZERO";
29+
constexpr const char textExec[] = "__TEXT_EXEC";
30+
constexpr const char text[] = "__TEXT";
2831

2932
} // namespace segment_names
3033

lld/MachO/SyntheticSections.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ void WeakBindingSection::writeTo(uint8_t *buf) const {
420420
}
421421

422422
StubsSection::StubsSection()
423-
: SyntheticSection(segment_names::text, "__stubs") {
423+
: SyntheticSection(segment_names::text, section_names::stubs) {
424424
flags = S_SYMBOL_STUBS | S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
425425
// The stubs section comprises machine instructions, which are aligned to
426426
// 4 bytes on the archs we care about.
@@ -448,7 +448,7 @@ bool StubsSection::addEntry(Symbol *sym) {
448448
}
449449

450450
StubHelperSection::StubHelperSection()
451-
: SyntheticSection(segment_names::text, "__stub_helper") {
451+
: SyntheticSection(segment_names::text, section_names::stubHelper) {
452452
flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
453453
align = 4; // This section comprises machine instructions
454454
}
@@ -488,15 +488,15 @@ void StubHelperSection::setup() {
488488

489489
ImageLoaderCacheSection::ImageLoaderCacheSection() {
490490
segname = segment_names::data;
491-
name = "__data";
491+
name = section_names::data;
492492
uint8_t *arr = bAlloc.Allocate<uint8_t>(target->wordSize);
493493
memset(arr, 0, target->wordSize);
494494
data = {arr, target->wordSize};
495495
align = target->wordSize;
496496
}
497497

498498
LazyPointerSection::LazyPointerSection()
499-
: SyntheticSection(segment_names::data, "__la_symbol_ptr") {
499+
: SyntheticSection(segment_names::data, section_names::lazySymbolPtr) {
500500
align = target->wordSize;
501501
flags = S_LAZY_SYMBOL_POINTERS;
502502
}

lld/MachO/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ static int sectionOrder(OutputSection *osec) {
791791
return std::numeric_limits<int>::max();
792792
default:
793793
return StringSwitch<int>(osec->name)
794-
.Case(section_names::laSymbolPtr, -2)
794+
.Case(section_names::lazySymbolPtr, -2)
795795
.Case(section_names::data, -1)
796796
.Default(0);
797797
}

0 commit comments

Comments
 (0)