[lld-macho][NFC] define more strings in section_names:: and segment_names::
authorGreg McGary <gkm@fb.com>
Tue, 27 Apr 2021 19:22:44 +0000 (12:22 -0700)
committerGreg McGary <gkm@fb.com>
Wed, 28 Apr 2021 00:48:45 +0000 (17:48 -0700)
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
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/ObjC.cpp
lld/MachO/OutputSegment.h
lld/MachO/SyntheticSections.cpp
lld/MachO/Writer.cpp

index c69b1a6..29b39dd 100644 (file)
@@ -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;
     }
index 8d9113b..50f2732 100644 (file)
@@ -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;
index de76a01..04dee3b 100644 (file)
@@ -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
 
index 8fd1628..8a748ce 100644 (file)
@@ -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;
       }
     }
index 1db3f0a..5593fb6 100644 (file)
@@ -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
 
index 387bfc2..4ea3091 100644 (file)
@@ -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;
 }
index 1298baa..ca46eec 100644 (file)
@@ -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);
     }