From 465204d63a71402ac412e444ba03bbdbbd17c667 Mon Sep 17 00:00:00 2001 From: Greg McGary Date: Tue, 27 Apr 2021 12:22:44 -0700 Subject: [PATCH] [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 --- lld/MachO/Dwarf.cpp | 11 ++++---- lld/MachO/InputSection.cpp | 2 +- lld/MachO/InputSection.h | 57 +++++++++++++++++++++++++++++------------ lld/MachO/ObjC.cpp | 7 +++-- lld/MachO/OutputSegment.h | 13 ++++++---- lld/MachO/SyntheticSections.cpp | 8 +++--- lld/MachO/Writer.cpp | 2 +- 7 files changed, 65 insertions(+), 35 deletions(-) diff --git a/lld/MachO/Dwarf.cpp b/lld/MachO/Dwarf.cpp index c69b1a6e..29b39dd 100644 --- a/lld/MachO/Dwarf.cpp +++ b/lld/MachO/Dwarf.cpp @@ -26,11 +26,12 @@ std::unique_ptr 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(isec->name) - .Case("__debug_info", &dObj->infoSection.Data) - .Case("__debug_abbrev", &dObj->abbrevSection) - .Case("__debug_str", &dObj->strSection) - .Default(nullptr)) { + if (StringRef *s = + StringSwitch(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 8d9113b..50f2732 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(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 de76a01..04dee3bf 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -78,30 +78,53 @@ extern std::vector 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 8fd1628..8a748ce 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 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 1db3f0a..5593fb6 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 387bfc2..4ea3091 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(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 1298baa..ca46eec 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -791,7 +791,7 @@ static int sectionOrder(OutputSection *osec) { return std::numeric_limits::max(); default: return StringSwitch(osec->name) - .Case(section_names::laSymbolPtr, -2) + .Case(section_names::lazySymbolPtr, -2) .Case(section_names::data, -1) .Default(0); } -- 2.7.4