[lld] 465204d - [lld-macho][NFC] define more strings in section_names:: and segment_names::
Greg McGary via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 27 17:49:40 PDT 2021
Author: Greg McGary
Date: 2021-04-27T17:48:45-07:00
New Revision: 465204d63a71402ac412e444ba03bbdbbd17c667
URL: https://github.com/llvm/llvm-project/commit/465204d63a71402ac412e444ba03bbdbbd17c667
DIFF: https://github.com/llvm/llvm-project/commit/465204d63a71402ac412e444ba03bbdbbd17c667.diff
LOG: [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
Added:
Modified:
lld/MachO/Dwarf.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/ObjC.cpp
lld/MachO/OutputSegment.h
lld/MachO/SyntheticSections.cpp
lld/MachO/Writer.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Dwarf.cpp b/lld/MachO/Dwarf.cpp
index c69b1a6ea70f..29b39ddf6416 100644
--- a/lld/MachO/Dwarf.cpp
+++ b/lld/MachO/Dwarf.cpp
@@ -26,11 +26,12 @@ std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) {
// emit in our STABS symbols, so we don't need to process & emit them
// ourselves.
for (const InputSection *isec : obj->debugSections) {
- if (StringRef *s = StringSwitch<StringRef *>(isec->name)
- .Case("__debug_info", &dObj->infoSection.Data)
- .Case("__debug_abbrev", &dObj->abbrevSection)
- .Case("__debug_str", &dObj->strSection)
- .Default(nullptr)) {
+ if (StringRef *s =
+ StringSwitch<StringRef *>(isec->name)
+ .Case(section_names::debugInfo, &dObj->infoSection.Data)
+ .Case(section_names::debugAbbrev, &dObj->abbrevSection)
+ .Case(section_names::debugStr, &dObj->strSection)
+ .Default(nullptr)) {
*s = toStringRef(isec->data);
hasDwarfInfo = true;
}
diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 8d9113b2d5bf..50f2732c4c9b 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -101,7 +101,7 @@ bool macho::isCodeSection(InputSection *isec) {
if (isec->segname == segment_names::text)
return StringSwitch<bool>(isec->name)
- .Cases("__textcoal_nt", "__StaticInit", true)
+ .Cases(section_names::textCoalNt, section_names::staticInit, true)
.Default(false);
return false;
diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index de76a0166884..04dee3bf17af 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -78,30 +78,53 @@ extern std::vector<InputSection *> inputSections;
namespace section_names {
-constexpr const char pageZero[] = "__pagezero";
-constexpr const char common[] = "__common";
-constexpr const char header[] = "__mach_header";
-constexpr const char rebase[] = "__rebase";
+constexpr const char authGot[] = "__auth_got";
+constexpr const char authPtr[] = "__auth_ptr";
constexpr const char binding[] = "__binding";
-constexpr const char weakBinding[] = "__weak_binding";
-constexpr const char lazyBinding[] = "__lazy_binding";
+constexpr const char bitcodeBundle[] = "__bundle";
+constexpr const char cfString[] = "__cfstring";
+constexpr const char codeSignature[] = "__code_signature";
+constexpr const char common[] = "__common";
+constexpr const char compactUnwind[] = "__compact_unwind";
+constexpr const char data[] = "__data";
+constexpr const char debugAbbrev[] = "__debug_abbrev";
+constexpr const char debugInfo[] = "__debug_info";
+constexpr const char debugStr[] = "__debug_str";
+constexpr const char ehFrame[] = "__eh_frame";
constexpr const char export_[] = "__export";
constexpr const char functionStarts[] = "__func_starts";
-constexpr const char symbolTable[] = "__symbol_table";
+constexpr const char got[] = "__got";
+constexpr const char header[] = "__mach_header";
constexpr const char indirectSymbolTable[] = "__ind_sym_tab";
+constexpr const char const_[] = "__const";
+constexpr const char lazySymbolPtr[] = "__la_symbol_ptr";
+constexpr const char lazyBinding[] = "__lazy_binding";
+constexpr const char moduleInitFunc[] = "__mod_init_func";
+constexpr const char moduleTermFunc[] = "__mod_term_func";
+constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr";
+constexpr const char objcCatList[] = "__objc_catlist";
+constexpr const char objcClassList[] = "__objc_classlist";
+constexpr const char objcConst[] = "__objc_const";
+constexpr const char objcImageInfo[] = "__objc_imageinfo";
+constexpr const char objcNonLazyCatList[] = "__objc_nlcatlist";
+constexpr const char objcNonLazyClassList[] = "__objc_nlclslist";
+constexpr const char objcProtoList[] = "__objc_protolist";
+constexpr const char pageZero[] = "__pagezero";
+constexpr const char pointers[] = "__pointers";
+constexpr const char rebase[] = "__rebase";
+constexpr const char staticInit[] = "__StaticInit";
constexpr const char stringTable[] = "__string_table";
-constexpr const char codeSignature[] = "__code_signature";
-constexpr const char got[] = "__got";
+constexpr const char stubHelper[] = "__stub_helper";
+constexpr const char stubs[] = "__stubs";
+constexpr const char swift[] = "__swift";
+constexpr const char symbolTable[] = "__symbol_table";
+constexpr const char textCoalNt[] = "__textcoal_nt";
+constexpr const char text[] = "__text";
constexpr const char threadPtrs[] = "__thread_ptrs";
+constexpr const char threadVars[] = "__thread_vars";
constexpr const char unwindInfo[] = "__unwind_info";
-constexpr const char compactUnwind[] = "__compact_unwind";
-constexpr const char ehFrame[] = "__eh_frame";
-constexpr const char text[] = "__text";
-constexpr const char stubs[] = "__stubs";
-constexpr const char stubHelper[] = "__stub_helper";
-constexpr const char laSymbolPtr[] = "__la_symbol_ptr";
-constexpr const char data[] = "__data";
-constexpr const char bitcodeBundle[] = "__bundle";
+constexpr const char weakBinding[] = "__weak_binding";
+constexpr const char zeroFill[] = "__zerofill";
} // namespace section_names
diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp
index 8fd1628435c4..8a748ceef6ab 100644
--- a/lld/MachO/ObjC.cpp
+++ b/lld/MachO/ObjC.cpp
@@ -8,6 +8,7 @@
#include "ObjC.h"
#include "InputFiles.h"
+#include "InputSection.h"
#include "OutputSegment.h"
#include "Target.h"
@@ -31,8 +32,10 @@ template <class LP> static bool hasObjCSection(MemoryBufferRef mb) {
StringRef sectname(sec.sectname,
strnlen(sec.sectname, sizeof(sec.sectname)));
StringRef segname(sec.segname, strnlen(sec.segname, sizeof(sec.segname)));
- if ((segname == segment_names::data && sectname == "__objc_catlist") ||
- (segname == segment_names::text && sectname == "__swift")) {
+ if ((segname == segment_names::data &&
+ sectname == section_names::objcCatList) ||
+ (segname == segment_names::text &&
+ sectname == section_names::swift)) {
return true;
}
}
diff --git a/lld/MachO/OutputSegment.h b/lld/MachO/OutputSegment.h
index 1db3f0ac79a3..5593fb62e605 100644
--- a/lld/MachO/OutputSegment.h
+++ b/lld/MachO/OutputSegment.h
@@ -17,14 +17,17 @@ namespace macho {
namespace segment_names {
-constexpr const char pageZero[] = "__PAGEZERO";
-constexpr const char text[] = "__TEXT";
-constexpr const char data[] = "__DATA";
-constexpr const char linkEdit[] = "__LINKEDIT";
constexpr const char dataConst[] = "__DATA_CONST";
-constexpr const char ld[] = "__LD"; // output only with -r
+constexpr const char dataDirty[] = "__DATA_DIRTY";
+constexpr const char data[] = "__DATA";
constexpr const char dwarf[] = "__DWARF";
+constexpr const char import[] = "__IMPORT";
+constexpr const char ld[] = "__LD"; // output only with -r
+constexpr const char linkEdit[] = "__LINKEDIT";
constexpr const char llvm[] = "__LLVM";
+constexpr const char pageZero[] = "__PAGEZERO";
+constexpr const char textExec[] = "__TEXT_EXEC";
+constexpr const char text[] = "__TEXT";
} // namespace segment_names
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 387bfc2ca462..4ea30913ab68 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -420,7 +420,7 @@ void WeakBindingSection::writeTo(uint8_t *buf) const {
}
StubsSection::StubsSection()
- : SyntheticSection(segment_names::text, "__stubs") {
+ : SyntheticSection(segment_names::text, section_names::stubs) {
flags = S_SYMBOL_STUBS | S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
// The stubs section comprises machine instructions, which are aligned to
// 4 bytes on the archs we care about.
@@ -448,7 +448,7 @@ bool StubsSection::addEntry(Symbol *sym) {
}
StubHelperSection::StubHelperSection()
- : SyntheticSection(segment_names::text, "__stub_helper") {
+ : SyntheticSection(segment_names::text, section_names::stubHelper) {
flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
align = 4; // This section comprises machine instructions
}
@@ -488,7 +488,7 @@ void StubHelperSection::setup() {
ImageLoaderCacheSection::ImageLoaderCacheSection() {
segname = segment_names::data;
- name = "__data";
+ name = section_names::data;
uint8_t *arr = bAlloc.Allocate<uint8_t>(target->wordSize);
memset(arr, 0, target->wordSize);
data = {arr, target->wordSize};
@@ -496,7 +496,7 @@ ImageLoaderCacheSection::ImageLoaderCacheSection() {
}
LazyPointerSection::LazyPointerSection()
- : SyntheticSection(segment_names::data, "__la_symbol_ptr") {
+ : SyntheticSection(segment_names::data, section_names::lazySymbolPtr) {
align = target->wordSize;
flags = S_LAZY_SYMBOL_POINTERS;
}
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 1298baadd7cb..ca46eecec162 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -791,7 +791,7 @@ static int sectionOrder(OutputSection *osec) {
return std::numeric_limits<int>::max();
default:
return StringSwitch<int>(osec->name)
- .Case(section_names::laSymbolPtr, -2)
+ .Case(section_names::lazySymbolPtr, -2)
.Case(section_names::data, -1)
.Default(0);
}
More information about the llvm-commits
mailing list