[PATCH] D104199: [lld-macho][nfc] Represent the image loader cache with a ConcatInputSection

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 13 16:52:32 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc5c05ffa4562: [lld-macho][nfc] Represent the image loader cache with a ConcatInputSection (authored by int3).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104199/new/

https://reviews.llvm.org/D104199

Files:
  lld/MachO/SyntheticSections.cpp
  lld/MachO/SyntheticSections.h
  lld/MachO/Writer.cpp


Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -1070,8 +1070,18 @@
   in.lazyPointers = make<LazyPointerSection>();
   in.stubs = make<StubsSection>();
   in.stubHelper = make<StubHelperSection>();
-  in.imageLoaderCache = make<ImageLoaderCacheSection>();
   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<uint8_t> data{bAlloc.Allocate<uint8_t>(target->wordSize),
+                         target->wordSize};
+  in.imageLoaderCache = make<ConcatInputSection>(
+      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;
Index: lld/MachO/SyntheticSections.h
===================================================================
--- lld/MachO/SyntheticSections.h
+++ lld/MachO/SyntheticSections.h
@@ -326,16 +326,6 @@
   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 @@
   LazyPointerSection *lazyPointers = nullptr;
   StubsSection *stubs = nullptr;
   StubHelperSection *stubHelper = nullptr;
-  ImageLoaderCacheSection *imageLoaderCache = nullptr;
   UnwindInfoSection *unwindInfo = nullptr;
+  ConcatInputSection *imageLoaderCache = nullptr;
 };
 
 extern InStruct in;
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -477,15 +477,6 @@
                     /*noDeadStrip=*/false);
 }
 
-ImageLoaderCacheSection::ImageLoaderCacheSection()
-    : ConcatInputSection(segment_names::data, section_names::data) {
-  uint8_t *arr = bAlloc.Allocate<uint8_t>(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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104199.351751.patch
Type: text/x-patch
Size: 2985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210613/13012c62/attachment.bin>


More information about the llvm-commits mailing list