]> git.saurik.com Git - apple/ld64.git/blobdiff - src/ld/passes/stubs/stubs.cpp
ld64-274.2.tar.gz
[apple/ld64.git] / src / ld / passes / stubs / stubs.cpp
index 5ea1b05606cfa9ef6158a273c2963da38d0f2636..fb5b9f3b6d2d6ea51cdf60fb2f78f02e45b936dc 100644 (file)
@@ -35,8 +35,8 @@
 #include <map>
 
 #include "Options.h"
-#include "ld.hpp"
 #include "MachOFileAbstraction.hpp"
+#include "ld.hpp"
 
 #include "make_stubs.h"
 
@@ -90,8 +90,9 @@ private:
 #include "stub_x86_classic.hpp"
 #include "stub_arm.hpp"
 #include "stub_arm_classic.hpp"
-
-
+#if SUPPORT_ARCH_arm64
+#include "stub_arm64.hpp"
+#endif
 
 Pass::Pass(const Options& opts) 
        :       compressedHelperHelper(NULL), 
@@ -119,6 +120,9 @@ const ld::Atom* Pass::stubableFixup(const ld::Fixup* fixup, ld::Internal& state)
                        case ld::Fixup::kindStoreTargetAddressX86BranchPCRel32:
                        case ld::Fixup::kindStoreTargetAddressARMBranch24:
                        case ld::Fixup::kindStoreTargetAddressThumbBranch22:
+#if SUPPORT_ARCH_arm64
+                       case ld::Fixup::kindStoreTargetAddressARM64Branch26:
+#endif
                 assert(target != NULL);
                                // create stub if target is in a dylib
                                if ( target->definition() == ld::Atom::definitionProxy ) 
@@ -131,8 +135,12 @@ const ld::Atom* Pass::stubableFixup(const ld::Fixup* fixup, ld::Internal& state)
                                        if ( (target->definition() == ld::Atom::definitionRegular) 
                                                && (target->combine() == ld::Atom::combineByName) 
                                                && ((target->symbolTableInclusion() == ld::Atom::symbolTableIn) 
-                                                || (target->symbolTableInclusion() == ld::Atom::symbolTableInAndNeverStrip)) )
+                                                || (target->symbolTableInclusion() == ld::Atom::symbolTableInAndNeverStrip)) ) {
+                                               // don't make stubs for auto-hide symbols
+                                               if ( target->autoHide() && (!_options.hasExportMaskList() || !_options.shouldExport(target->name())) )
+                                                       return NULL;
                                                return target;
+                                       }
                                        // create stub if target is interposable
                                        if ( _options.interposable(target->name()) ) 
                                                return target;
@@ -160,17 +168,20 @@ const ld::Atom* Pass::stubableFixup(const ld::Fixup* fixup, ld::Internal& state)
 
 ld::Atom* Pass::makeStub(const ld::Atom& target, bool weakImport)
 {
-       //fprintf(stderr, "makeStub(target=%p %s in sect %s)\n", &target, target.name(), target.section().sectionName());
-       bool stubToGlobalWeakDef = ( (target.scope() == ld::Atom::scopeGlobal)
-                                                               && (target.definition() == ld::Atom::definitionRegular) 
-                                                               && (target.combine() == ld::Atom::combineByName) );
+       //fprintf(stderr, "makeStub(target=%p %s in sect %s, def=%d)\n", &target, target.name(), target.section().sectionName(), target.definition());
+       bool stubToGlobalWeakDef = ( (target.combine() == ld::Atom::combineByName) &&
+                                                                (((target.definition() == ld::Atom::definitionRegular) && (target.scope() == ld::Atom::scopeGlobal))
+                                                                 || (target.definition() == ld::Atom::definitionProxy)) );
 
        bool forLazyDylib = false;
        const ld::dylib::File* dylib = dynamic_cast<const ld::dylib::File*>(target.file());
        if ( (dylib != NULL) && dylib->willBeLazyLoadedDylib() ) 
                forLazyDylib = true;
        bool stubToResolver = (target.contentType() == ld::Atom::typeResolver);
-       
+#if SUPPORT_ARCH_arm_any || SUPPORT_ARCH_arm64
+       bool usingDataConst =  _options.useDataConstSegment();
+#endif
+
        if ( usingCompressedLINKEDIT() && !forLazyDylib ) {
                if ( _internal->compressedFastBinderProxy == NULL )
                        throwf("symbol dyld_stub_binder not found (normally in libSystem.dylib).  Needed to perform lazy binding to function %s", target.name());
@@ -202,10 +213,10 @@ ld::Atom* Pass::makeStub(const ld::Atom& target, bool weakImport)
                                return new ld::passes::stubs::arm::StubPICKextAtom(*this, target);
                        }
                        else if ( usingCompressedLINKEDIT() && !forLazyDylib ) {
-                               if ( (_stubCount < 900) && !_mightBeInSharedRegion && !_largeText )
+                               if ( (_stubCount < 900) && !_mightBeInSharedRegion && !_largeText && !_options.makeEncryptable() )
                                        return new ld::passes::stubs::arm::StubCloseAtom(*this, target, stubToGlobalWeakDef, stubToResolver, weakImport);
                                else if ( _pic )
-                                       return new ld::passes::stubs::arm::StubPICAtom(*this, target, stubToGlobalWeakDef, stubToResolver, weakImport);
+                                       return new ld::passes::stubs::arm::StubPICAtom(*this, target, stubToGlobalWeakDef, stubToResolver, weakImport, usingDataConst);
                                else
                                        return new ld::passes::stubs::arm::StubNoPICAtom(*this, target, stubToGlobalWeakDef, stubToResolver, weakImport);
                        } 
@@ -216,6 +227,14 @@ ld::Atom* Pass::makeStub(const ld::Atom& target, bool weakImport)
                                        return new ld::passes::stubs::arm::classic::StubNoPICAtom(*this, target, forLazyDylib, weakImport);
                        }
                        break;
+#endif
+#if SUPPORT_ARCH_arm64
+               case CPU_TYPE_ARM64:
+                       if ( (_options.outputKind() == Options::kKextBundle) && _options.kextsUseStubs() ) 
+                               return new ld::passes::stubs::arm64::KextStubAtom(*this, target);
+                       else
+                               return new ld::passes::stubs::arm64::StubAtom(*this, target, stubToGlobalWeakDef, stubToResolver, weakImport, usingDataConst);
+                       break;
 #endif
        }
        throw "unsupported arch for stub";