diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 919a14b8bcf08..14c111ce9685c 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1394,6 +1394,7 @@ bool link(ArrayRef argsArr, llvm::raw_ostream &stdoutOS, syntheticSections.clear(); thunkMap.clear(); unprocessedLCLinkerOptions.clear(); + ObjCSelRefsHelper::cleanup(); firstTLVDataSection = nullptr; tar = nullptr; diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 1b3694528de1d..0afbbd478bb9f 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -806,10 +806,9 @@ void StubHelperSection::setUp() { dyldPrivate->used = true; } -ObjCSelRefsSection::ObjCSelRefsSection() - : SyntheticSection(segment_names::data, section_names::objcSelrefs) {} - -void ObjCSelRefsSection::initialize() { +llvm::DenseMap + ObjCSelRefsHelper::methnameToSelref; +void ObjCSelRefsHelper::initialize() { // Do not fold selrefs without ICF. if (config->icfLevel == ICFLevel::none) return; @@ -836,7 +835,9 @@ void ObjCSelRefsSection::initialize() { } } -ConcatInputSection *ObjCSelRefsSection::makeSelRef(StringRef methname) { +void ObjCSelRefsHelper::cleanup() { methnameToSelref.clear(); } + +ConcatInputSection *ObjCSelRefsHelper::makeSelRef(StringRef methname) { auto methnameOffset = in.objcMethnameSection->getStringOffset(methname).outSecOff; @@ -861,7 +862,7 @@ ConcatInputSection *ObjCSelRefsSection::makeSelRef(StringRef methname) { return objcSelref; } -ConcatInputSection *ObjCSelRefsSection::getSelRef(StringRef methname) { +ConcatInputSection *ObjCSelRefsHelper::getSelRef(StringRef methname) { auto it = methnameToSelref.find(CachedHashStringRef(methname)); if (it == methnameToSelref.end()) return nullptr; @@ -890,8 +891,8 @@ StringRef ObjCStubsSection::getMethname(Symbol *sym) { void ObjCStubsSection::addEntry(Symbol *sym) { StringRef methname = getMethname(sym); // We create a selref entry for each unique methname. - if (!in.objcSelRefs->getSelRef(methname)) - in.objcSelRefs->makeSelRef(methname); + if (!ObjCSelRefsHelper::getSelRef(methname)) + ObjCSelRefsHelper::makeSelRef(methname); auto stubSize = config->objcStubsMode == ObjCStubsMode::fast ? target->objcStubsFastSize @@ -940,7 +941,7 @@ void ObjCStubsSection::writeTo(uint8_t *buf) const { Defined *sym = symbols[i]; auto methname = getMethname(sym); - InputSection *selRef = in.objcSelRefs->getSelRef(methname); + InputSection *selRef = ObjCSelRefsHelper::getSelRef(methname); assert(selRef != nullptr && "no selref for methname"); auto selrefAddr = selRef->getVA(0); target->writeObjCMsgSendStub(buf + stubOffset, sym, in.objcStubs->addr, diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h index 6d85f0aea8e04..4586a4a0bf436 100644 --- a/lld/MachO/SyntheticSections.h +++ b/lld/MachO/SyntheticSections.h @@ -315,24 +315,16 @@ class StubHelperSection final : public SyntheticSection { Defined *dyldPrivate = nullptr; }; -class ObjCSelRefsSection final : public SyntheticSection { +class ObjCSelRefsHelper { public: - ObjCSelRefsSection(); - void initialize(); - - // This SyntheticSection does not do directly write data to the output, it is - // just a placeholder for easily creating SyntheticInputSection's which will - // be inserted into inputSections and handeled by the default writing - // mechanism. - uint64_t getSize() const override { return 0; } - bool isNeeded() const override { return false; } - void writeTo(uint8_t *buf) const override {} + static void initialize(); + static void cleanup(); - ConcatInputSection *getSelRef(StringRef methname); - ConcatInputSection *makeSelRef(StringRef methname); + static ConcatInputSection *getSelRef(StringRef methname); + static ConcatInputSection *makeSelRef(StringRef methname); private: - llvm::DenseMap + static llvm::DenseMap methnameToSelref; }; @@ -813,7 +805,6 @@ struct InStruct { LazyPointerSection *lazyPointers = nullptr; StubsSection *stubs = nullptr; StubHelperSection *stubHelper = nullptr; - ObjCSelRefsSection *objcSelRefs = nullptr; ObjCStubsSection *objcStubs = nullptr; UnwindInfoSection *unwindInfo = nullptr; ObjCImageInfoSection *objCImageInfo = nullptr; diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp index 8f335188e12c7..a18b5268fd42a 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -720,7 +720,7 @@ static void addNonWeakDefinition(const Defined *defined) { void Writer::scanSymbols() { TimeTraceScope timeScope("Scan symbols"); - in.objcSelRefs->initialize(); + ObjCSelRefsHelper::initialize(); for (Symbol *sym : symtab->getSymbols()) { if (auto *defined = dyn_cast(sym)) { if (!defined->isLive()) @@ -1359,7 +1359,6 @@ void macho::createSyntheticSections() { in.got = make(); in.tlvPointers = make(); in.stubs = make(); - in.objcSelRefs = make(); in.objcStubs = make(); in.unwindInfo = makeUnwindInfoSection(); in.objCImageInfo = make();