Loading...
cache_builder/CacheDylib.h dyld-1340 dyld-1162
--- dyld/dyld-1340/cache_builder/CacheDylib.h
+++ dyld/dyld-1162/cache_builder/CacheDylib.h
@@ -34,7 +34,6 @@
 #include "SectionCoalescer.h"
 #include "SwiftVisitor.h"
 #include "Timer.h"
-#include "Image.h"
 
 #include <list>
 
@@ -48,7 +47,6 @@
 struct ObjCCategoryOptimizer;
 struct StubOptimizer;
 struct UnmappedSymbolsOptimizer;
-struct FunctionVariantsOptimizer;
 
 // A dylib which will be included in the cache
 struct CacheDylib
@@ -59,8 +57,6 @@
     CacheDylib() = delete;
 #endif
     CacheDylib(InputFile& inputFile);
-    // create a CacheDylib *placeholder* with an install name only and no input mach-o
-    CacheDylib(std::string_view installName);
     ~CacheDylib() = default;
 
     CacheDylib(const CacheDylib&) = delete;
@@ -80,15 +76,13 @@
                            const BuilderConfig& config, Timer::AggregateTimer& timer,
                            UnmappedSymbolsOptimizer& unmappedSymbolsOptimizer);
     void updateSymbolTables(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer);
-    std::vector<error::Error> calculateBindTargets(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer,
-                                                   const std::vector<const CacheDylib *>& cacheDylibs,
-                                                   PatchInfo& dylibPatchInfo);
-    void calcuatePatchInfo(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer,
-                           PatchInfo& dylibPatchInfo);
+    void calculateBindTargets(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer,
+                              const std::vector<const CacheDylib *>& cacheDylibs,
+                              PatchInfo& dylibPatchInfo);
     void bind(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer,
-              PatchInfo& dylibPatchInfo, FunctionVariantsOptimizer& functionVariantsOptimizer);
+              PatchInfo& dylibPatchInfo);
     void updateObjCSelectorReferences(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer,
-                                      ObjCSelectorOptimizer& objcSelectorOptimizer);
+                                      const ObjCSelectorOptimizer& objcSelectorOptimizer);
     void convertObjCMethodListsToOffsets(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer,
                                          const Chunk* selectorStringsChunk);
     void sortObjCMethodLists(Diagnostics& diag, const BuilderConfig& config, Timer::AggregateTimer& timer,
@@ -109,9 +103,6 @@
                          const ObjCPreAttachedCategoriesChunk* preAttachedCategoriesChunk,
                          const ObjCHeaderInfoReadWriteChunk* headerInfoReadWriteChunk,
                          const ObjCCanonicalProtocolsChunk* canonicalProtocolsChunk);
-    // remove all dylib link load commands, except libSystem
-    void removeLinkedDylibs(Diagnostics& diag);
-    void addLinkedDylib(Diagnostics& diag, const CacheDylib& dylib);
 
     void forEachCacheSection(void (^callback)(std::string_view segmentName,
                                               std::string_view sectionName,
@@ -153,8 +144,6 @@
             VMOffset            targetRuntimeOffset;
             const CacheDylib*   targetDylib;
             bool                isWeakDef;
-            bool                isFunctionVariant;
-            uint16_t            functionVariantTableIndex;
         };
 
         struct CacheImage
@@ -162,8 +151,6 @@
             VMOffset            targetRuntimeOffset;
             const CacheDylib*   targetDylib;
             bool                isWeakDef;
-            bool                isFunctionVariant;
-            uint16_t            functionVariantTableIndex;
         };
 
         Kind        kind    = Kind::absolute;
@@ -178,14 +165,7 @@
         };
         uint64_t    addend  = 0;
         bool        isWeakImport;
-#if DEBUG
-        CString     name;
-#endif
     };
-
-    // Map from where the GOT is located in the dylib to where its located in the coalesced section
-    // We don't know the final VMAddr yet, but can map from GOTs in the client to the GOT+offset in the final cache
-    typedef std::unordered_map<const InputDylibVMAddress, ChunkPlusOffset, InputDylibVMAddressHash, InputDylibVMAddressEqual> CoalescedGOTsMap;
 
     typedef std::pair<BindTarget, std::string> BindTargetAndName;
     enum class SearchMode
@@ -211,31 +191,23 @@
     // Helper method for calculateBindTargets()
     BindTargetAndName                   resolveSymbol(Diagnostics& diag, int libOrdinal, const char* symbolName, bool weakImport,
                                                       const std::vector<const CacheDylib*>& cacheDylibs) const;
