mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-24 06:10:12 +00:00
[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
This commit is contained in:
parent
7fe2063446
commit
465204d63a
@ -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
|
// emit in our STABS symbols, so we don't need to process & emit them
|
||||||
// ourselves.
|
// ourselves.
|
||||||
for (const InputSection *isec : obj->debugSections) {
|
for (const InputSection *isec : obj->debugSections) {
|
||||||
if (StringRef *s = StringSwitch<StringRef *>(isec->name)
|
if (StringRef *s =
|
||||||
.Case("__debug_info", &dObj->infoSection.Data)
|
StringSwitch<StringRef *>(isec->name)
|
||||||
.Case("__debug_abbrev", &dObj->abbrevSection)
|
.Case(section_names::debugInfo, &dObj->infoSection.Data)
|
||||||
.Case("__debug_str", &dObj->strSection)
|
.Case(section_names::debugAbbrev, &dObj->abbrevSection)
|
||||||
.Default(nullptr)) {
|
.Case(section_names::debugStr, &dObj->strSection)
|
||||||
|
.Default(nullptr)) {
|
||||||
*s = toStringRef(isec->data);
|
*s = toStringRef(isec->data);
|
||||||
hasDwarfInfo = true;
|
hasDwarfInfo = true;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ bool macho::isCodeSection(InputSection *isec) {
|
|||||||
|
|
||||||
if (isec->segname == segment_names::text)
|
if (isec->segname == segment_names::text)
|
||||||
return StringSwitch<bool>(isec->name)
|
return StringSwitch<bool>(isec->name)
|
||||||
.Cases("__textcoal_nt", "__StaticInit", true)
|
.Cases(section_names::textCoalNt, section_names::staticInit, true)
|
||||||
.Default(false);
|
.Default(false);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -78,30 +78,53 @@ extern std::vector<InputSection *> inputSections;
|
|||||||
|
|
||||||
namespace section_names {
|
namespace section_names {
|
||||||
|
|
||||||
constexpr const char pageZero[] = "__pagezero";
|
constexpr const char authGot[] = "__auth_got";
|
||||||
constexpr const char common[] = "__common";
|
constexpr const char authPtr[] = "__auth_ptr";
|
||||||
constexpr const char header[] = "__mach_header";
|
|
||||||
constexpr const char rebase[] = "__rebase";
|
|
||||||
constexpr const char binding[] = "__binding";
|
constexpr const char binding[] = "__binding";
|
||||||
constexpr const char weakBinding[] = "__weak_binding";
|
constexpr const char bitcodeBundle[] = "__bundle";
|
||||||
constexpr const char lazyBinding[] = "__lazy_binding";
|
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 export_[] = "__export";
|
||||||
constexpr const char functionStarts[] = "__func_starts";
|
constexpr const char functionStarts[] = "__func_starts";
|
||||||
constexpr const char symbolTable[] = "__symbol_table";
|
|
||||||
constexpr const char indirectSymbolTable[] = "__ind_sym_tab";
|
|
||||||
constexpr const char stringTable[] = "__string_table";
|
|
||||||
constexpr const char codeSignature[] = "__code_signature";
|
|
||||||
constexpr const char got[] = "__got";
|
constexpr const char got[] = "__got";
|
||||||
constexpr const char threadPtrs[] = "__thread_ptrs";
|
constexpr const char header[] = "__mach_header";
|
||||||
constexpr const char unwindInfo[] = "__unwind_info";
|
constexpr const char indirectSymbolTable[] = "__ind_sym_tab";
|
||||||
constexpr const char compactUnwind[] = "__compact_unwind";
|
constexpr const char const_[] = "__const";
|
||||||
constexpr const char ehFrame[] = "__eh_frame";
|
constexpr const char lazySymbolPtr[] = "__la_symbol_ptr";
|
||||||
constexpr const char text[] = "__text";
|
constexpr const char lazyBinding[] = "__lazy_binding";
|
||||||
constexpr const char stubs[] = "__stubs";
|
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 stubHelper[] = "__stub_helper";
|
constexpr const char stubHelper[] = "__stub_helper";
|
||||||
constexpr const char laSymbolPtr[] = "__la_symbol_ptr";
|
constexpr const char stubs[] = "__stubs";
|
||||||
constexpr const char data[] = "__data";
|
constexpr const char swift[] = "__swift";
|
||||||
constexpr const char bitcodeBundle[] = "__bundle";
|
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 weakBinding[] = "__weak_binding";
|
||||||
|
constexpr const char zeroFill[] = "__zerofill";
|
||||||
|
|
||||||
} // namespace section_names
|
} // namespace section_names
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "ObjC.h"
|
#include "ObjC.h"
|
||||||
#include "InputFiles.h"
|
#include "InputFiles.h"
|
||||||
|
#include "InputSection.h"
|
||||||
#include "OutputSegment.h"
|
#include "OutputSegment.h"
|
||||||
#include "Target.h"
|
#include "Target.h"
|
||||||
|
|
||||||
@ -31,8 +32,10 @@ template <class LP> static bool hasObjCSection(MemoryBufferRef mb) {
|
|||||||
StringRef sectname(sec.sectname,
|
StringRef sectname(sec.sectname,
|
||||||
strnlen(sec.sectname, sizeof(sec.sectname)));
|
strnlen(sec.sectname, sizeof(sec.sectname)));
|
||||||
StringRef segname(sec.segname, strnlen(sec.segname, sizeof(sec.segname)));
|
StringRef segname(sec.segname, strnlen(sec.segname, sizeof(sec.segname)));
|
||||||
if ((segname == segment_names::data && sectname == "__objc_catlist") ||
|
if ((segname == segment_names::data &&
|
||||||
(segname == segment_names::text && sectname == "__swift")) {
|
sectname == section_names::objcCatList) ||
|
||||||
|
(segname == segment_names::text &&
|
||||||
|
sectname == section_names::swift)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,17 @@ namespace macho {
|
|||||||
|
|
||||||
namespace segment_names {
|
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 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 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 llvm[] = "__LLVM";
|
||||||
|
constexpr const char pageZero[] = "__PAGEZERO";
|
||||||
|
constexpr const char textExec[] = "__TEXT_EXEC";
|
||||||
|
constexpr const char text[] = "__TEXT";
|
||||||
|
|
||||||
} // namespace segment_names
|
} // namespace segment_names
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ void WeakBindingSection::writeTo(uint8_t *buf) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StubsSection::StubsSection()
|
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;
|
flags = S_SYMBOL_STUBS | S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
|
||||||
// The stubs section comprises machine instructions, which are aligned to
|
// The stubs section comprises machine instructions, which are aligned to
|
||||||
// 4 bytes on the archs we care about.
|
// 4 bytes on the archs we care about.
|
||||||
@ -448,7 +448,7 @@ bool StubsSection::addEntry(Symbol *sym) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StubHelperSection::StubHelperSection()
|
StubHelperSection::StubHelperSection()
|
||||||
: SyntheticSection(segment_names::text, "__stub_helper") {
|
: SyntheticSection(segment_names::text, section_names::stubHelper) {
|
||||||
flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
|
flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS;
|
||||||
align = 4; // This section comprises machine instructions
|
align = 4; // This section comprises machine instructions
|
||||||
}
|
}
|
||||||
@ -488,7 +488,7 @@ void StubHelperSection::setup() {
|
|||||||
|
|
||||||
ImageLoaderCacheSection::ImageLoaderCacheSection() {
|
ImageLoaderCacheSection::ImageLoaderCacheSection() {
|
||||||
segname = segment_names::data;
|
segname = segment_names::data;
|
||||||
name = "__data";
|
name = section_names::data;
|
||||||
uint8_t *arr = bAlloc.Allocate<uint8_t>(target->wordSize);
|
uint8_t *arr = bAlloc.Allocate<uint8_t>(target->wordSize);
|
||||||
memset(arr, 0, target->wordSize);
|
memset(arr, 0, target->wordSize);
|
||||||
data = {arr, target->wordSize};
|
data = {arr, target->wordSize};
|
||||||
@ -496,7 +496,7 @@ ImageLoaderCacheSection::ImageLoaderCacheSection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LazyPointerSection::LazyPointerSection()
|
LazyPointerSection::LazyPointerSection()
|
||||||
: SyntheticSection(segment_names::data, "__la_symbol_ptr") {
|
: SyntheticSection(segment_names::data, section_names::lazySymbolPtr) {
|
||||||
align = target->wordSize;
|
align = target->wordSize;
|
||||||
flags = S_LAZY_SYMBOL_POINTERS;
|
flags = S_LAZY_SYMBOL_POINTERS;
|
||||||
}
|
}
|
||||||
|
@ -791,7 +791,7 @@ static int sectionOrder(OutputSection *osec) {
|
|||||||
return std::numeric_limits<int>::max();
|
return std::numeric_limits<int>::max();
|
||||||
default:
|
default:
|
||||||
return StringSwitch<int>(osec->name)
|
return StringSwitch<int>(osec->name)
|
||||||
.Case(section_names::laSymbolPtr, -2)
|
.Case(section_names::lazySymbolPtr, -2)
|
||||||
.Case(section_names::data, -1)
|
.Case(section_names::data, -1)
|
||||||
.Default(0);
|
.Default(0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user