1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2005-2010 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
30 #include <mach/machine.h>
33 #include <unordered_set>
34 #include <unordered_map>
38 #include "MachOFileAbstraction.hpp"
40 extern void throwf (const char* format
, ...) __attribute__ ((noreturn
,format(printf
, 1, 2)));
41 extern void warning(const char* format
, ...) __attribute__((format(printf
, 1, 2)));
48 LibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false),
49 fLazyLoad(false), fUpward(false), fIndirectDylib(false),
51 // for dynamic libraries
58 // for static libraries
65 // The public interface to the Options class is the abstract representation of what work the linker
68 // This abstraction layer will make it easier to support a future where the linker is a shared library
69 // invoked directly from Xcode. The target settings in Xcode would be used to directly construct an Options
70 // object (without building a command line which is then parsed).
76 Options(int argc
, const char* argv
[]);
79 enum OutputKind
{ kDynamicExecutable
, kStaticExecutable
, kDynamicLibrary
, kDynamicBundle
, kObjectFile
, kDyld
, kPreload
, kKextBundle
};
80 enum NameSpace
{ kTwoLevelNameSpace
, kFlatNameSpace
, kForceFlatNameSpace
};
81 // Standard treatment for many options.
82 enum Treatment
{ kError
, kWarning
, kSuppress
, kNULL
, kInvalid
};
83 enum UndefinedTreatment
{ kUndefinedError
, kUndefinedWarning
, kUndefinedSuppress
, kUndefinedDynamicLookup
};
84 enum WeakReferenceMismatchTreatment
{ kWeakReferenceMismatchError
, kWeakReferenceMismatchWeak
,
85 kWeakReferenceMismatchNonWeak
};
86 enum CommonsMode
{ kCommonsIgnoreDylibs
, kCommonsOverriddenByDylibs
, kCommonsConflictsDylibsError
};
87 enum UUIDMode
{ kUUIDNone
, kUUIDRandom
, kUUIDContent
};
88 enum LocalSymbolHandling
{ kLocalSymbolsAll
, kLocalSymbolsNone
, kLocalSymbolsSelectiveInclude
, kLocalSymbolsSelectiveExclude
};
89 enum BitcodeMode
{ kBitcodeProcess
, kBitcodeAsData
, kBitcodeMarker
, kBitcodeStrip
};
90 enum DebugInfoStripping
{ kDebugInfoNone
, kDebugInfoMinimal
, kDebugInfoFull
};
92 enum Platform
{ kPlatformUnknown
, kPlatformOSX
, kPlatformiOS
, kPlatformWatchOS
, kPlatform_tvOS
};
94 enum Platform
{ kPlatformUnknown
, kPlatformOSX
, kPlatformiOS
, kPlatformWatchOS
};
97 static Platform
platformForLoadCommand(uint32_t lc
) {
99 case LC_VERSION_MIN_MACOSX
:
101 case LC_VERSION_MIN_IPHONEOS
:
103 case LC_VERSION_MIN_WATCHOS
:
104 return kPlatformWatchOS
;
106 case LC_VERSION_MIN_TVOS
:
107 return kPlatform_tvOS
;
110 assert(!lc
&& "unknown LC_VERSION_MIN load command");
111 return kPlatformUnknown
;
114 static const char* platformName(Platform platform
) {
120 case kPlatformWatchOS
:
126 case kPlatformUnknown
:
137 LibraryOptions options
;
138 ld::File::Ordinal ordinal
;
141 // These are used by the threaded input file parsing engine.
142 mutable int inputFileSlot
; // The input file "slot" assigned to this particular file
145 // The use pattern for FileInfo is to create one on the stack in a leaf function and return
146 // it to the calling frame by copy. Therefore the copy constructor steals the path string from
147 // the source, which dies with the stack frame.
148 FileInfo(FileInfo
const &other
) : path(other
.path
), fileLen(other
.fileLen
), modTime(other
.modTime
), options(other
.options
), ordinal(other
.ordinal
), fromFileList(other
.fromFileList
), inputFileSlot(-1) { ((FileInfo
&)other
).path
= NULL
; };
150 FileInfo
&operator=(FileInfo other
) {
151 std::swap(path
, other
.path
);
152 std::swap(fileLen
, other
.fileLen
);
153 std::swap(modTime
, other
.modTime
);
154 std::swap(options
, other
.options
);
155 std::swap(ordinal
, other
.ordinal
);
156 std::swap(fromFileList
, other
.fromFileList
);
157 std::swap(inputFileSlot
, other
.inputFileSlot
);
158 std::swap(readyToParse
, other
.readyToParse
);
162 // Create an empty FileInfo. The path can be set implicitly by checkFileExists().
163 FileInfo() : path(NULL
), fileLen(0), modTime(-1), options(), fromFileList(false) {};
165 // Create a FileInfo for a specific path, but does not stat the file.
166 FileInfo(const char *_path
) : path(strdup(_path
)), fileLen(0), modTime(-1), options(), fromFileList(false) {};
168 ~FileInfo() { if (path
) ::free((void*)path
); }
170 // Stat the file and update fileLen and modTime.
171 // If the object already has a path the p must be NULL.
172 // If the object does not have a path then p can be any candidate path, and if the file exists the object permanently remembers the path.
173 // Returns true if the file exists, false if not.
174 bool checkFileExists(const Options
& options
, const char *p
=NULL
);
176 // Returns true if a previous call to checkFileExists() succeeded.
177 // Returns false if the file does not exist of checkFileExists() has never been called.
178 bool missing() const { return modTime
== -1; }
181 struct ExtraSection
{
182 const char* segmentName
;
183 const char* sectionName
;
187 typedef ExtraSection
* iterator
;
188 typedef const ExtraSection
* const_iterator
;
191 struct SectionAlignment
{
192 const char* segmentName
;
193 const char* sectionName
;
197 struct SectionOrderList
{
198 const char* segmentName
;
199 std::vector
<const char*> sectionOrder
;
202 struct OrderedSymbol
{
203 const char* symbolName
;
204 const char* objectFileName
;
206 typedef const OrderedSymbol
* OrderedSymbolsIterator
;
208 struct SegmentStart
{
218 struct SegmentProtect
{
224 struct DylibOverride
{
225 const char* installName
;
226 const char* useInstead
;
230 const char* realName
;
234 struct SectionRename
{
235 const char* fromSegment
;
236 const char* fromSection
;
237 const char* toSegment
;
238 const char* toSection
;
241 struct SegmentRename
{
242 const char* fromSegment
;
243 const char* toSegment
;
246 enum { depLinkerVersion
=0x00, depObjectFile
=0x10, depDirectDylib
=0x10, depIndirectDylib
=0x10,
247 depUpwardDirectDylib
=0x10, depUpwardIndirectDylib
=0x10, depArchive
=0x10,
248 depFileList
=0x10, depSection
=0x10, depBundleLoader
=0x10, depMisc
=0x10, depNotFound
=0x11,
249 depOutputFile
= 0x40 };
251 void dumpDependency(uint8_t, const char* path
) const;
253 typedef const char* const* UndefinesIterator
;
255 // const ObjectFile::ReaderOptions& readerOptions();
256 const char* outputFilePath() const { return fOutputFile
; }
257 const std::vector
<FileInfo
>& getInputFiles() const { return fInputFiles
; }
259 cpu_type_t
architecture() const { return fArchitecture
; }
260 bool preferSubArchitecture() const { return fHasPreferredSubType
; }
261 cpu_subtype_t
subArchitecture() const { return fSubArchitecture
; }
262 bool allowSubArchitectureMismatches() const { return fAllowCpuSubtypeMismatches
; }
263 bool enforceDylibSubtypesMatch() const { return fEnforceDylibSubtypesMatch
; }
264 bool forceCpuSubtypeAll() const { return fForceSubtypeAll
; }
265 const char* architectureName() const { return fArchitectureName
; }
266 void setArchitecture(cpu_type_t
, cpu_subtype_t subtype
, Options::Platform platform
);
267 bool archSupportsThumb2() const { return fArchSupportsThumb2
; }
268 OutputKind
outputKind() const { return fOutputKind
; }
269 bool prebind() const { return fPrebind
; }
270 bool bindAtLoad() const { return fBindAtLoad
; }
271 NameSpace
nameSpace() const { return fNameSpace
; }
272 const char* installPath() const; // only for kDynamicLibrary
273 uint64_t currentVersion() const { return fDylibCurrentVersion
; } // only for kDynamicLibrary
274 uint32_t currentVersion32() const; // only for kDynamicLibrary
275 uint32_t compatibilityVersion() const { return fDylibCompatVersion
; } // only for kDynamicLibrary
276 const char* entryName() const { return fEntryName
; } // only for kDynamicExecutable or kStaticExecutable
277 const char* executablePath();
278 uint64_t baseAddress() const { return fBaseAddress
; }
279 uint64_t maxAddress() const { return fMaxAddress
; }
280 bool keepPrivateExterns() const { return fKeepPrivateExterns
; } // only for kObjectFile
281 bool needsModuleTable() const { return fNeedsModuleTable
; } // only for kDynamicLibrary
282 bool interposable(const char* name
) const;
283 bool hasExportRestrictList() const { return (fExportMode
!= kExportDefault
); } // -exported_symbol or -unexported_symbol
284 bool hasExportMaskList() const { return (fExportMode
== kExportSome
); } // just -exported_symbol
285 bool hasWildCardExportRestrictList() const;
286 bool hasReExportList() const { return ! fReExportSymbols
.empty(); }
287 bool wasRemovedExport(const char* sym
) const { return ( fRemovedExports
.find(sym
) != fRemovedExports
.end() ); }
288 bool allGlobalsAreDeadStripRoots() const;
289 bool shouldExport(const char*) const;
290 bool shouldReExport(const char*) const;
291 std::vector
<const char*> exportsData() const;
292 bool ignoreOtherArchInputFiles() const { return fIgnoreOtherArchFiles
; }
293 bool traceDylibs() const { return fTraceDylibs
; }
294 bool traceArchives() const { return fTraceArchives
; }
295 bool traceEmitJSON() const { return fTraceEmitJSON
; }
296 bool deadCodeStrip() const { return fDeadStrip
; }
297 UndefinedTreatment
undefinedTreatment() const { return fUndefinedTreatment
; }
298 ld::MacVersionMin
macosxVersionMin() const { return fMacVersionMin
; }
299 ld::IOSVersionMin
iOSVersionMin() const { return fIOSVersionMin
; }
300 ld::WatchOSVersionMin
watchOSVersionMin() const { return fWatchOSVersionMin
; }
301 uint32_t minOSversion() const;
302 bool minOS(ld::MacVersionMin mac
, ld::IOSVersionMin iPhoneOS
);
303 bool min_iOS(ld::IOSVersionMin requirediOSMin
);
304 bool messagesPrefixedWithArchitecture();
305 Treatment
picTreatment();
306 WeakReferenceMismatchTreatment
weakReferenceMismatchTreatment() const { return fWeakReferenceMismatchTreatment
; }
307 const char* umbrellaName() const { return fUmbrellaName
; }
308 const std::vector
<const char*>& allowableClients() const { return fAllowableClients
; }
309 const char* clientName() const { return fClientName
; }
310 const char* initFunctionName() const { return fInitFunctionName
; } // only for kDynamicLibrary
311 const char* dotOutputFile();
312 uint64_t pageZeroSize() const { return fZeroPageSize
; }
313 bool hasCustomStack() const { return (fStackSize
!= 0); }
314 uint64_t customStackSize() const { return fStackSize
; }
315 uint64_t customStackAddr() const { return fStackAddr
; }
316 bool hasExecutableStack() const { return fExecutableStack
; }
317 bool hasNonExecutableHeap() const { return fNonExecutableHeap
; }
318 UndefinesIterator
initialUndefinesBegin() const { return &fInitialUndefines
[0]; }
319 UndefinesIterator
initialUndefinesEnd() const { return &fInitialUndefines
[fInitialUndefines
.size()]; }
320 const std::vector
<const char*>& initialUndefines() const { return fInitialUndefines
; }
321 bool printWhyLive(const char* name
) const;
322 uint32_t minimumHeaderPad() const { return fMinimumHeaderPad
; }
323 bool maxMminimumHeaderPad() const { return fMaxMinimumHeaderPad
; }
324 ExtraSection::const_iterator
extraSectionsBegin() const { return &fExtraSections
[0]; }
325 ExtraSection::const_iterator
extraSectionsEnd() const { return &fExtraSections
[fExtraSections
.size()]; }
326 CommonsMode
commonsMode() const { return fCommonsMode
; }
327 bool warnCommons() const { return fWarnCommons
; }
328 bool keepRelocations();
329 FileInfo
findFile(const std::string
&path
, const ld::dylib::File
* fromDylib
=nullptr) const;
330 bool findFile(const std::string
&path
, const std::vector
<std::string
> &tbdExtensions
, FileInfo
& result
) const;
331 UUIDMode
UUIDMode() const { return fUUIDMode
; }
333 bool pauseAtEnd() { return fPause
; }
334 bool printStatistics() const { return fStatistics
; }
335 bool printArchPrefix() const { return fMessagesPrefixedWithArchitecture
; }
336 void gotoClassicLinker(int argc
, const char* argv
[]);
337 bool sharedRegionEligible() const { return fSharedRegionEligible
; }
338 bool printOrderFileStatistics() const { return fPrintOrderFileStatistics
; }
339 const char* dTraceScriptName() { return fDtraceScriptName
; }
340 bool dTrace() { return (fDtraceScriptName
!= NULL
); }
341 unsigned long orderedSymbolsCount() const { return fOrderedSymbols
.size(); }
342 OrderedSymbolsIterator
orderedSymbolsBegin() const { return &fOrderedSymbols
[0]; }
343 OrderedSymbolsIterator
orderedSymbolsEnd() const { return &fOrderedSymbols
[fOrderedSymbols
.size()]; }
344 bool splitSeg() const { return fSplitSegs
; }
345 uint64_t baseWritableAddress() { return fBaseWritableAddress
; }
346 uint64_t segmentAlignment() const { return fSegmentAlignment
; }
347 uint64_t segPageSize(const char* segName
) const;
348 uint64_t customSegmentAddress(const char* segName
) const;
349 bool hasCustomSegmentAddress(const char* segName
) const;
350 bool hasCustomSectionAlignment(const char* segName
, const char* sectName
) const;
351 uint8_t customSectionAlignment(const char* segName
, const char* sectName
) const;
352 uint32_t initialSegProtection(const char*) const;
353 uint32_t maxSegProtection(const char*) const;
354 bool saveTempFiles() const { return fSaveTempFiles
; }
355 const std::vector
<const char*>& rpaths() const { return fRPaths
; }
356 bool readOnlyx86Stubs() { return fReadOnlyx86Stubs
; }
357 const std::vector
<DylibOverride
>& dylibOverrides() const { return fDylibOverrides
; }
358 const char* generatedMapPath() const { return fMapPath
; }
359 bool positionIndependentExecutable() const { return fPositionIndependentExecutable
; }
360 Options::FileInfo
findIndirectDylib(const std::string
& installName
, const ld::dylib::File
* fromDylib
) const;
361 bool deadStripDylibs() const { return fDeadStripDylibs
; }
362 bool allowedUndefined(const char* name
) const { return ( fAllowedUndefined
.find(name
) != fAllowedUndefined
.end() ); }
363 bool someAllowedUndefines() const { return (fAllowedUndefined
.size() != 0); }
364 LocalSymbolHandling
localSymbolHandling() { return fLocalSymbolHandling
; }
365 bool keepLocalSymbol(const char* symbolName
) const;
366 bool allowTextRelocs() const { return fAllowTextRelocs
; }
367 bool warnAboutTextRelocs() const { return fWarnTextRelocs
; }
368 bool kextsUseStubs() const { return fKextsUseStubs
; }
369 bool usingLazyDylibLinking() const { return fUsingLazyDylibLinking
; }
370 bool verbose() const { return fVerbose
; }
371 bool makeEncryptable() const { return fEncryptable
; }
372 bool needsUnwindInfoSection() const { return fAddCompactUnwindEncoding
; }
373 const std::vector
<const char*>& llvmOptions() const{ return fLLVMOptions
; }
374 const std::vector
<const char*>& segmentOrder() const{ return fSegmentOrder
; }
375 bool segmentOrderAfterFixedAddressSegment(const char* segName
) const;
376 const std::vector
<const char*>* sectionOrder(const char* segName
) const;
377 const std::vector
<const char*>& dyldEnvironExtras() const{ return fDyldEnvironExtras
; }
378 const std::vector
<const char*>& astFilePaths() const{ return fASTFilePaths
; }
379 bool makeCompressedDyldInfo() const { return fMakeCompressedDyldInfo
; }
380 bool hasExportedSymbolOrder();
381 bool exportedSymbolOrder(const char* sym
, unsigned int* order
) const;
382 bool orderData() { return fOrderData
; }
383 bool errorOnOtherArchFiles() const { return fErrorOnOtherArchFiles
; }
384 bool markAutoDeadStripDylib() const { return fMarkDeadStrippableDylib
; }
385 bool removeEHLabels() const { return fNoEHLabels
; }
386 bool useSimplifiedDylibReExports() const { return fUseSimplifiedDylibReExports
; }
387 bool objCABIVersion2POverride() const { return fObjCABIVersion2Override
; }
388 bool useUpwardDylibs() const { return fCanUseUpwardDylib
; }
389 bool fullyLoadArchives() const { return fFullyLoadArchives
; }
390 bool loadAllObjcObjectsFromArchives() const { return fLoadAllObjcObjectsFromArchives
; }
391 bool autoOrderInitializers() const { return fAutoOrderInitializers
; }
392 bool optimizeZeroFill() const { return fOptimizeZeroFill
; }
393 bool mergeZeroFill() const { return fMergeZeroFill
; }
394 bool logAllFiles() const { return fLogAllFiles
; }
395 DebugInfoStripping
debugInfoStripping() const { return fDebugInfoStripping
; }
396 bool flatNamespace() const { return fFlatNamespace
; }
397 bool linkingMainExecutable() const { return fLinkingMainExecutable
; }
398 bool implicitlyLinkIndirectPublicDylibs() const { return fImplicitlyLinkPublicDylibs
; }
399 bool whyLoad() const { return fWhyLoad
; }
400 const char* traceOutputFile() const { return fTraceOutputFile
; }
401 bool outputSlidable() const { return fOutputSlidable
; }
402 bool haveCmdLineAliases() const { return (fAliases
.size() != 0); }
403 const std::vector
<AliasPair
>& cmdLineAliases() const { return fAliases
; }
404 bool makeTentativeDefinitionsReal() const { return fMakeTentativeDefinitionsReal
; }
405 const char* dyldInstallPath() const { return fDyldInstallPath
; }
406 bool warnWeakExports() const { return fWarnWeakExports
; }
407 bool objcGcCompaction() const { return fObjcGcCompaction
; }
408 bool objcGc() const { return fObjCGc
; }
409 bool objcGcOnly() const { return fObjCGcOnly
; }
410 bool canUseThreadLocalVariables() const { return fTLVSupport
; }
411 bool addVersionLoadCommand() const { return fVersionLoadCommand
&& (fPlatform
!= kPlatformUnknown
); }
412 bool addFunctionStarts() const { return fFunctionStartsLoadCommand
; }
413 bool addDataInCodeInfo() const { return fDataInCodeInfoLoadCommand
; }
414 bool canReExportSymbols() const { return fCanReExportSymbols
; }
415 const char* ltoCachePath() const { return fLtoCachePath
; }
416 int ltoPruneInterval() const { return fLtoPruneInterval
; }
417 int ltoPruneAfter() const { return fLtoPruneAfter
; }
418 unsigned ltoMaxCacheSize() const { return fLtoMaxCacheSize
; }
419 const char* tempLtoObjectPath() const { return fTempLtoObjectPath
; }
420 const char* overridePathlibLTO() const { return fOverridePathlibLTO
; }
421 const char* mcpuLTO() const { return fLtoCpu
; }
422 bool objcCategoryMerging() const { return fObjcCategoryMerging
; }
423 bool pageAlignDataAtoms() const { return fPageAlignDataAtoms
; }
424 bool keepDwarfUnwind() const { return fKeepDwarfUnwind
; }
425 bool verboseOptimizationHints() const { return fVerboseOptimizationHints
; }
426 bool ignoreOptimizationHints() const { return fIgnoreOptimizationHints
; }
427 bool generateDtraceDOF() const { return fGenerateDtraceDOF
; }
428 bool allowBranchIslands() const { return fAllowBranchIslands
; }
429 bool traceSymbolLayout() const { return fTraceSymbolLayout
; }
430 bool markAppExtensionSafe() const { return fMarkAppExtensionSafe
; }
431 bool checkDylibsAreAppExtensionSafe() const { return fCheckAppExtensionSafe
; }
432 bool forceLoadSwiftLibs() const { return fForceLoadSwiftLibs
; }
433 bool bundleBitcode() const { return fBundleBitcode
; }
434 bool hideSymbols() const { return fHideSymbols
; }
435 bool verifyBitcode() const { return fVerifyBitcode
; }
436 bool renameReverseSymbolMap() const { return fReverseMapUUIDRename
; }
437 bool deduplicateFunctions() const { return fDeDupe
; }
438 bool verboseDeduplicate() const { return fVerboseDeDupe
; }
439 const char* reverseSymbolMapPath() const { return fReverseMapPath
; }
440 std::string
reverseMapTempPath() const { return fReverseMapTempPath
; }
441 bool ltoCodegenOnly() const { return fLTOCodegenOnly
; }
442 bool ignoreAutoLink() const { return fIgnoreAutoLink
; }
443 bool allowDeadDuplicates() const { return fAllowDeadDups
; }
444 bool allowWeakImports() const { return fAllowWeakImports
; }
445 BitcodeMode
bitcodeKind() const { return fBitcodeKind
; }
446 bool sharedRegionEncodingV2() const { return fSharedRegionEncodingV2
; }
447 bool useDataConstSegment() const { return fUseDataConstSegment
; }
448 bool useTextExecSegment() const { return fUseTextExecSegment
; }
449 bool hasWeakBitTweaks() const;
450 bool forceWeak(const char* symbolName
) const;
451 bool forceNotWeak(const char* symbolName
) const;
452 bool forceWeakNonWildCard(const char* symbolName
) const;
453 bool forceNotWeakNonWildcard(const char* symbolName
) const;
454 bool forceCoalesce(const char* symbolName
) const;
455 Snapshot
& snapshot() const { return fLinkSnapshot
; }
456 bool errorBecauseOfWarnings() const;
457 bool needsThreadLoadCommand() const { return fNeedsThreadLoadCommand
; }
458 bool needsEntryPointLoadCommand() const { return fEntryPointLoadCommand
; }
459 bool needsSourceVersionLoadCommand() const { return fSourceVersionLoadCommand
; }
460 bool canUseAbsoluteSymbols() const { return fAbsoluteSymbols
; }
461 bool allowSimulatorToLinkWithMacOSX() const { return fAllowSimulatorToLinkWithMacOSX
; }
462 uint64_t sourceVersion() const { return fSourceVersion
; }
463 uint32_t sdkVersion() const { return fSDKVersion
; }
464 const char* demangleSymbol(const char* sym
) const;
465 bool pipelineEnabled() const { return fPipelineFifo
!= NULL
; }
466 const char* pipelineFifo() const { return fPipelineFifo
; }
467 bool dumpDependencyInfo() const { return (fDependencyInfoPath
!= NULL
); }
468 const char* dependencyInfoPath() const { return fDependencyInfoPath
; }
469 bool targetIOSSimulator() const { return fTargetIOSSimulator
; }
470 ld::relocatable::File::LinkerOptionsList
&
471 linkerOptions() const { return fLinkerOptions
; }
472 FileInfo
findFramework(const char* frameworkName
) const;
473 FileInfo
findLibrary(const char* rootName
, bool dylibsOnly
=false) const;
474 bool armUsesZeroCostExceptions() const;
475 const std::vector
<SectionRename
>& sectionRenames() const { return fSectionRenames
; }
476 const std::vector
<SegmentRename
>& segmentRenames() const { return fSegmentRenames
; }
477 bool moveRoSymbol(const char* symName
, const char* filePath
, const char*& seg
, bool& wildCardMatch
) const;
478 bool moveRwSymbol(const char* symName
, const char* filePath
, const char*& seg
, bool& wildCardMatch
) const;
479 Platform
platform() const { return fPlatform
; }
480 const std::vector
<const char*>& sdkPaths() const { return fSDKPaths
; }
481 std::vector
<std::string
> writeBitcodeLinkOptions() const;
482 std::string
getSDKVersionStr() const;
483 std::string
getPlatformStr() const;
484 uint8_t maxDefaultCommonAlign() const { return fMaxDefaultCommonAlign
; }
485 bool hasDataSymbolMoves() const { return !fSymbolsMovesData
.empty(); }
486 bool hasCodeSymbolMoves() const { return !fSymbolsMovesCode
.empty(); }
488 static uint32_t parseVersionNumber32(const char*);
491 typedef std::unordered_map
<const char*, unsigned int, ld::CStringHash
, ld::CStringEquals
> NameToOrder
;
492 typedef std::unordered_set
<const char*, ld::CStringHash
, ld::CStringEquals
> NameSet
;
493 enum ExportMode
{ kExportDefault
, kExportSome
, kDontExportSome
};
494 enum LibrarySearchMode
{ kSearchDylibAndArchiveInEachDir
, kSearchAllDirsForDylibsThenAllDirsForArchives
};
495 enum InterposeMode
{ kInterposeNone
, kInterposeAllExternal
, kInterposeSome
};
497 class SetWithWildcards
{
499 void insert(const char*);
500 bool contains(const char*, bool* wildCardMatch
=NULL
) const;
501 bool containsWithPrefix(const char* symbol
, const char* file
, bool& wildCardMatch
) const;
502 bool containsNonWildcard(const char*) const;
503 bool empty() const { return fRegular
.empty() && fWildCard
.empty(); }
504 bool hasWildCards() const { return !fWildCard
.empty(); }
505 NameSet::iterator
regularBegin() const { return fRegular
.begin(); }
506 NameSet::iterator
regularEnd() const { return fRegular
.end(); }
507 void remove(const NameSet
&);
508 std::vector
<const char*> data() const;
510 static bool hasWildCards(const char*);
511 bool wildCardMatch(const char* pattern
, const char* candidate
) const;
512 bool inCharRange(const char*& range
, unsigned char c
) const;
515 std::vector
<const char*> fWildCard
;
519 const char* toSegment
;
520 SetWithWildcards symbols
;
523 void parse(int argc
, const char* argv
[]);
524 void checkIllegalOptionCombinations();
525 void buildSearchPaths(int argc
, const char* argv
[]);
526 void parseArch(const char* architecture
);
527 FileInfo
findFramework(const char* rootName
, const char* suffix
) const;
528 bool checkForFile(const char* format
, const char* dir
, const char* rootName
,
529 FileInfo
& result
) const;
530 uint64_t parseVersionNumber64(const char*);
531 std::string
getVersionString32(uint32_t ver
) const;
532 std::string
getVersionString64(uint64_t ver
) const;
533 bool parsePackedVersion32(const std::string
& versionStr
, uint32_t &result
);
534 void parseSectionOrderFile(const char* segment
, const char* section
, const char* path
);
535 void parseOrderFile(const char* path
, bool cstring
);
536 void addSection(const char* segment
, const char* section
, const char* path
);
537 void addSubLibrary(const char* name
);
538 void loadFileList(const char* fileOfPaths
, ld::File::Ordinal baseOrdinal
);
539 uint64_t parseAddress(const char* addr
);
540 void loadExportFile(const char* fileOfExports
, const char* option
, SetWithWildcards
& set
);
541 void parseAliasFile(const char* fileOfAliases
);
542 void parsePreCommandLineEnvironmentSettings();
543 void parsePostCommandLineEnvironmentSettings();
544 void setUndefinedTreatment(const char* treatment
);
545 void setMacOSXVersionMin(const char* version
);
546 void setIOSVersionMin(const char* version
);
547 void setWatchOSVersionMin(const char* version
);
548 void setWeakReferenceMismatchTreatment(const char* treatment
);
549 void addDylibOverride(const char* paths
);
550 void addSectionAlignment(const char* segment
, const char* section
, const char* alignment
);
551 CommonsMode
parseCommonsTreatment(const char* mode
);
552 Treatment
parseTreatment(const char* treatment
);
553 void reconfigureDefaults();
554 void checkForClassic(int argc
, const char* argv
[]);
555 void parseSegAddrTable(const char* segAddrPath
, const char* installPath
);
556 void addLibrary(const FileInfo
& info
);
557 void warnObsolete(const char* arg
);
558 uint32_t parseProtection(const char* prot
);
559 void loadSymbolOrderFile(const char* fileOfExports
, NameToOrder
& orderMapping
);
560 void addSectionRename(const char* srcSegment
, const char* srcSection
, const char* dstSegment
, const char* dstSection
);
561 void addSegmentRename(const char* srcSegment
, const char* dstSegment
);
562 void addSymbolMove(const char* dstSegment
, const char* symbolList
, std::vector
<SymbolsMove
>& list
, const char* optionName
);
563 void cannotBeUsedWithBitcode(const char* arg
);
566 // ObjectFile::ReaderOptions fReaderOptions;
567 const char* fOutputFile
;
568 std::vector
<Options::FileInfo
> fInputFiles
;
569 cpu_type_t fArchitecture
;
570 cpu_subtype_t fSubArchitecture
;
571 const char* fArchitectureName
;
572 OutputKind fOutputKind
;
573 bool fHasPreferredSubType
;
574 bool fArchSupportsThumb2
;
577 bool fKeepPrivateExterns
;
578 bool fNeedsModuleTable
;
579 bool fIgnoreOtherArchFiles
;
580 bool fErrorOnOtherArchFiles
;
581 bool fForceSubtypeAll
;
582 InterposeMode fInterposeMode
;
584 NameSpace fNameSpace
;
585 uint32_t fDylibCompatVersion
;
586 uint64_t fDylibCurrentVersion
;
587 const char* fDylibInstallName
;
588 const char* fFinalName
;
589 const char* fEntryName
;
590 uint64_t fBaseAddress
;
591 uint64_t fMaxAddress
;
592 uint64_t fBaseWritableAddress
;
594 SetWithWildcards fExportSymbols
;
595 SetWithWildcards fDontExportSymbols
;
596 SetWithWildcards fInterposeList
;
597 SetWithWildcards fForceWeakSymbols
;
598 SetWithWildcards fForceNotWeakSymbols
;
599 SetWithWildcards fReExportSymbols
;
600 SetWithWildcards fForceCoalesceSymbols
;
601 NameSet fRemovedExports
;
602 NameToOrder fExportSymbolsOrder
;
603 ExportMode fExportMode
;
604 LibrarySearchMode fLibrarySearchMode
;
605 UndefinedTreatment fUndefinedTreatment
;
606 bool fMessagesPrefixedWithArchitecture
;
607 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment
;
608 std::vector
<const char*> fSubUmbellas
;
609 std::vector
<const char*> fSubLibraries
;
610 std::vector
<const char*> fAllowableClients
;
611 std::vector
<const char*> fRPaths
;
612 const char* fClientName
;
613 const char* fUmbrellaName
;
614 const char* fInitFunctionName
;
615 const char* fDotOutputFile
;
616 const char* fExecutablePath
;
617 const char* fBundleLoader
;
618 const char* fDtraceScriptName
;
619 const char* fSegAddrTablePath
;
620 const char* fMapPath
;
621 const char* fDyldInstallPath
;
622 const char* fLtoCachePath
;
623 int fLtoPruneInterval
;
625 unsigned fLtoMaxCacheSize
;
626 const char* fTempLtoObjectPath
;
627 const char* fOverridePathlibLTO
;
629 uint64_t fZeroPageSize
;
632 uint64_t fSourceVersion
;
633 uint32_t fSDKVersion
;
634 bool fExecutableStack
;
635 bool fNonExecutableHeap
;
636 bool fDisableNonExecutableHeap
;
637 uint32_t fMinimumHeaderPad
;
638 uint64_t fSegmentAlignment
;
639 CommonsMode fCommonsMode
;
640 enum UUIDMode fUUIDMode
;
641 SetWithWildcards fLocalSymbolsIncluded
;
642 SetWithWildcards fLocalSymbolsExcluded
;
643 LocalSymbolHandling fLocalSymbolHandling
;
646 bool fKeepRelocations
;
648 bool fTraceDylibSearching
;
652 bool fSharedRegionEligible
;
653 bool fSharedRegionEligibleForceOff
;
654 bool fPrintOrderFileStatistics
;
655 bool fReadOnlyx86Stubs
;
656 bool fPositionIndependentExecutable
;
657 bool fPIEOnCommandLine
;
658 bool fDisablePositionIndependentExecutable
;
659 bool fMaxMinimumHeaderPad
;
660 bool fDeadStripDylibs
;
661 bool fAllowTextRelocs
;
662 bool fWarnTextRelocs
;
664 bool fUsingLazyDylibLinking
;
666 bool fEncryptableForceOn
;
667 bool fEncryptableForceOff
;
669 bool fMarkDeadStrippableDylib
;
670 bool fMakeCompressedDyldInfo
;
671 bool fMakeCompressedDyldInfoForceOff
;
673 bool fAllowCpuSubtypeMismatches
;
674 bool fEnforceDylibSubtypesMatch
;
675 bool fUseSimplifiedDylibReExports
;
676 bool fObjCABIVersion2Override
;
677 bool fObjCABIVersion1Override
;
678 bool fCanUseUpwardDylib
;
679 bool fFullyLoadArchives
;
680 bool fLoadAllObjcObjectsFromArchives
;
682 bool fLinkingMainExecutable
;
683 bool fForFinalLinkedImage
;
686 bool fMakeTentativeDefinitionsReal
;
690 bool fImplicitlyLinkPublicDylibs
;
691 bool fAddCompactUnwindEncoding
;
692 bool fWarnCompactUnwind
;
693 bool fRemoveDwarfUnwindIfCompactExists
;
694 bool fAutoOrderInitializers
;
695 bool fOptimizeZeroFill
;
697 bool fLogObjectFiles
;
700 bool fTraceIndirectDylibs
;
703 bool fOutputSlidable
;
704 bool fWarnWeakExports
;
705 bool fObjcGcCompaction
;
710 bool fVersionLoadCommand
;
711 bool fVersionLoadCommandForcedOn
;
712 bool fVersionLoadCommandForcedOff
;
713 bool fFunctionStartsLoadCommand
;
714 bool fFunctionStartsForcedOn
;
715 bool fFunctionStartsForcedOff
;
716 bool fDataInCodeInfoLoadCommand
;
717 bool fDataInCodeInfoLoadCommandForcedOn
;
718 bool fDataInCodeInfoLoadCommandForcedOff
;
719 bool fCanReExportSymbols
;
720 bool fObjcCategoryMerging
;
721 bool fPageAlignDataAtoms
;
722 bool fNeedsThreadLoadCommand
;
723 bool fEntryPointLoadCommand
;
724 bool fEntryPointLoadCommandForceOn
;
725 bool fEntryPointLoadCommandForceOff
;
726 bool fSourceVersionLoadCommand
;
727 bool fSourceVersionLoadCommandForceOn
;
728 bool fSourceVersionLoadCommandForceOff
;
729 bool fTargetIOSSimulator
;
731 bool fAbsoluteSymbols
;
732 bool fAllowSimulatorToLinkWithMacOSX
;
733 bool fKeepDwarfUnwind
;
734 bool fKeepDwarfUnwindForcedOn
;
735 bool fKeepDwarfUnwindForcedOff
;
736 bool fVerboseOptimizationHints
;
737 bool fIgnoreOptimizationHints
;
738 bool fGenerateDtraceDOF
;
739 bool fAllowBranchIslands
;
740 bool fTraceSymbolLayout
;
741 bool fMarkAppExtensionSafe
;
742 bool fCheckAppExtensionSafe
;
743 bool fForceLoadSwiftLibs
;
744 bool fSharedRegionEncodingV2
;
745 bool fUseDataConstSegment
;
746 bool fUseDataConstSegmentForceOn
;
747 bool fUseDataConstSegmentForceOff
;
748 bool fUseTextExecSegment
;
752 bool fReverseMapUUIDRename
;
755 const char* fReverseMapPath
;
756 std::string fReverseMapTempPath
;
757 bool fLTOCodegenOnly
;
758 bool fIgnoreAutoLink
;
760 bool fAllowWeakImports
;
761 BitcodeMode fBitcodeKind
;
763 DebugInfoStripping fDebugInfoStripping
;
764 const char* fTraceOutputFile
;
765 ld::MacVersionMin fMacVersionMin
;
766 ld::IOSVersionMin fIOSVersionMin
;
767 ld::WatchOSVersionMin fWatchOSVersionMin
;
768 std::vector
<AliasPair
> fAliases
;
769 std::vector
<const char*> fInitialUndefines
;
770 NameSet fAllowedUndefined
;
771 SetWithWildcards fWhyLive
;
772 std::vector
<ExtraSection
> fExtraSections
;
773 std::vector
<SectionAlignment
> fSectionAlignments
;
774 std::vector
<OrderedSymbol
> fOrderedSymbols
;
775 std::vector
<SegmentStart
> fCustomSegmentAddresses
;
776 std::vector
<SegmentSize
> fCustomSegmentSizes
;
777 std::vector
<SegmentProtect
> fCustomSegmentProtections
;
778 std::vector
<DylibOverride
> fDylibOverrides
;
779 std::vector
<const char*> fLLVMOptions
;
780 std::vector
<const char*> fLibrarySearchPaths
;
781 std::vector
<const char*> fFrameworkSearchPaths
;
782 std::vector
<const char*> fSDKPaths
;
783 std::vector
<const char*> fDyldEnvironExtras
;
784 std::vector
<const char*> fSegmentOrder
;
785 std::vector
<const char*> fASTFilePaths
;
786 std::vector
<SectionOrderList
> fSectionOrder
;
787 std::vector
< std::vector
<const char*> > fLinkerOptions
;
788 std::vector
<SectionRename
> fSectionRenames
;
789 std::vector
<SegmentRename
> fSegmentRenames
;
790 std::vector
<SymbolsMove
> fSymbolsMovesData
;
791 std::vector
<SymbolsMove
> fSymbolsMovesCode
;
793 mutable Snapshot fLinkSnapshot
;
794 bool fSnapshotRequested
;
795 const char* fPipelineFifo
;
796 const char* fDependencyInfoPath
;
797 mutable int fDependencyFileDescriptor
;
798 uint8_t fMaxDefaultCommonAlign
;
803 #endif // __OPTIONS__