From c5c05ffa4562223cae7db537ca7772afaeccd009 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Sun, 13 Jun 2021 19:43:36 -0400 Subject: [PATCH] [lld-macho][nfc] Represent the image loader cache with a ConcatInputSection We don't need to define any special behavior for this section, so creating a subclass for it is redundant. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D104199 --- lld/MachO/SyntheticSections.cpp | 9 --------- lld/MachO/SyntheticSections.h | 12 +----------- lld/MachO/Writer.cpp | 12 +++++++++++- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index f402ff6..5f2d446 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -477,15 +477,6 @@ void StubHelperSection::setup() { /*noDeadStrip=*/false); } -ImageLoaderCacheSection::ImageLoaderCacheSection() - : ConcatInputSection(segment_names::data, section_names::data) { - uint8_t *arr = bAlloc.Allocate(target->wordSize); - memset(arr, 0, target->wordSize); - data = {arr, target->wordSize}; - align = target->wordSize; - live = true; -} - LazyPointerSection::LazyPointerSection() : SyntheticSection(segment_names::data, section_names::lazySymbolPtr) { align = target->wordSize; diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h index bde3b3b..4e3ea69 100644 --- a/lld/MachO/SyntheticSections.h +++ b/lld/MachO/SyntheticSections.h @@ -326,16 +326,6 @@ public: Defined *dyldPrivate = nullptr; }; -// This section contains space for just a single word, and will be used by dyld -// to cache an address to the image loader it uses. Note that unlike the other -// synthetic sections, which are OutputSections, the ImageLoaderCacheSection is -// an InputSection that gets merged into the __data OutputSection. -class ImageLoaderCacheSection : public ConcatInputSection { -public: - ImageLoaderCacheSection(); - uint64_t getSize() const override { return target->wordSize; } -}; - // Note that this section may also be targeted by non-lazy bindings. In // particular, this happens when branch relocations target weak symbols. class LazyPointerSection : public SyntheticSection { @@ -600,8 +590,8 @@ struct InStruct { LazyPointerSection *lazyPointers = nullptr; StubsSection *stubs = nullptr; StubHelperSection *stubHelper = nullptr; - ImageLoaderCacheSection *imageLoaderCache = nullptr; UnwindInfoSection *unwindInfo = nullptr; + ConcatInputSection *imageLoaderCache = nullptr; }; extern InStruct in; diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp index 6626b52..40f27fa 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -1070,8 +1070,18 @@ void macho::createSyntheticSections() { in.lazyPointers = make(); in.stubs = make(); in.stubHelper = make(); - in.imageLoaderCache = make(); in.unwindInfo = makeUnwindInfoSection(); + + // This section contains space for just a single word, and will be used by + // dyld to cache an address to the image loader it uses. + ArrayRef data{bAlloc.Allocate(target->wordSize), + target->wordSize}; + in.imageLoaderCache = make( + segment_names::data, section_names::data, /*file=*/nullptr, data, + /*align=*/target->wordSize, /*flags=*/S_REGULAR); + // References from dyld are not visible to us, so ensure this section is + // always treated as live. + in.imageLoaderCache->live = true; } OutputSection *macho::firstTLVDataSection = nullptr; -- 2.7.4