]> git.saurik.com Git - apple/ld64.git/blobdiff - src/ld/ld.hpp
ld64-253.9.tar.gz
[apple/ld64.git] / src / ld / ld.hpp
index 889cf2cd3bc080db7c0b71e12fef985e33211835..e297036efe41243d1241d73b821df7b860f64e51 100644 (file)
 #include <unistd.h>
 #include <assert.h>
 
+#include <set>
+#include <map>
 #include <vector>
+#include <string>
 #include <unordered_set>
 
 #include "configure.h"
 
 namespace ld {
 
+// Forward declaration for bitcode support
+class Bitcode;
+
 //
 // ld::File 
 //
@@ -149,8 +155,11 @@ public:
        virtual uint8_t                                         swiftVersion() const                    { return 0; }
        virtual uint32_t                                        cpuSubType() const              { return 0; }
        virtual uint32_t                                        subFileCount() const    { return 1; }
+       virtual uint32_t                                        minOSVersion() const    { return 0; }
+       virtual uint32_t                                        platformLoadCommand() const             { return 0; }
     bool                                                               fileExists() const     { return _modTime != 0; }
        Type                                                            type() const { return _type; }
+       virtual Bitcode*                                        getBitcode() const              { return NULL; }
 private:
        const char*                                                     _path;
        time_t                                                          _modTime;
@@ -169,7 +178,9 @@ enum IOSVersionMin { iOSVersionUnset=0, iOS_2_0=0x00020000, iOS_3_1=0x00030100,
                                                iOS_4_2=0x00040200, iOS_4_3=0x00040300, iOS_5_0=0x00050000,
                                                iOS_6_0=0x00060000, iOS_7_0=0x00070000, iOS_8_0=0x00080000,
                                                iOS_9_0=0x00090000, iOS_Future=0x10000000};
+enum WatchOSVersionMin  { wOSVersionUnset=0, wOS_1_0=0x00010000, wOS_2_0=0x00020000 };
+
+
 namespace relocatable {
        //
        // ld::relocatable::File 
@@ -191,6 +202,7 @@ namespace relocatable {
        {
        public:
                enum DebugInfoKind { kDebugInfoNone=0, kDebugInfoStabs=1, kDebugInfoDwarf=2, kDebugInfoStabsUUID=3 };
+               enum SourceKind { kSourceUnknown=0, kSourceObj, kSourceLTO, kSourceArchive, kSourceCompilerArchive };
                struct Stab {
                        const class Atom*       atom;
                        uint8_t                         type;
@@ -211,6 +223,7 @@ namespace relocatable {
                virtual bool                                            canScatterAtoms() const = 0;
                virtual bool                                            hasLongBranchStubs()            { return false; }
                virtual LinkerOptionsList*                      linkerOptions() const = 0;
+               virtual SourceKind                                      sourceKind() const { return kSourceUnknown; }
        };
 } // namespace relocatable
 
@@ -269,13 +282,15 @@ namespace dylib {
                virtual bool                                            hasWeakDefinition(const char* name) const = 0;
                virtual bool                                            hasPublicInstallName() const = 0;
                virtual bool                                            allSymbolsAreWeakImported() const = 0;
-               virtual const void*                                     codeSignatureDR() const = 0;
                virtual bool                                            installPathVersionSpecific() const { return false; }
                virtual bool                                            appExtensionSafe() const = 0;
-               virtual MacVersionMin                           macMinVersion() const { return macVersionUnset; }
-               virtual IOSVersionMin                           iOSMinVersion() const { return iOSVersionUnset; }
 
        protected:
+               struct ReExportChain { ReExportChain* prev; const File* file; };
+               virtual std::pair<bool, bool>           hasWeakDefinitionImpl(const char* name) const = 0;
+               virtual bool                                            containsOrReExports(const char* name, bool& weakDef, bool& tlv, uint64_t& defAddress) const = 0;
+               virtual void                                            assertNoReExportCycles(ReExportChain*) const = 0;
+
                const char*                                                     _dylibInstallPath;
                uint32_t                                                        _dylibTimeStamp;
                uint32_t                                                        _dylibCurrentVersion;
@@ -322,7 +337,7 @@ public:
                                typeLazyDylibPointer, typeStubHelper, typeInitializerPointers, typeTerminatorPointers,
                                typeStubClose, typeLazyPointerClose, typeAbsoluteSymbols, 
                                typeTLVDefs, typeTLVZeroFill, typeTLVInitialValues, typeTLVInitializerPointers, typeTLVPointers,
-                               typeFirstSection, typeLastSection, typeDebug };
+                               typeFirstSection, typeLastSection, typeDebug, typeSectCreate };
 
 
                                        Section(const char* sgName, const char* sctName,
@@ -644,7 +659,7 @@ public:
                                        typeSectionEnd, typeBranchIsland, typeLazyPointer, typeStub, typeNonLazyPointer, 
                                        typeLazyDylibPointer, typeStubHelper, typeInitializerPointers, typeTerminatorPointers,
                                        typeLTOtemporary, typeResolver,
-                                       typeTLV, typeTLVZeroFill, typeTLVInitialValue, typeTLVInitializerPointers };
+                                       typeTLV, typeTLVZeroFill, typeTLVInitialValue, typeTLVInitializerPointers, typeTLVPointer };
 
        enum SymbolTableInclusion { symbolTableNotIn, symbolTableNotInFinalLinkedImages, symbolTableIn,
                                                                symbolTableInAndNeverStrip, symbolTableInAsAbsolute, 
@@ -679,7 +694,8 @@ public:
                                                                                                        _contentType(ct), _symbolTableInclusion(i),
                                                                                                        _scope(s), _mode(modeSectionOffset), 
                                                                                                        _overridesADylibsWeakDef(false), _coalescedAway(false),
-                                                                                                       _live(false), _machoSection(0), _weakImportState(weakImportUnset)
+                                                                                                       _live(false), _dontDeadStripIfRefLive(false),
+                                                                                                       _machoSection(0), _weakImportState(weakImportUnset)
                                                                                                         {
                                                                                                        #ifndef NDEBUG
                                                                                                                switch ( _combine ) {
@@ -703,6 +719,7 @@ public:
        ContentType                                                             contentType() const                     { return _contentType; }
        SymbolTableInclusion                                    symbolTableInclusion() const{ return _symbolTableInclusion; }
        bool                                                                    dontDeadStrip() const           { return _dontDeadStrip; }
+       bool                                                                    dontDeadStripIfReferencesLive() const { return _dontDeadStripIfRefLive; }
        bool                                                                    isThumb() const                         { return _thumb; }
        bool                                                                    isAlias() const                         { return _alias; }
        Alignment                                                               alignment() const                       { return Alignment(_alignmentPowerOf2, _alignmentModulus); }
@@ -722,6 +739,7 @@ public:
        void                                                                    setCoalescedAway()                      { _coalescedAway = true; }
        void                                                                    setWeakImportState(bool w)      { assert(_definition == definitionProxy); _weakImportState = ( w ? weakImportTrue : weakImportFalse); }
        void                                                                    setAutoHide()                           { _autoHide = true; }
+       void                                                                    setDontDeadStripIfReferencesLive() { _dontDeadStripIfRefLive = true; }
        void                                                                    setLive()                                       { _live = true; }
        void                                                                    setLive(bool value)                     { _live = value; }
        void                                                                    setMachoSection(unsigned x) { assert(x != 0); assert(x < 256); _machoSection = x; }
@@ -794,6 +812,7 @@ protected:
        bool                                                            _overridesADylibsWeakDef : 1;
        bool                                                            _coalescedAway : 1;
        bool                                                            _live : 1;
+       bool                                                            _dontDeadStripIfRefLive : 1;
        unsigned                                                        _machoSection : 8;
        WeakImportState                                         _weakImportState : 2;
 };
@@ -824,6 +843,7 @@ struct CStringEquals
 
 typedef        std::unordered_set<const char*, ld::CStringHash, ld::CStringEquals>  CStringSet;
 
+
 class Internal
 {
 public:
@@ -848,6 +868,8 @@ public:
                bool                                                    hasExternalRelocs;
        };
        
+       typedef std::map<const ld::Atom*, FinalSection*>        AtomToSection;          
+
        virtual uint64_t                                        assignFileOffsets() = 0;
        virtual void                                            setSectionSizesAndAlignments() = 0;
        virtual ld::Internal::FinalSection*     addAtom(const Atom&) = 0;
@@ -858,19 +880,23 @@ public:
                                                                                        lazyBindingHelper(NULL), compressedFastBinderProxy(NULL),
                                                                                        objcObjectConstraint(ld::File::objcConstraintNone), 
                                                                                        objcDylibConstraint(ld::File::objcConstraintNone), 
-                                                                                       swiftVersion(0), cpuSubType(0), 
+                                                                                       swiftVersion(0), cpuSubType(0), minOSVersion(0),
+                                                                                       objectFileFoundWithNoVersion(false),
                                                                                        allObjectFilesScatterable(true), 
                                                                                        someObjectFileHasDwarf(false), usingHugeSections(false),
                                                                                        hasThreadLocalVariableDefinitions(false),
                                                                                        hasWeakExternalSymbols(false),
-                                                                                       someObjectHasOptimizationHints(false) { }
-                                                                               
+                                                                                       someObjectHasOptimizationHints(false),
+                                                                                       dropAllBitcode(false), embedMarkerOnly(false)   { }
+
        std::vector<FinalSection*>                                      sections;
        std::vector<ld::dylib::File*>                           dylibs;
        std::vector<ld::relocatable::File::Stab>        stabs;
+       AtomToSection                                                           atomToSection;          
        CStringSet                                                                      linkerOptionLibraries;
        CStringSet                                                                      linkerOptionFrameworks;
        std::vector<const ld::Atom*>                            indirectBindingTable;
+       std::vector<const ld::relocatable::File*>       filesWithBitcode;
        const ld::dylib::File*                                          bundleLoader;
        const Atom*                                                                     entryPoint;
        const Atom*                                                                     classicBindingHelper;
@@ -880,12 +906,18 @@ public:
        ld::File::ObjcConstraint                                        objcDylibConstraint;
        uint8_t                                                                         swiftVersion;
        uint32_t                                                                        cpuSubType;
+       uint32_t                                                                        minOSVersion;
+       uint32_t                                                                        derivedPlatformLoadCommand;
+       bool                                                                            objectFileFoundWithNoVersion;
        bool                                                                            allObjectFilesScatterable;
        bool                                                                            someObjectFileHasDwarf;
        bool                                                                            usingHugeSections;
        bool                                                                            hasThreadLocalVariableDefinitions;
        bool                                                                            hasWeakExternalSymbols;
        bool                                                                            someObjectHasOptimizationHints;
+       bool                                                                            dropAllBitcode;
+       bool                                                                            embedMarkerOnly;
+       std::string                                                                     ltoBitcodePath;
 };
 
 
@@ -894,10 +926,6 @@ public:
 
 
 
-
-
-
-
 } // namespace ld 
 
 #endif // __LD_HPP__