-    std::optional<BindTargetAndName>    findDyldMagicSymbolAddress(const char* fullSymbolName, std::string_view name) const;
-
-    void calculateBindLocationPatchInfo(Diagnostics& diag, const BuilderConfig& config,
-                                        const BindTarget& bindTarget, uint64_t addend,
-                                        uint32_t bindOrdinal, uint32_t segIndex,
-                                        InputDylibVMAddress fixupVMAddr, dyld3::MachOFile::PointerMetaData pmd,
-                                        CoalescedGOTsMap& coalescedGOTs, CoalescedGOTsMap& coalescedAuthGOTs,
-                                        CoalescedGOTsMap& coalescedAuthPtrs, PatchInfo& dylibPatchInfo);
+
+    // Map from where the GOT is located in the dylib to where its located in the coalesced section
+    typedef std::unordered_map<const CacheVMAddress, CacheVMAddress, CacheVMAddressHash, CacheVMAddressEqual> CoalescedGOTMap;
 
     void bindLocation(Diagnostics& diag, const BuilderConfig& config,
                       const BindTarget& bindTarget, uint64_t addend,
                       uint32_t bindOrdinal, uint32_t segIndex,
                       dyld3::MachOFile::ChainedFixupPointerOnDisk* fixupLoc,
                       CacheVMAddress fixupVMAddr, dyld3::MachOFile::PointerMetaData pmd,
-                      CoalescedGOTsMap& coalescedGOTs, CoalescedGOTsMap& coalescedAuthGOTs,
-                      CoalescedGOTsMap& coalescedAuthPtrs, PatchInfo& dylibPatchInfo,
-                      FunctionVariantsOptimizer& functionVariantsOptimizer);
+                      CoalescedGOTMap& coalescedGOTs, CoalescedGOTMap& coalescedAuthGOTs,
+                      PatchInfo& dylibPatchInfo);
     void bindWithChainedFixups(Diagnostics& diag, const BuilderConfig& config,
-                               CoalescedGOTsMap& coalescedGOTs, CoalescedGOTsMap& coalescedAuthGOTs,
-                               CoalescedGOTsMap& coalescedAuthPtrs, PatchInfo& dylibPatchInfo,
-                               FunctionVariantsOptimizer& functionVariantsOptimizer);
+                               CoalescedGOTMap& coalescedGOTs, CoalescedGOTMap& coalescedAuthGOTs,
+                               PatchInfo& dylibPatchInfo);
     void bindWithOpcodeFixups(Diagnostics& diag, const BuilderConfig& config,
-                              CoalescedGOTsMap& coalescedGOTs, CoalescedGOTsMap& coalescedAuthGOTs,
-                              CoalescedGOTsMap& coalescedAuthPtrs, PatchInfo& dylibPatchInfo,
-                              FunctionVariantsOptimizer& functionVariantsOptimizer);
+                              CoalescedGOTMap& coalescedGOTs, CoalescedGOTMap& coalescedAuthGOTs,
+                              PatchInfo& dylibPatchInfo);
 
     void forEachReferenceToASelRef(Diagnostics &diags,
                                    void (^handler)(uint64_t kind, uint32_t* instrPtr, uint64_t selRefVMAddr)) const;
@@ -270,22 +242,16 @@
 public:
     InputFile*                              inputFile               = nullptr;
     const dyld3::MachOFile*                 inputMF                 = nullptr;
-    const mach_o::Header*                   inputHdr                = nullptr;
-    std::unique_ptr<mach_o::Image>          inputImage              = nullptr;
     InputDylibVMAddress                     inputLoadAddress;
     std::string_view                        installName;
     uint32_t                                cacheIndex;
-    bool                                    needsPatchTable         = true;
     dyld3::MachOFile*                       cacheMF                 = nullptr;
-    const mach_o::Header*                   cacheHdr                = nullptr;
     CacheVMAddress                          cacheLoadAddress;
     std::vector<DylibSegmentChunk>          segments;
     // This is a list due to iterator invalidation, ie, calculateSubCacheSymbolStrings() deletes
     // elements and Region holds pointers to them
     std::list<LinkeditDataChunk>            linkeditChunks;
     std::vector<DependentDylib>             dependents;
-    // an unmodified list of linked libraries, used for symbol resolution
-    std::vector<DependentDylib>             inputDependents;
     std::vector<BindTarget>                 bindTargets;
     std::optional<uint32_t>                 weakBindTargetsStartIndex;
     std::unique_ptr<DylibSegmentsAdjustor>  adjustor;