]> git.saurik.com Git - apple/ld64.git/blobdiff - src/ld/passes/stubs/stub_arm64.hpp
ld64-274.2.tar.gz
[apple/ld64.git] / src / ld / passes / stubs / stub_arm64.hpp
index cb1ceb33cb51d516bcb00c218df9ef82f02e2a22..815e28a53b1a80184a44e4f3b86d631c1b0ff7b5 100644 (file)
@@ -95,7 +95,9 @@ public:
                                _fixup1(0,  ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64Page21,    compressedImageCache(pass)),
                                _fixup2(4,  ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64PageOff12, compressedImageCache(pass)), 
                                _fixup3(12, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64Page21,    compressedFastBinder(pass)), 
-                               _fixup4(16, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64PageOff12, compressedFastBinder(pass)) 
+                               _fixup4(16, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64PageOff12, compressedFastBinder(pass)), 
+                               _fixup5(ld::Fixup::kindLinkerOptimizationHint, LOH_ARM64_ADRP_ADD, 0, 4), 
+                               _fixup6(ld::Fixup::kindLinkerOptimizationHint, LOH_ARM64_ADRP_LDR, 12, 16) 
                                        { pass.addAtom(*this); }
 
        virtual ld::File*                                               file() const                                    { return NULL; }
@@ -112,7 +114,7 @@ public:
        }
        virtual void                                                    setScope(Scope)                                 { }
        virtual ld::Fixup::iterator                             fixupsBegin() const                             { return &_fixup1; }
-       virtual ld::Fixup::iterator                             fixupsEnd()     const                           { return &((ld::Fixup*)&_fixup4)[1]; }
+       virtual ld::Fixup::iterator                             fixupsEnd()     const                           { return &((ld::Fixup*)&_fixup6)[1]; }
 
 private:
        static ld::Atom* compressedImageCache(ld::passes::stubs::Pass& pass) {
@@ -130,6 +132,8 @@ private:
        ld::Fixup                                                               _fixup2;
        ld::Fixup                                                               _fixup3;
        ld::Fixup                                                               _fixup4;
+       ld::Fixup                                                               _fixup5;
+       ld::Fixup                                                               _fixup6;
        
        static ld::Section                                              _s_section;
 };
@@ -237,8 +241,9 @@ ld::Section                                         ResolverHelperAtom::_s_section("__TEXT", "__stub_helper", ld::S
 class LazyPointerAtom : public ld::Atom {
 public:
                                                                                        LazyPointerAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo,
-                                                                                                                       bool stubToGlobalWeakDef, bool stubToResolver, bool weakImport)
-                               : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever,
+                                                                                                                       bool stubToGlobalWeakDef, bool stubToResolver, bool weakImport, bool dataConstUsed)
+                               : ld::Atom(selectSection(stubToGlobalWeakDef, stubToResolver, dataConstUsed),
+                                                       ld::Atom::definitionRegular, ld::Atom::combineNever,
                                                        ld::Atom::scopeTranslationUnit, ld::Atom::typeLazyPointer, 
                                                        symbolTableNotIn, false, false, false, ld::Atom::Alignment(3)), 
                                _stubTo(stubTo),
@@ -265,6 +270,15 @@ public:
        virtual ld::Fixup::iterator                             fixupsEnd()     const                           { return &((ld::Fixup*)&_fixup2)[1]; }
 
 private:
+       static ld::Section& selectSection(bool stubToGlobalWeakDef, bool stubToResolver, bool dataConstUsed) {
+               if ( stubToGlobalWeakDef && dataConstUsed )
+                       return _s_sectionWeak;
+               else if ( stubToResolver && dataConstUsed )
+                       return _s_sectionResolver;
+               else
+                       return _s_section;
+       }
+
        const ld::Atom&                                                 _stubTo;
        StubHelperAtom                                                  _helper;
        ResolverHelperAtom                                              _resolverHelper;
@@ -272,23 +286,28 @@ private:
        ld::Fixup                                                               _fixup2;
        
        static ld::Section                                              _s_section;
+       static ld::Section                                              _s_sectionResolver;
+       static ld::Section                                              _s_sectionWeak;
 };
 
 ld::Section LazyPointerAtom::_s_section("__DATA", "__la_symbol_ptr", ld::Section::typeLazyPointer);
+ld::Section LazyPointerAtom::_s_sectionResolver("__DATA_DIRTY", "__la_resolver", ld::Section::typeLazyPointer);
+ld::Section LazyPointerAtom::_s_sectionWeak("__DATA", "__la_weak_ptr", ld::Section::typeLazyPointer);
 
 
 class StubAtom : public ld::Atom {
 public:
                                                                                        StubAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo,
-                                                                                                       bool stubToGlobalWeakDef, bool stubToResolver, bool weakImport)
+                                                                                                       bool stubToGlobalWeakDef, bool stubToResolver, bool weakImport, bool dataConstUsed)
                                : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever,
                                                        ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, 
                                                        symbolTableNotIn, false, false, false, ld::Atom::Alignment(1)), 
                                _stubTo(stubTo), 
-                               _lazyPointer(pass, stubTo, stubToGlobalWeakDef, stubToResolver, weakImport),
+                               _lazyPointer(pass, stubTo, stubToGlobalWeakDef, stubToResolver, weakImport, dataConstUsed),
                                _fixup1(0, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64Page21, &_lazyPointer),
-                               _fixup2(4, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64PageOff12, &_lazyPointer) 
-                                       { pass.addAtom(*this); }
+                               _fixup2(4, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARM64PageOff12, &_lazyPointer),
+                               _fixup3(ld::Fixup::kindLinkerOptimizationHint, LOH_ARM64_ADRP_LDR, 0, 4) 
+                                       { pass.addAtom(*this);  }
 
        virtual const ld::File*                                 file() const                                    { return _stubTo.file(); }
        virtual const char*                                             name() const                                    { return _stubTo.name(); }
@@ -301,13 +320,14 @@ public:
        }
        virtual void                                                    setScope(Scope)                                 { }
        virtual ld::Fixup::iterator                             fixupsBegin() const                             { return &_fixup1; }
-       virtual ld::Fixup::iterator                             fixupsEnd()     const                           { return &((ld::Fixup*)&_fixup2)[1]; }
+       virtual ld::Fixup::iterator                             fixupsEnd()     const                           { return &((ld::Fixup*)&_fixup3)[1]; }
 
 private:
        const ld::Atom&                                                 _stubTo;
        LazyPointerAtom                                                 _lazyPointer;
        mutable ld::Fixup                                               _fixup1;
        mutable ld::Fixup                                               _fixup2;
+       mutable ld::Fixup                                               _fixup3;
        
        static ld::Section                                              _s_section;
 };
@@ -386,5 +406,5 @@ private:
 ld::Section KextStubAtom::_s_section("__TEXT", "__stubs", ld::Section::typeCode);
 
 
-} // namespace x86_64 
+} // namespace arm64