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 // Create an empty FileInfo. The path can be set implicitly by checkFileExists().
151 FileInfo() : path(NULL
), fileLen(0), modTime(0), options(), fromFileList(false) {};
153 // Create a FileInfo for a specific path, but does not stat the file.
154 FileInfo(const char *_path
) : path(strdup(_path
)), fileLen(0), modTime(0), options(), fromFileList(false) {};
156 ~FileInfo() { if (path
) ::free((void*)path
); }
158 // Stat the file and update fileLen and modTime.
159 // If the object already has a path the p must be NULL.
160 // 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.
161 // Returns true if the file exists, false if not.
162 bool checkFileExists(const Options
& options
, const char *p
=NULL
);
164 // Returns true if a previous call to checkFileExists() succeeded.
165 // Returns false if the file does not exist of checkFileExists() has never been called.
166 bool missing() const { return modTime
==0; }
169 struct ExtraSection
{
170 const char* segmentName
;
171 const char* sectionName
;
175 typedef ExtraSection
* iterator
;
176 typedef const ExtraSection
* const_iterator
;
179 struct SectionAlignment
{
180 const char* segmentName
;
181 const char* sectionName
;
185 struct SectionOrderList
{
186 const char* segmentName
;
187 std::vector
<const char*> sectionOrder
;
190 struct OrderedSymbol
{
191 const char* symbolName
;
192 const char* objectFileName
;
194 typedef const OrderedSymbol
* OrderedSymbolsIterator
;
196 struct SegmentStart
{
206 struct SegmentProtect
{
212 struct DylibOverride
{
213 const char* installName
;
214 const char* useInstead
;
218 const char* realName
;
222 struct SectionRename
{
223 const char* fromSegment
;
224 const char* fromSection
;
225 const char* toSegment
;
226 const char* toSection
;
229 struct SegmentRename
{
230 const char* fromSegment
;
231 const char* toSegment
;
234 enum { depLinkerVersion
=0x00, depObjectFile
=0x10, depDirectDylib
=0x10, depIndirectDylib
=0x10,
235 depUpwardDirectDylib
=0x10, depUpwardIndirectDylib
=0x10, depArchive
=0x10,
236 depFileList
=0x10, depSection
=0x10, depBundleLoader
=0x10, depMisc
=0x10, depNotFound
=0x11,
237 depOutputFile
= 0x40 };
239 void dumpDependency(uint8_t, const char* path
) const;
241 typedef const char* const* UndefinesIterator
;
243 // const ObjectFile::ReaderOptions& readerOptions();
244 const char* outputFilePath() const { return fOutputFile
; }
245 const std::vector
<FileInfo
>& getInputFiles() const { return fInputFiles
; }
247 cpu_type_t
architecture() const { return fArchitecture
; }
248 bool preferSubArchitecture() const { return fHasPreferredSubType
; }
249 cpu_subtype_t
subArchitecture() const { return fSubArchitecture
; }
250 bool allowSubArchitectureMismatches() const { return fAllowCpuSubtypeMismatches
; }
251 bool forceCpuSubtypeAll() const { return fForceSubtypeAll
; }
252 const char* architectureName() const { return fArchitectureName
; }
253 void setArchitecture(cpu_type_t
, cpu_subtype_t subtype
, Options::Platform platform
);
254 bool archSupportsThumb2() const { return fArchSupportsThumb2
; }
255 OutputKind
outputKind() const { return fOutputKind
; }
256 bool prebind() const { return fPrebind
; }
257 bool bindAtLoad() const { return fBindAtLoad
; }
258 NameSpace
nameSpace() const { return fNameSpace
; }
259 const char* installPath() const; // only for kDynamicLibrary
260 uint64_t currentVersion() const { return fDylibCurrentVersion
; } // only for kDynamicLibrary
261 uint32_t currentVersion32() const; // only for kDynamicLibrary
262 uint32_t compatibilityVersion() const { return fDylibCompatVersion
; } // only for kDynamicLibrary
263 const char* entryName() const { return fEntryName
; } // only for kDynamicExecutable or kStaticExecutable
264 const char* executablePath();
265 uint64_t baseAddress() const { return fBaseAddress
; }
266 uint64_t maxAddress() const { return fMaxAddress
; }
267 bool keepPrivateExterns() const { return fKeepPrivateExterns
; } // only for kObjectFile
268 bool needsModuleTable() const { return fNeedsModuleTable
; } // only for kDynamicLibrary
269 bool interposable(const char* name
) const;
270 bool hasExportRestrictList() const { return (fExportMode
!= kExportDefault
); } // -exported_symbol or -unexported_symbol
271 bool hasExportMaskList() const { return (fExportMode
== kExportSome
); } // just -exported_symbol
272 bool hasWildCardExportRestrictList() const;
273 bool hasReExportList() const { return ! fReExportSymbols
.empty(); }
274 bool wasRemovedExport(const char* sym
) const { return ( fRemovedExports
.find(sym
) != fRemovedExports
.end() ); }
275 bool allGlobalsAreDeadStripRoots() const;
276 bool shouldExport(const char*) const;
277 bool shouldReExport(const char*) const;
278 std::vector
<const char*> exportsData() const;
279 bool ignoreOtherArchInputFiles() const { return fIgnoreOtherArchFiles
; }
280 bool traceDylibs() const { return fTraceDylibs
; }
281 bool traceArchives() const { return fTraceArchives
; }
282 bool deadCodeStrip() const { return fDeadStrip
; }
283 UndefinedTreatment
undefinedTreatment() const { return fUndefinedTreatment
; }
284 ld::MacVersionMin
macosxVersionMin() const { return fMacVersionMin
; }
285 ld::IOSVersionMin
iOSVersionMin() const { return fIOSVersionMin
; }
286 ld::WatchOSVersionMin
watchOSVersionMin() const { return fWatchOSVersionMin
; }
287 uint32_t minOSversion() const;
288 bool minOS(ld::MacVersionMin mac
, ld::IOSVersionMin iPhoneOS
);
289 bool min_iOS(ld::IOSVersionMin requirediOSMin
);
290 bool messagesPrefixedWithArchitecture();
291 Treatment
picTreatment();
292 WeakReferenceMismatchTreatment
weakReferenceMismatchTreatment() const { return fWeakReferenceMismatchTreatment
; }
293 const char* umbrellaName() const { return fUmbrellaName
; }
294 const std::vector
<const char*>& allowableClients() const { return fAllowableClients
; }
295 const char* clientName() const { return fClientName
; }
296 const char* initFunctionName() const { return fInitFunctionName
; } // only for kDynamicLibrary
297 const char* dotOutputFile();
298 uint64_t pageZeroSize() const { return fZeroPageSize
; }
299 bool hasCustomStack() const { return (fStackSize
!= 0); }
300 uint64_t customStackSize() const { return fStackSize
; }
301 uint64_t customStackAddr() const { return fStackAddr
; }
302 bool hasExecutableStack() const { return fExecutableStack
; }
303 bool hasNonExecutableHeap() const { return fNonExecutableHeap
; }
304 UndefinesIterator
initialUndefinesBegin() const { return &fInitialUndefines
[0]; }
305 UndefinesIterator
initialUndefinesEnd() const { return &fInitialUndefines
[fInitialUndefines
.size()]; }
306 const std::vector
<const char*>& initialUndefines() const { return fInitialUndefines
; }
307 bool printWhyLive(const char* name
) const;
308 uint32_t minimumHeaderPad() const { return fMinimumHeaderPad
; }
309 bool maxMminimumHeaderPad() const { return fMaxMinimumHeaderPad
; }
310 ExtraSection::const_iterator
extraSectionsBegin() const { return &fExtraSections
[0]; }
311 ExtraSection::const_iterator
extraSectionsEnd() const { return &fExtraSections
[fExtraSections
.size()]; }
312 CommonsMode
commonsMode() const { return fCommonsMode
; }
313 bool warnCommons() const { return fWarnCommons
; }
314 bool keepRelocations();
315 FileInfo
findFile(const std::string
&path
) const;
316 UUIDMode
UUIDMode() const { return fUUIDMode
; }
318 bool pauseAtEnd() { return fPause
; }
319 bool printStatistics() const { return fStatistics
; }
320 bool printArchPrefix() const { return fMessagesPrefixedWithArchitecture
; }
321 void gotoClassicLinker(int argc
, const char* argv
[]);
322 bool sharedRegionEligible() const { return fSharedRegionEligible
; }
323 bool printOrderFileStatistics() const { return fPrintOrderFileStatistics
; }
324 const char* dTraceScriptName() { return fDtraceScriptName
; }
325 bool dTrace() { return (fDtraceScriptName
!= NULL
); }
326 unsigned long orderedSymbolsCount() const { return fOrderedSymbols
.size(); }
327 OrderedSymbolsIterator
orderedSymbolsBegin() const { return &fOrderedSymbols
[0]; }
328 OrderedSymbolsIterator
orderedSymbolsEnd() const { return &fOrderedSymbols
[fOrderedSymbols
.size()]; }
329 bool splitSeg() const { return fSplitSegs
; }
330 uint64_t baseWritableAddress() { return fBaseWritableAddress
; }
331 uint64_t segmentAlignment() const { return fSegmentAlignment
; }
332 uint64_t segPageSize(const char* segName
) const;
333 uint64_t customSegmentAddress(const char* segName
) const;
334 bool hasCustomSegmentAddress(const char* segName
) const;
335 bool hasCustomSectionAlignment(const char* segName
, const char* sectName
) const;
336 uint8_t customSectionAlignment(const char* segName
, const char* sectName
) const;
337 uint32_t initialSegProtection(const char*) const;
338 uint32_t maxSegProtection(const char*) const;
339 bool saveTempFiles() const { return fSaveTempFiles
; }
340 const std::vector
<const char*>& rpaths() const { return fRPaths
; }
341 bool readOnlyx86Stubs() { return fReadOnlyx86Stubs
; }
342 const std::vector
<DylibOverride
>& dylibOverrides() const { return fDylibOverrides
; }
343 const char* generatedMapPath() const { return fMapPath
; }
344 bool positionIndependentExecutable() const { return fPositionIndependentExecutable
; }
345 Options::FileInfo
findFileUsingPaths(const std::string
&path
) const;
346 bool deadStripDylibs() const { return fDeadStripDylibs
; }
347 bool allowedUndefined(const char* name
) const { return ( fAllowedUndefined
.find(name
) != fAllowedUndefined
.end() ); }
348 bool someAllowedUndefines() const { return (fAllowedUndefined
.size() != 0); }
349 LocalSymbolHandling
localSymbolHandling() { return fLocalSymbolHandling
; }
350 bool keepLocalSymbol(const char* symbolName
) const;
351 bool allowTextRelocs() const { return fAllowTextRelocs
; }
352 bool warnAboutTextRelocs() const { return fWarnTextRelocs
; }
353 bool kextsUseStubs() const { return fKextsUseStubs
; }
354 bool usingLazyDylibLinking() const { return fUsingLazyDylibLinking
; }
355 bool verbose() const { return fVerbose
; }
356 bool makeEncryptable() const { return fEncryptable
; }
357 bool needsUnwindInfoSection() const { return fAddCompactUnwindEncoding
; }
358 const std::vector
<const char*>& llvmOptions() const{ return fLLVMOptions
; }
359 const std::vector
<const char*>& segmentOrder() const{ return fSegmentOrder
; }
360 bool segmentOrderAfterFixedAddressSegment(const char* segName
) const;
361 const std::vector
<const char*>* sectionOrder(const char* segName
) const;
362 const std::vector
<const char*>& dyldEnvironExtras() const{ return fDyldEnvironExtras
; }
363 const std::vector
<const char*>& astFilePaths() const{ return fASTFilePaths
; }
364 bool makeCompressedDyldInfo() const { return fMakeCompressedDyldInfo
; }
365 bool hasExportedSymbolOrder();
366 bool exportedSymbolOrder(const char* sym
, unsigned int* order
) const;
367 bool orderData() { return fOrderData
; }
368 bool errorOnOtherArchFiles() const { return fErrorOnOtherArchFiles
; }
369 bool markAutoDeadStripDylib() const { return fMarkDeadStrippableDylib
; }
370 bool removeEHLabels() const { return fNoEHLabels
; }
371 bool useSimplifiedDylibReExports() const { return fUseSimplifiedDylibReExports
; }
372 bool objCABIVersion2POverride() const { return fObjCABIVersion2Override
; }
373 bool useUpwardDylibs() const { return fCanUseUpwardDylib
; }
374 bool fullyLoadArchives() const { return fFullyLoadArchives
; }
375 bool loadAllObjcObjectsFromArchives() const { return fLoadAllObjcObjectsFromArchives
; }
376 bool autoOrderInitializers() const { return fAutoOrderInitializers
; }
377 bool optimizeZeroFill() const { return fOptimizeZeroFill
; }
378 bool mergeZeroFill() const { return fMergeZeroFill
; }
379 bool logAllFiles() const { return fLogAllFiles
; }
380 DebugInfoStripping
debugInfoStripping() const { return fDebugInfoStripping
; }
381 bool flatNamespace() const { return fFlatNamespace
; }
382 bool linkingMainExecutable() const { return fLinkingMainExecutable
; }
383 bool implicitlyLinkIndirectPublicDylibs() const { return fImplicitlyLinkPublicDylibs
; }
384 bool whyLoad() const { return fWhyLoad
; }
385 const char* traceOutputFile() const { return fTraceOutputFile
; }
386 bool outputSlidable() const { return fOutputSlidable
; }
387 bool haveCmdLineAliases() const { return (fAliases
.size() != 0); }
388 const std::vector
<AliasPair
>& cmdLineAliases() const { return fAliases
; }
389 bool makeTentativeDefinitionsReal() const { return fMakeTentativeDefinitionsReal
; }
390 const char* dyldInstallPath() const { return fDyldInstallPath
; }
391 bool warnWeakExports() const { return fWarnWeakExports
; }
392 bool objcGcCompaction() const { return fObjcGcCompaction
; }
393 bool objcGc() const { return fObjCGc
; }
394 bool objcGcOnly() const { return fObjCGcOnly
; }
395 bool canUseThreadLocalVariables() const { return fTLVSupport
; }
396 bool addVersionLoadCommand() const { return fVersionLoadCommand
&& (fPlatform
!= kPlatformUnknown
); }
397 bool addFunctionStarts() const { return fFunctionStartsLoadCommand
; }
398 bool addDataInCodeInfo() const { return fDataInCodeInfoLoadCommand
; }
399 bool canReExportSymbols() const { return fCanReExportSymbols
; }
400 const char* tempLtoObjectPath() const { return fTempLtoObjectPath
; }
401 const char* overridePathlibLTO() const { return fOverridePathlibLTO
; }
402 const char* mcpuLTO() const { return fLtoCpu
; }
403 bool objcCategoryMerging() const { return fObjcCategoryMerging
; }
404 bool pageAlignDataAtoms() const { return fPageAlignDataAtoms
; }
405 bool keepDwarfUnwind() const { return fKeepDwarfUnwind
; }
406 bool verboseOptimizationHints() const { return fVerboseOptimizationHints
; }
407 bool ignoreOptimizationHints() const { return fIgnoreOptimizationHints
; }
408 bool generateDtraceDOF() const { return fGenerateDtraceDOF
; }
409 bool allowBranchIslands() const { return fAllowBranchIslands
; }
410 bool traceSymbolLayout() const { return fTraceSymbolLayout
; }
411 bool markAppExtensionSafe() const { return fMarkAppExtensionSafe
; }
412 bool checkDylibsAreAppExtensionSafe() const { return fCheckAppExtensionSafe
; }
413 bool forceLoadSwiftLibs() const { return fForceLoadSwiftLibs
; }
414 bool bundleBitcode() const { return fBundleBitcode
; }
415 bool hideSymbols() const { return fHideSymbols
; }
416 bool verifyBitcode() const { return fVerifyBitcode
; }
417 bool renameReverseSymbolMap() const { return fReverseMapUUIDRename
; }
418 const char* reverseSymbolMapPath() const { return fReverseMapPath
; }
419 std::string
reverseMapTempPath() const { return fReverseMapTempPath
; }
420 bool ltoCodegenOnly() const { return fLTOCodegenOnly
; }
421 bool ignoreAutoLink() const { return fIgnoreAutoLink
; }
422 bool allowDeadDuplicates() const { return fAllowDeadDups
; }
423 BitcodeMode
bitcodeKind() const { return fBitcodeKind
; }
424 bool sharedRegionEncodingV2() const { return fSharedRegionEncodingV2
; }
425 bool useDataConstSegment() const { return fUseDataConstSegment
; }
426 bool hasWeakBitTweaks() const;
427 bool forceWeak(const char* symbolName
) const;
428 bool forceNotWeak(const char* symbolName
) const;
429 bool forceWeakNonWildCard(const char* symbolName
) const;
430 bool forceNotWeakNonWildcard(const char* symbolName
) const;
431 bool forceCoalesce(const char* symbolName
) const;
432 Snapshot
& snapshot() const { return fLinkSnapshot
; }
433 bool errorBecauseOfWarnings() const;
434 bool needsThreadLoadCommand() const { return fNeedsThreadLoadCommand
; }
435 bool needsEntryPointLoadCommand() const { return fEntryPointLoadCommand
; }
436 bool needsSourceVersionLoadCommand() const { return fSourceVersionLoadCommand
; }
437 bool canUseAbsoluteSymbols() const { return fAbsoluteSymbols
; }
438 bool allowSimulatorToLinkWithMacOSX() const { return fAllowSimulatorToLinkWithMacOSX
; }
439 uint64_t sourceVersion() const { return fSourceVersion
; }
440 uint32_t sdkVersion() const { return fSDKVersion
; }
441 const char* demangleSymbol(const char* sym
) const;
442 bool pipelineEnabled() const { return fPipelineFifo
!= NULL
; }
443 const char* pipelineFifo() const { return fPipelineFifo
; }
444 bool dumpDependencyInfo() const { return (fDependencyInfoPath
!= NULL
); }
445 const char* dependencyInfoPath() const { return fDependencyInfoPath
; }
446 bool targetIOSSimulator() const { return fTargetIOSSimulator
; }
447 ld::relocatable::File::LinkerOptionsList
&
448 linkerOptions() const { return fLinkerOptions
; }
449 FileInfo
findFramework(const char* frameworkName
) const;
450 FileInfo
findLibrary(const char* rootName
, bool dylibsOnly
=false) const;
451 bool armUsesZeroCostExceptions() const;
452 const std::vector
<SectionRename
>& sectionRenames() const { return fSectionRenames
; }
453 const std::vector
<SegmentRename
>& segmentRenames() const { return fSegmentRenames
; }
454 bool moveRoSymbol(const char* symName
, const char* filePath
, const char*& seg
, bool& wildCardMatch
) const;
455 bool moveRwSymbol(const char* symName
, const char* filePath
, const char*& seg
, bool& wildCardMatch
) const;
456 Platform
platform() const { return fPlatform
; }
457 const std::vector
<const char*>& sdkPaths() const { return fSDKPaths
; }
458 std::vector
<std::string
> writeBitcodeLinkOptions() const;
459 std::string
getSDKVersionStr() const;
460 std::string
getPlatformStr() const;
463 typedef std::unordered_map
<const char*, unsigned int, ld::CStringHash
, ld::CStringEquals
> NameToOrder
;
464 typedef std::unordered_set
<const char*, ld::CStringHash
, ld::CStringEquals
> NameSet
;
465 enum ExportMode
{ kExportDefault
, kExportSome
, kDontExportSome
};
466 enum LibrarySearchMode
{ kSearchDylibAndArchiveInEachDir
, kSearchAllDirsForDylibsThenAllDirsForArchives
};
467 enum InterposeMode
{ kInterposeNone
, kInterposeAllExternal
, kInterposeSome
};
469 class SetWithWildcards
{
471 void insert(const char*);
472 bool contains(const char*, bool* wildCardMatch
=NULL
) const;
473 bool containsWithPrefix(const char* symbol
, const char* file
, bool& wildCardMatch
) const;
474 bool containsNonWildcard(const char*) const;
475 bool empty() const { return fRegular
.empty() && fWildCard
.empty(); }
476 bool hasWildCards() const { return !fWildCard
.empty(); }
477 NameSet::iterator
regularBegin() const { return fRegular
.begin(); }
478 NameSet::iterator
regularEnd() const { return fRegular
.end(); }
479 void remove(const NameSet
&);
480 std::vector
<const char*> data() const;
482 static bool hasWildCards(const char*);
483 bool wildCardMatch(const char* pattern
, const char* candidate
) const;
484 bool inCharRange(const char*& range
, unsigned char c
) const;
487 std::vector
<const char*> fWildCard
;
491 const char* toSegment
;
492 SetWithWildcards symbols
;
495 void parse(int argc
, const char* argv
[]);
496 void checkIllegalOptionCombinations();
497 void buildSearchPaths(int argc
, const char* argv
[]);
498 void parseArch(const char* architecture
);
499 FileInfo
findFramework(const char* rootName
, const char* suffix
) const;
500 bool checkForFile(const char* format
, const char* dir
, const char* rootName
,
501 FileInfo
& result
) const;
502 uint64_t parseVersionNumber64(const char*);
503 uint32_t parseVersionNumber32(const char*);
504 std::string
getVersionString32(uint32_t ver
) const;
505 std::string
getVersionString64(uint64_t ver
) const;
506 void parseSectionOrderFile(const char* segment
, const char* section
, const char* path
);
507 void parseOrderFile(const char* path
, bool cstring
);
508 void addSection(const char* segment
, const char* section
, const char* path
);
509 void addSubLibrary(const char* name
);
510 void loadFileList(const char* fileOfPaths
, ld::File::Ordinal baseOrdinal
);
511 uint64_t parseAddress(const char* addr
);
512 void loadExportFile(const char* fileOfExports
, const char* option
, SetWithWildcards
& set
);
513 void parseAliasFile(const char* fileOfAliases
);
514 void parsePreCommandLineEnvironmentSettings();
515 void parsePostCommandLineEnvironmentSettings();
516 void setUndefinedTreatment(const char* treatment
);
517 void setMacOSXVersionMin(const char* version
);
518 void setIOSVersionMin(const char* version
);
519 void setWatchOSVersionMin(const char* version
);
520 void setWeakReferenceMismatchTreatment(const char* treatment
);
521 void addDylibOverride(const char* paths
);
522 void addSectionAlignment(const char* segment
, const char* section
, const char* alignment
);
523 CommonsMode
parseCommonsTreatment(const char* mode
);
524 Treatment
parseTreatment(const char* treatment
);
525 void reconfigureDefaults();
526 void checkForClassic(int argc
, const char* argv
[]);
527 void parseSegAddrTable(const char* segAddrPath
, const char* installPath
);
528 void addLibrary(const FileInfo
& info
);
529 void warnObsolete(const char* arg
);
530 uint32_t parseProtection(const char* prot
);
531 void loadSymbolOrderFile(const char* fileOfExports
, NameToOrder
& orderMapping
);
532 void addSectionRename(const char* srcSegment
, const char* srcSection
, const char* dstSegment
, const char* dstSection
);
533 void addSegmentRename(const char* srcSegment
, const char* dstSegment
);
534 void addSymbolMove(const char* dstSegment
, const char* symbolList
, std::vector
<SymbolsMove
>& list
, const char* optionName
);
535 void cannotBeUsedWithBitcode(const char* arg
);
538 // ObjectFile::ReaderOptions fReaderOptions;
539 const char* fOutputFile
;
540 std::vector
<Options::FileInfo
> fInputFiles
;
541 cpu_type_t fArchitecture
;
542 cpu_subtype_t fSubArchitecture
;
543 const char* fArchitectureName
;
544 OutputKind fOutputKind
;
545 bool fHasPreferredSubType
;
546 bool fArchSupportsThumb2
;
549 bool fKeepPrivateExterns
;
550 bool fNeedsModuleTable
;
551 bool fIgnoreOtherArchFiles
;
552 bool fErrorOnOtherArchFiles
;
553 bool fForceSubtypeAll
;
554 InterposeMode fInterposeMode
;
556 NameSpace fNameSpace
;
557 uint32_t fDylibCompatVersion
;
558 uint64_t fDylibCurrentVersion
;
559 const char* fDylibInstallName
;
560 const char* fFinalName
;
561 const char* fEntryName
;
562 uint64_t fBaseAddress
;
563 uint64_t fMaxAddress
;
564 uint64_t fBaseWritableAddress
;
566 SetWithWildcards fExportSymbols
;
567 SetWithWildcards fDontExportSymbols
;
568 SetWithWildcards fInterposeList
;
569 SetWithWildcards fForceWeakSymbols
;
570 SetWithWildcards fForceNotWeakSymbols
;
571 SetWithWildcards fReExportSymbols
;
572 SetWithWildcards fForceCoalesceSymbols
;
573 NameSet fRemovedExports
;
574 NameToOrder fExportSymbolsOrder
;
575 ExportMode fExportMode
;
576 LibrarySearchMode fLibrarySearchMode
;
577 UndefinedTreatment fUndefinedTreatment
;
578 bool fMessagesPrefixedWithArchitecture
;
579 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment
;
580 std::vector
<const char*> fSubUmbellas
;
581 std::vector
<const char*> fSubLibraries
;
582 std::vector
<const char*> fAllowableClients
;
583 std::vector
<const char*> fRPaths
;
584 const char* fClientName
;
585 const char* fUmbrellaName
;
586 const char* fInitFunctionName
;
587 const char* fDotOutputFile
;
588 const char* fExecutablePath
;
589 const char* fBundleLoader
;
590 const char* fDtraceScriptName
;
591 const char* fSegAddrTablePath
;
592 const char* fMapPath
;
593 const char* fDyldInstallPath
;
594 const char* fTempLtoObjectPath
;
595 const char* fOverridePathlibLTO
;
597 uint64_t fZeroPageSize
;
600 uint64_t fSourceVersion
;
601 uint32_t fSDKVersion
;
602 bool fExecutableStack
;
603 bool fNonExecutableHeap
;
604 bool fDisableNonExecutableHeap
;
605 uint32_t fMinimumHeaderPad
;
606 uint64_t fSegmentAlignment
;
607 CommonsMode fCommonsMode
;
608 enum UUIDMode fUUIDMode
;
609 SetWithWildcards fLocalSymbolsIncluded
;
610 SetWithWildcards fLocalSymbolsExcluded
;
611 LocalSymbolHandling fLocalSymbolHandling
;
614 bool fKeepRelocations
;
616 bool fTraceDylibSearching
;
620 bool fSharedRegionEligible
;
621 bool fSharedRegionEligibleForceOff
;
622 bool fPrintOrderFileStatistics
;
623 bool fReadOnlyx86Stubs
;
624 bool fPositionIndependentExecutable
;
625 bool fPIEOnCommandLine
;
626 bool fDisablePositionIndependentExecutable
;
627 bool fMaxMinimumHeaderPad
;
628 bool fDeadStripDylibs
;
629 bool fAllowTextRelocs
;
630 bool fWarnTextRelocs
;
632 bool fUsingLazyDylibLinking
;
634 bool fEncryptableForceOn
;
635 bool fEncryptableForceOff
;
637 bool fMarkDeadStrippableDylib
;
638 bool fMakeCompressedDyldInfo
;
639 bool fMakeCompressedDyldInfoForceOff
;
641 bool fAllowCpuSubtypeMismatches
;
642 bool fUseSimplifiedDylibReExports
;
643 bool fObjCABIVersion2Override
;
644 bool fObjCABIVersion1Override
;
645 bool fCanUseUpwardDylib
;
646 bool fFullyLoadArchives
;
647 bool fLoadAllObjcObjectsFromArchives
;
649 bool fLinkingMainExecutable
;
650 bool fForFinalLinkedImage
;
653 bool fMakeTentativeDefinitionsReal
;
657 bool fImplicitlyLinkPublicDylibs
;
658 bool fAddCompactUnwindEncoding
;
659 bool fWarnCompactUnwind
;
660 bool fRemoveDwarfUnwindIfCompactExists
;
661 bool fAutoOrderInitializers
;
662 bool fOptimizeZeroFill
;
664 bool fLogObjectFiles
;
667 bool fTraceIndirectDylibs
;
669 bool fOutputSlidable
;
670 bool fWarnWeakExports
;
671 bool fObjcGcCompaction
;
676 bool fVersionLoadCommand
;
677 bool fVersionLoadCommandForcedOn
;
678 bool fVersionLoadCommandForcedOff
;
679 bool fFunctionStartsLoadCommand
;
680 bool fFunctionStartsForcedOn
;
681 bool fFunctionStartsForcedOff
;
682 bool fDataInCodeInfoLoadCommand
;
683 bool fDataInCodeInfoLoadCommandForcedOn
;
684 bool fDataInCodeInfoLoadCommandForcedOff
;
685 bool fCanReExportSymbols
;
686 bool fObjcCategoryMerging
;
687 bool fPageAlignDataAtoms
;
688 bool fNeedsThreadLoadCommand
;
689 bool fEntryPointLoadCommand
;
690 bool fEntryPointLoadCommandForceOn
;
691 bool fEntryPointLoadCommandForceOff
;
692 bool fSourceVersionLoadCommand
;
693 bool fSourceVersionLoadCommandForceOn
;
694 bool fSourceVersionLoadCommandForceOff
;
695 bool fTargetIOSSimulator
;
697 bool fAbsoluteSymbols
;
698 bool fAllowSimulatorToLinkWithMacOSX
;
699 bool fKeepDwarfUnwind
;
700 bool fKeepDwarfUnwindForcedOn
;
701 bool fKeepDwarfUnwindForcedOff
;
702 bool fVerboseOptimizationHints
;
703 bool fIgnoreOptimizationHints
;
704 bool fGenerateDtraceDOF
;
705 bool fAllowBranchIslands
;
706 bool fTraceSymbolLayout
;
707 bool fMarkAppExtensionSafe
;
708 bool fCheckAppExtensionSafe
;
709 bool fForceLoadSwiftLibs
;
710 bool fSharedRegionEncodingV2
;
711 bool fUseDataConstSegment
;
712 bool fUseDataConstSegmentForceOn
;
713 bool fUseDataConstSegmentForceOff
;
717 bool fReverseMapUUIDRename
;
718 const char* fReverseMapPath
;
719 std::string fReverseMapTempPath
;
720 bool fLTOCodegenOnly
;
721 bool fIgnoreAutoLink
;
723 BitcodeMode fBitcodeKind
;
725 DebugInfoStripping fDebugInfoStripping
;
726 const char* fTraceOutputFile
;
727 ld::MacVersionMin fMacVersionMin
;
728 ld::IOSVersionMin fIOSVersionMin
;
729 ld::WatchOSVersionMin fWatchOSVersionMin
;
730 std::vector
<AliasPair
> fAliases
;
731 std::vector
<const char*> fInitialUndefines
;
732 NameSet fAllowedUndefined
;
733 SetWithWildcards fWhyLive
;
734 std::vector
<ExtraSection
> fExtraSections
;
735 std::vector
<SectionAlignment
> fSectionAlignments
;
736 std::vector
<OrderedSymbol
> fOrderedSymbols
;
737 std::vector
<SegmentStart
> fCustomSegmentAddresses
;
738 std::vector
<SegmentSize
> fCustomSegmentSizes
;
739 std::vector
<SegmentProtect
> fCustomSegmentProtections
;
740 std::vector
<DylibOverride
> fDylibOverrides
;
741 std::vector
<const char*> fLLVMOptions
;
742 std::vector
<const char*> fLibrarySearchPaths
;
743 std::vector
<const char*> fFrameworkSearchPaths
;
744 std::vector
<const char*> fSDKPaths
;
745 std::vector
<const char*> fDyldEnvironExtras
;
746 std::vector
<const char*> fSegmentOrder
;
747 std::vector
<const char*> fASTFilePaths
;
748 std::vector
<SectionOrderList
> fSectionOrder
;
749 std::vector
< std::vector
<const char*> > fLinkerOptions
;
750 std::vector
<SectionRename
> fSectionRenames
;
751 std::vector
<SegmentRename
> fSegmentRenames
;
752 std::vector
<SymbolsMove
> fSymbolsMovesData
;
753 std::vector
<SymbolsMove
> fSymbolsMovesCode
;
754 std::vector
<SymbolsMove
> fSymbolsMovesZeroFill
;
756 mutable Snapshot fLinkSnapshot
;
757 bool fSnapshotRequested
;
758 const char* fPipelineFifo
;
759 const char* fDependencyInfoPath
;
760 mutable int fDependencyFileDescriptor
;
765 #endif // __OPTIONS__