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