X-Git-Url: https://git.saurik.com/apple/ld64.git/blobdiff_plain/d92462995e19e0e740e5068b9540ca3ed9c93572..a645023da60d22e86be13f7b4d97adeff8bc6665:/src/ld/Options.h diff --git a/src/ld/Options.h b/src/ld/Options.h index 4a06a5e..7ce5766 100644 --- a/src/ld/Options.h +++ b/src/ld/Options.h @@ -1,6 +1,6 @@ /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- * - * Copyright (c) 2005-2007 Apple Inc. All rights reserved. + * Copyright (c) 2005-2010 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -33,7 +33,7 @@ #include #include -#include "ObjectFile.h" +#include "ld.hpp" extern void throwf (const char* format, ...) __attribute__ ((noreturn,format(printf, 1, 2))); extern void warning(const char* format, ...) __attribute__((format(printf, 1, 2))); @@ -41,12 +41,14 @@ extern void warning(const char* format, ...) __attribute__((format(printf, 1, 2) class LibraryOptions { public: - LibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false), fLazyLoad(false), fForceLoad(false) {} + LibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false), + fLazyLoad(false), fUpward(false), fForceLoad(false) {} // for dynamic libraries bool fWeakImport; bool fReExport; bool fBundleLoader; bool fLazyLoad; + bool fUpward; // for static libraries bool fForceLoad; }; @@ -76,9 +78,9 @@ public: enum WeakReferenceMismatchTreatment { kWeakReferenceMismatchError, kWeakReferenceMismatchWeak, kWeakReferenceMismatchNonWeak }; enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError }; - enum DeadStripMode { kDeadStripOff, kDeadStripOn, kDeadStripOnPlusUnusedInits }; enum UUIDMode { kUUIDNone, kUUIDRandom, kUUIDContent }; enum LocalSymbolHandling { kLocalSymbolsAll, kLocalSymbolsNone, kLocalSymbolsSelectiveInclude, kLocalSymbolsSelectiveExclude }; + enum DebugInfoStripping { kDebugInfoNone, kDebugInfoMinimal, kDebugInfoFull }; struct FileInfo { const char* path; @@ -93,6 +95,8 @@ public: const char* path; const uint8_t* data; uint64_t dataLen; + typedef ExtraSection* iterator; + typedef const ExtraSection* const_iterator; }; struct SectionAlignment { @@ -105,6 +109,7 @@ public: const char* symbolName; const char* objectFileName; }; + typedef const OrderedSymbol* OrderedSymbolsIterator; struct SegmentStart { const char* name; @@ -127,112 +132,164 @@ public: const char* useInstead; }; + struct AliasPair { + const char* realName; + const char* alias; + }; + + typedef const char* const* UndefinesIterator; - const ObjectFile::ReaderOptions& readerOptions(); - const char* getOutputFilePath(); - std::vector& getInputFiles(); +// const ObjectFile::ReaderOptions& readerOptions(); + const char* outputFilePath() const { return fOutputFile; } + const std::vector& getInputFiles() const { return fInputFiles; } - cpu_type_t architecture() { return fArchitecture; } - bool preferSubArchitecture() { return fHasPreferredSubType; } - cpu_subtype_t subArchitecture() { return fSubArchitecture; } - bool allowSubArchitectureMismatches() { return fAllowCpuSubtypeMismatches; } - OutputKind outputKind(); - bool prebind(); - bool bindAtLoad(); - bool fullyLoadArchives(); - NameSpace nameSpace(); - const char* installPath(); // only for kDynamicLibrary - uint32_t currentVersion(); // only for kDynamicLibrary - uint32_t compatibilityVersion(); // only for kDynamicLibrary - const char* entryName(); // only for kDynamicExecutable or kStaticExecutable + cpu_type_t architecture() const { return fArchitecture; } + bool preferSubArchitecture() const { return fHasPreferredSubType; } + cpu_subtype_t subArchitecture() const { return fSubArchitecture; } + bool allowSubArchitectureMismatches() const { return fAllowCpuSubtypeMismatches; } + bool forceCpuSubtypeAll() const { return fForceSubtypeAll; } + const char* architectureName() const { return fArchitectureName; } + void setArchitecture(cpu_type_t, cpu_subtype_t subtype); + OutputKind outputKind() const { return fOutputKind; } + bool prebind() const { return fPrebind; } + bool bindAtLoad() const { return fBindAtLoad; } + NameSpace nameSpace() const { return fNameSpace; } + const char* installPath() const; // only for kDynamicLibrary + uint32_t currentVersion() const { return fDylibCurrentVersion; } // only for kDynamicLibrary + uint32_t compatibilityVersion() const { return fDylibCompatVersion; } // only for kDynamicLibrary + const char* entryName() const { return fEntryName; } // only for kDynamicExecutable or kStaticExecutable const char* executablePath(); - uint64_t baseAddress(); - bool keepPrivateExterns(); // only for kObjectFile - bool needsModuleTable(); // only for kDynamicLibrary - bool interposable(const char* name); - bool hasExportRestrictList(); // -exported_symbol or -unexported_symbol - bool hasExportMaskList(); // just -exported_symbol - bool hasWildCardExportRestrictList(); - bool allGlobalsAreDeadStripRoots(); - bool shouldExport(const char*); - bool ignoreOtherArchInputFiles(); - bool forceCpuSubtypeAll(); - bool traceDylibs(); - bool traceArchives(); - DeadStripMode deadStrip(); - UndefinedTreatment undefinedTreatment(); - ObjectFile::ReaderOptions::MacVersionMin macosxVersionMin() { return fReaderOptions.fMacVersionMin; } - ObjectFile::ReaderOptions::IPhoneVersionMin iphoneOSVersionMin() { return fReaderOptions.fIPhoneVersionMin; } - bool minOS(ObjectFile::ReaderOptions::MacVersionMin mac, ObjectFile::ReaderOptions::IPhoneVersionMin iPhoneOS); + uint64_t baseAddress() const { return fBaseAddress; } + uint64_t maxAddress() const { return fMaxAddress; } + bool keepPrivateExterns() const { return fKeepPrivateExterns; } // only for kObjectFile + bool needsModuleTable() const { return fNeedsModuleTable; } // only for kDynamicLibrary + bool interposable(const char* name) const; + bool hasExportRestrictList() const { return (fExportMode != kExportDefault); } // -exported_symbol or -unexported_symbol + bool hasExportMaskList() const { return (fExportMode == kExportSome); } // just -exported_symbol + bool hasWildCardExportRestrictList() const; + bool hasReExportList() const { return ! fReExportSymbols.empty(); } + bool wasRemovedExport(const char* sym) const { return ( fRemovedExports.find(sym) != fRemovedExports.end() ); } + bool allGlobalsAreDeadStripRoots() const; + bool shouldExport(const char*) const; + bool shouldReExport(const char*) const; + bool ignoreOtherArchInputFiles() const { return fIgnoreOtherArchFiles; } + bool traceDylibs() const { return fTraceDylibs; } + bool traceArchives() const { return fTraceArchives; } + bool deadCodeStrip() const { return fDeadStrip; } + UndefinedTreatment undefinedTreatment() const { return fUndefinedTreatment; } + ld::MacVersionMin macosxVersionMin() const { return fMacVersionMin; } + ld::IPhoneVersionMin iphoneOSVersionMin() const { return fIPhoneVersionMin; } + bool minOS(ld::MacVersionMin mac, ld::IPhoneVersionMin iPhoneOS); bool messagesPrefixedWithArchitecture(); Treatment picTreatment(); - WeakReferenceMismatchTreatment weakReferenceMismatchTreatment(); - const char* umbrellaName(); - std::vector& allowableClients(); - const char* clientName(); - const char* initFunctionName(); // only for kDynamicLibrary + WeakReferenceMismatchTreatment weakReferenceMismatchTreatment() const { return fWeakReferenceMismatchTreatment; } + const char* umbrellaName() const { return fUmbrellaName; } + const std::vector& allowableClients() const { return fAllowableClients; } + const char* clientName() const { return fClientName; } + const char* initFunctionName() const { return fInitFunctionName; } // only for kDynamicLibrary const char* dotOutputFile(); - uint64_t zeroPageSize(); - bool hasCustomStack(); - uint64_t customStackSize(); - uint64_t customStackAddr(); - bool hasExecutableStack(); - std::vector& initialUndefines(); - bool printWhyLive(const char* name); - uint32_t minimumHeaderPad(); - uint64_t segmentAlignment() { return fSegmentAlignment; } - bool maxMminimumHeaderPad() { return fMaxMinimumHeaderPad; } - std::vector& extraSections(); - std::vector& sectionAlignments(); - CommonsMode commonsMode(); - bool warnCommons(); + uint64_t pageZeroSize() const { return fZeroPageSize; } + bool hasCustomStack() const { return (fStackSize != 0); } + uint64_t customStackSize() const { return fStackSize; } + uint64_t customStackAddr() const { return fStackAddr; } + bool hasExecutableStack() const { return fExecutableStack; } + bool hasNonExecutableHeap() const { return fNonExecutableHeap; } + UndefinesIterator initialUndefinesBegin() const { return &fInitialUndefines[0]; } + UndefinesIterator initialUndefinesEnd() const { return &fInitialUndefines[fInitialUndefines.size()]; } + bool printWhyLive(const char* name) const; + uint32_t minimumHeaderPad() const { return fMinimumHeaderPad; } + bool maxMminimumHeaderPad() const { return fMaxMinimumHeaderPad; } + ExtraSection::const_iterator extraSectionsBegin() const { return &fExtraSections[0]; } + ExtraSection::const_iterator extraSectionsEnd() const { return &fExtraSections[fExtraSections.size()]; } + CommonsMode commonsMode() const { return fCommonsMode; } + bool warnCommons() const { return fWarnCommons; } bool keepRelocations(); - FileInfo findFile(const char* path); - UUIDMode getUUIDMode() { return fUUIDMode; } + FileInfo findFile(const char* path) const; + UUIDMode UUIDMode() const { return fUUIDMode; } bool warnStabs(); bool pauseAtEnd() { return fPause; } - bool printStatistics() { return fStatistics; } - bool printArchPrefix() { return fMessagesPrefixedWithArchitecture; } + bool printStatistics() const { return fStatistics; } + bool printArchPrefix() const { return fMessagesPrefixedWithArchitecture; } void gotoClassicLinker(int argc, const char* argv[]); - bool sharedRegionEligible() { return fSharedRegionEligible; } - bool printOrderFileStatistics() { return fPrintOrderFileStatistics; } + bool sharedRegionEligible() const { return fSharedRegionEligible; } + bool printOrderFileStatistics() const { return fPrintOrderFileStatistics; } const char* dTraceScriptName() { return fDtraceScriptName; } bool dTrace() { return (fDtraceScriptName != NULL); } - std::vector& orderedSymbols() { return fOrderedSymbols; } - bool splitSeg() { return fSplitSegs; } + unsigned long orderedSymbolsCount() const { return fOrderedSymbols.size(); } + OrderedSymbolsIterator orderedSymbolsBegin() const { return &fOrderedSymbols[0]; } + OrderedSymbolsIterator orderedSymbolsEnd() const { return &fOrderedSymbols[fOrderedSymbols.size()]; } + bool splitSeg() const { return fSplitSegs; } uint64_t baseWritableAddress() { return fBaseWritableAddress; } - std::vector& customSegmentAddresses() { return fCustomSegmentAddresses; } - std::vector& customSegmentSizes() { return fCustomSegmentSizes; } - std::vector& customSegmentProtections() { return fCustomSegmentProtections; } - bool saveTempFiles() { return fSaveTempFiles; } - const std::vector& rpaths() { return fRPaths; } + uint64_t segmentAlignment() const { return fSegmentAlignment; } + uint64_t segPageSize(const char* segName) const; + uint64_t customSegmentAddress(const char* segName) const; + bool hasCustomSegmentAddress(const char* segName) const; + bool hasCustomSectionAlignment(const char* segName, const char* sectName) const; + uint8_t customSectionAlignment(const char* segName, const char* sectName) const; + uint32_t initialSegProtection(const char*) const; + uint32_t maxSegProtection(const char*) const; + bool saveTempFiles() const { return fSaveTempFiles; } + const std::vector& rpaths() const { return fRPaths; } bool readOnlyx86Stubs() { return fReadOnlyx86Stubs; } - std::vector& dylibOverrides() { return fDylibOverrides; } - const char* generatedMapPath() { return fMapPath; } - bool positionIndependentExecutable() { return fPositionIndependentExecutable; } - Options::FileInfo findFileUsingPaths(const char* path); - bool deadStripDylibs() { return fDeadStripDylibs; } - bool allowedUndefined(const char* name) { return ( fAllowedUndefined.find(name) != fAllowedUndefined.end() ); } - bool someAllowedUndefines() { return (fAllowedUndefined.size() != 0); } + const std::vector& dylibOverrides() const { return fDylibOverrides; } + const char* generatedMapPath() const { return fMapPath; } + bool positionIndependentExecutable() const { return fPositionIndependentExecutable; } + Options::FileInfo findFileUsingPaths(const char* path) const; + bool deadStripDylibs() const { return fDeadStripDylibs; } + bool allowedUndefined(const char* name) const { return ( fAllowedUndefined.find(name) != fAllowedUndefined.end() ); } + bool someAllowedUndefines() const { return (fAllowedUndefined.size() != 0); } LocalSymbolHandling localSymbolHandling() { return fLocalSymbolHandling; } - bool keepLocalSymbol(const char* symbolName); - bool allowTextRelocs() { return fAllowTextRelocs; } - bool warnAboutTextRelocs() { return fWarnTextRelocs; } - bool usingLazyDylibLinking() { return fUsingLazyDylibLinking; } - bool verbose() { return fVerbose; } - bool makeEncryptable() { return fEncryptable; } - bool needsUnwindInfoSection() { return fReaderOptions.fAddCompactUnwindEncoding; } - std::vector& llvmOptions() { return fLLVMOptions; } - bool makeClassicDyldInfo() { return fMakeClassicDyldInfo; } - bool makeCompressedDyldInfo() { return fMakeCompressedDyldInfo; } + bool keepLocalSymbol(const char* symbolName) const; + bool allowTextRelocs() const { return fAllowTextRelocs; } + bool warnAboutTextRelocs() const { return fWarnTextRelocs; } + bool usingLazyDylibLinking() const { return fUsingLazyDylibLinking; } + bool verbose() const { return fVerbose; } + bool makeEncryptable() const { return fEncryptable; } + bool needsUnwindInfoSection() const { return fAddCompactUnwindEncoding; } + const std::vector& llvmOptions() const{ return fLLVMOptions; } + const std::vector& dyldEnvironExtras() const{ return fDyldEnvironExtras; } + bool makeCompressedDyldInfo() const { return fMakeCompressedDyldInfo; } bool hasExportedSymbolOrder(); - bool exportedSymbolOrder(const char* sym, unsigned int* order); + bool exportedSymbolOrder(const char* sym, unsigned int* order) const; bool orderData() { return fOrderData; } - bool errorOnOtherArchFiles() { return fErrorOnOtherArchFiles; } - bool markAutoDeadStripDylib() { return fMarkDeadStrippableDylib; } - bool removeEHLabels() { return fReaderOptions.fNoEHLabels; } - bool useSimplifiedDylibReExports() { return fUseSimplifiedDylibReExports; } - bool objCABIVersion2POverride() { return fObjCABIVersion2POverride; } + bool errorOnOtherArchFiles() const { return fErrorOnOtherArchFiles; } + bool markAutoDeadStripDylib() const { return fMarkDeadStrippableDylib; } + bool removeEHLabels() const { return fNoEHLabels; } + bool useSimplifiedDylibReExports() const { return fUseSimplifiedDylibReExports; } + bool objCABIVersion2POverride() const { return fObjCABIVersion2Override; } + bool useUpwardDylibs() const { return fCanUseUpwardDylib; } + bool fullyLoadArchives() const { return fFullyLoadArchives; } + bool loadAllObjcObjectsFromArchives() const { return fLoadAllObjcObjectsFromArchives; } + bool autoOrderInitializers() const { return fAutoOrderInitializers; } + bool optimizeZeroFill() const { return fOptimizeZeroFill; } + bool logAllFiles() const { return fLogAllFiles; } + DebugInfoStripping debugInfoStripping() const { return fDebugInfoStripping; } + bool flatNamespace() const { return fFlatNamespace; } + bool linkingMainExecutable() const { return fLinkingMainExecutable; } + bool implicitlyLinkIndirectPublicDylibs() const { return fImplicitlyLinkPublicDylibs; } + bool whyLoad() const { return fWhyLoad; } + const char* traceOutputFile() const { return fTraceOutputFile; } + bool outputSlidable() const { return fOutputSlidable; } + bool haveCmdLineAliases() const { return (fAliases.size() != 0); } + const std::vector& cmdLineAliases() const { return fAliases; } + bool makeTentativeDefinitionsReal() const { return fMakeTentativeDefinitionsReal; } + const char* dyldInstallPath() const { return fDyldInstallPath; } + bool warnWeakExports() const { return fWarnWeakExports; } + bool objcGcCompaction() const { return fObjcGcCompaction; } + bool objcGc() const { return fObjCGc; } + bool objcGcOnly() const { return fObjCGcOnly; } + bool canUseThreadLocalVariables() const { return fTLVSupport; } + bool demangleSymbols() const { return fDemangle; } + bool addVersionLoadCommand() const { return fVersionLoadCommand; } + bool addFunctionStarts() const { return fFunctionStartsLoadCommand; } + bool canReExportSymbols() const { return fCanReExportSymbols; } + const char* tempLtoObjectPath() const { return fTempLtoObjectPath; } + bool objcCategoryMerging() const { return fObjcCategoryMerging; } + bool hasWeakBitTweaks() const; + bool forceWeak(const char* symbolName) const; + bool forceNotWeak(const char* symbolName) const; + bool forceWeakNonWildCard(const char* symbolName) const; + bool forceNotWeakNonWildcard(const char* symbolName) const; private: class CStringEquals @@ -249,14 +306,17 @@ private: class SetWithWildcards { public: void insert(const char*); - bool contains(const char*); - bool hasWildCards() { return !fWildCard.empty(); } - NameSet::iterator regularBegin() { return fRegular.begin(); } - NameSet::iterator regularEnd() { return fRegular.end(); } + bool contains(const char*) const; + bool containsNonWildcard(const char*) const; + bool empty() const { return fRegular.empty() && fWildCard.empty(); } + bool hasWildCards() const { return !fWildCard.empty(); } + NameSet::iterator regularBegin() const { return fRegular.begin(); } + NameSet::iterator regularEnd() const { return fRegular.end(); } + void remove(const NameSet&); private: static bool hasWildCards(const char*); - bool wildCardMatch(const char* pattern, const char* candidate); - bool inCharRange(const char*& range, unsigned char c); + bool wildCardMatch(const char* pattern, const char* candidate) const; + bool inCharRange(const char*& range, unsigned char c) const; NameSet fRegular; std::vector fWildCard; @@ -271,7 +331,7 @@ private: FileInfo findFramework(const char* frameworkName); FileInfo findFramework(const char* rootName, const char* suffix); bool checkForFile(const char* format, const char* dir, const char* rootName, - FileInfo& result); + FileInfo& result) const; uint32_t parseVersionNumber(const char*); void parseSectionOrderFile(const char* segment, const char* section, const char* path); void parseOrderFile(const char* path, bool cstring); @@ -300,11 +360,13 @@ private: void loadSymbolOrderFile(const char* fileOfExports, NameToOrder& orderMapping); - ObjectFile::ReaderOptions fReaderOptions; + +// ObjectFile::ReaderOptions fReaderOptions; const char* fOutputFile; std::vector fInputFiles; cpu_type_t fArchitecture; cpu_subtype_t fSubArchitecture; + const char* fArchitectureName; OutputKind fOutputKind; bool fHasPreferredSubType; bool fPrebind; @@ -315,7 +377,7 @@ private: bool fErrorOnOtherArchFiles; bool fForceSubtypeAll; InterposeMode fInterposeMode; - DeadStripMode fDeadStrip; + bool fDeadStrip; NameSpace fNameSpace; uint32_t fDylibCompatVersion; uint32_t fDylibCurrentVersion; @@ -323,11 +385,16 @@ private: const char* fFinalName; const char* fEntryName; uint64_t fBaseAddress; + uint64_t fMaxAddress; uint64_t fBaseWritableAddress; bool fSplitSegs; SetWithWildcards fExportSymbols; SetWithWildcards fDontExportSymbols; SetWithWildcards fInterposeList; + SetWithWildcards fForceWeakSymbols; + SetWithWildcards fForceNotWeakSymbols; + SetWithWildcards fReExportSymbols; + NameSet fRemovedExports; NameToOrder fExportSymbolsOrder; ExportMode fExportMode; LibrarySearchMode fLibrarySearchMode; @@ -347,14 +414,18 @@ private: const char* fDtraceScriptName; const char* fSegAddrTablePath; const char* fMapPath; + const char* fDyldInstallPath; + const char* fTempLtoObjectPath; uint64_t fZeroPageSize; uint64_t fStackSize; uint64_t fStackAddr; bool fExecutableStack; + bool fNonExecutableHeap; + bool fDisableNonExecutableHeap; uint32_t fMinimumHeaderPad; uint64_t fSegmentAlignment; CommonsMode fCommonsMode; - UUIDMode fUUIDMode; + enum UUIDMode fUUIDMode; SetWithWildcards fLocalSymbolsIncluded; SetWithWildcards fLocalSymbolsExcluded; LocalSymbolHandling fLocalSymbolHandling; @@ -370,6 +441,7 @@ private: bool fPrintOrderFileStatistics; bool fReadOnlyx86Stubs; bool fPositionIndependentExecutable; + bool fPIEOnCommandLine; bool fDisablePositionIndependentExecutable; bool fMaxMinimumHeaderPad; bool fDeadStripDylibs; @@ -379,12 +451,52 @@ private: bool fEncryptable; bool fOrderData; bool fMarkDeadStrippableDylib; - bool fMakeClassicDyldInfo; bool fMakeCompressedDyldInfo; + bool fMakeCompressedDyldInfoForceOff; bool fNoEHLabels; bool fAllowCpuSubtypeMismatches; bool fUseSimplifiedDylibReExports; - bool fObjCABIVersion2POverride; + bool fObjCABIVersion2Override; + bool fObjCABIVersion1Override; + bool fCanUseUpwardDylib; + bool fFullyLoadArchives; + bool fLoadAllObjcObjectsFromArchives; + bool fFlatNamespace; + bool fLinkingMainExecutable; + bool fForFinalLinkedImage; + bool fForStatic; + bool fForDyld; + bool fMakeTentativeDefinitionsReal; + bool fWhyLoad; + bool fRootSafe; + bool fSetuidSafe; + bool fImplicitlyLinkPublicDylibs; + bool fAddCompactUnwindEncoding; + bool fWarnCompactUnwind; + bool fRemoveDwarfUnwindIfCompactExists; + bool fAutoOrderInitializers; + bool fOptimizeZeroFill; + bool fLogObjectFiles; + bool fLogAllFiles; + bool fTraceDylibs; + bool fTraceIndirectDylibs; + bool fTraceArchives; + bool fOutputSlidable; + bool fWarnWeakExports; + bool fObjcGcCompaction; + bool fObjCGc; + bool fObjCGcOnly; + bool fDemangle; + bool fTLVSupport; + bool fVersionLoadCommand; + bool fFunctionStartsLoadCommand; + bool fCanReExportSymbols; + bool fObjcCategoryMerging; + DebugInfoStripping fDebugInfoStripping; + const char* fTraceOutputFile; + ld::MacVersionMin fMacVersionMin; + ld::IPhoneVersionMin fIPhoneVersionMin; + std::vector fAliases; std::vector fInitialUndefines; NameSet fAllowedUndefined; NameSet fWhyLive; @@ -399,6 +511,7 @@ private: std::vector fLibrarySearchPaths; std::vector fFrameworkSearchPaths; std::vector fSDKPaths; + std::vector fDyldEnvironExtras; bool fSaveTempFiles; };