264.3.102
[darwin-xtools.git] / ld64 / src / ld / Options.h
blob5155de4ad876f5d13b177331c0cb1509677d8938
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
12 * file.
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@
25 #ifndef __OPTIONS__
26 #define __OPTIONS__
29 #include <stdint.h>
30 #include <mach/machine.h>
32 #include <vector>
33 #include <unordered_set>
34 #include <unordered_map>
36 #include "ld.hpp"
37 #include "Snapshot.h"
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)));
43 class Snapshot;
45 class LibraryOptions
47 public:
48 LibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false),
49 fLazyLoad(false), fUpward(false), fIndirectDylib(false),
50 fForceLoad(false) {}
51 // for dynamic libraries
52 bool fWeakImport;
53 bool fReExport;
54 bool fBundleLoader;
55 bool fLazyLoad;
56 bool fUpward;
57 bool fIndirectDylib;
58 // for static libraries
59 bool fForceLoad;
65 // The public interface to the Options class is the abstract representation of what work the linker
66 // should do.
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).
73 class Options
75 public:
76 Options(int argc, const char* argv[]);
77 ~Options();
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 };
91 #if SUPPORT_APPLE_TV
92 enum Platform { kPlatformUnknown, kPlatformOSX, kPlatformiOS, kPlatformWatchOS, kPlatform_tvOS };
93 #else
94 enum Platform { kPlatformUnknown, kPlatformOSX, kPlatformiOS, kPlatformWatchOS };
95 #endif
97 static Platform platformForLoadCommand(uint32_t lc) {
98 switch (lc) {
99 case LC_VERSION_MIN_MACOSX:
100 return kPlatformOSX;
101 case LC_VERSION_MIN_IPHONEOS:
102 return kPlatformiOS;
103 case LC_VERSION_MIN_WATCHOS:
104 return kPlatformWatchOS;
105 #if SUPPORT_APPLE_TV
106 case LC_VERSION_MIN_TVOS:
107 return kPlatform_tvOS;
108 #endif
110 assert(!lc && "unknown LC_VERSION_MIN load command");
111 return kPlatformUnknown;
114 static const char* platformName(Platform platform) {
115 switch (platform) {
116 case kPlatformOSX:
117 return "OSX";
118 case kPlatformiOS:
119 return "iOS";
120 case kPlatformWatchOS:
121 return "watchOS";
122 #if SUPPORT_APPLE_TV
123 case kPlatform_tvOS:
124 return "tvOS";
125 #endif
126 case kPlatformUnknown:
127 default:
128 return "(unknown)";
132 class FileInfo {
133 public:
134 const char* path;
135 uint64_t fileLen;
136 time_t modTime;
137 LibraryOptions options;
138 ld::File::Ordinal ordinal;
139 bool fromFileList;
141 // These are used by the threaded input file parsing engine.
142 mutable int inputFileSlot; // The input file "slot" assigned to this particular file
143 bool readyToParse;
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);
159 return *this;
162 // Create an empty FileInfo. The path can be set implicitly by checkFileExists().
163 FileInfo() : path(NULL), fileLen(0), modTime(0), 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(0), 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==0; }
181 struct ExtraSection {
182 const char* segmentName;
183 const char* sectionName;
184 const char* path;
185 const uint8_t* data;
186 uint64_t dataLen;
187 typedef ExtraSection* iterator;
188 typedef const ExtraSection* const_iterator;
191 struct SectionAlignment {
192 const char* segmentName;
193 const char* sectionName;
194 uint8_t alignment;
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 {
209 const char* name;
210 uint64_t address;
213 struct SegmentSize {
214 const char* name;
215 uint64_t size;
218 struct SegmentProtect {
219 const char* name;
220 uint32_t max;
221 uint32_t init;
224 struct DylibOverride {
225 const char* installName;
226 const char* useInstead;
229 struct AliasPair {
230 const char* realName;
231 const char* alias;
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 deadCodeStrip() const { return fDeadStrip; }
296 UndefinedTreatment undefinedTreatment() const { return fUndefinedTreatment; }
297 ld::MacVersionMin macosxVersionMin() const { return fMacVersionMin; }
298 ld::IOSVersionMin iOSVersionMin() const { return fIOSVersionMin; }
299 ld::WatchOSVersionMin watchOSVersionMin() const { return fWatchOSVersionMin; }
300 uint32_t minOSversion() const;
301 bool minOS(ld::MacVersionMin mac, ld::IOSVersionMin iPhoneOS);
302 bool min_iOS(ld::IOSVersionMin requirediOSMin);
303 bool messagesPrefixedWithArchitecture();
304 Treatment picTreatment();
305 WeakReferenceMismatchTreatment weakReferenceMismatchTreatment() const { return fWeakReferenceMismatchTreatment; }
306 const char* umbrellaName() const { return fUmbrellaName; }
307 const std::vector<const char*>& allowableClients() const { return fAllowableClients; }
308 const char* clientName() const { return fClientName; }
309 const char* initFunctionName() const { return fInitFunctionName; } // only for kDynamicLibrary
310 const char* dotOutputFile();
311 uint64_t pageZeroSize() const { return fZeroPageSize; }
312 bool hasCustomStack() const { return (fStackSize != 0); }
313 uint64_t customStackSize() const { return fStackSize; }
314 uint64_t customStackAddr() const { return fStackAddr; }
315 bool hasExecutableStack() const { return fExecutableStack; }
316 bool hasNonExecutableHeap() const { return fNonExecutableHeap; }
317 UndefinesIterator initialUndefinesBegin() const { return &fInitialUndefines[0]; }
318 UndefinesIterator initialUndefinesEnd() const { return &fInitialUndefines[fInitialUndefines.size()]; }
319 const std::vector<const char*>& initialUndefines() const { return fInitialUndefines; }
320 bool printWhyLive(const char* name) const;
321 uint32_t minimumHeaderPad() const { return fMinimumHeaderPad; }
322 bool maxMminimumHeaderPad() const { return fMaxMinimumHeaderPad; }
323 ExtraSection::const_iterator extraSectionsBegin() const { return &fExtraSections[0]; }
324 ExtraSection::const_iterator extraSectionsEnd() const { return &fExtraSections[fExtraSections.size()]; }
325 CommonsMode commonsMode() const { return fCommonsMode; }
326 bool warnCommons() const { return fWarnCommons; }
327 bool keepRelocations();
328 FileInfo findFile(const std::string &path) const;
329 bool findFile(const std::string &path, const std::vector<std::string> &tbdExtensions, FileInfo& result) const;
330 UUIDMode UUIDMode() const { return fUUIDMode; }
331 bool warnStabs();
332 bool pauseAtEnd() { return fPause; }
333 bool printStatistics() const { return fStatistics; }
334 bool printArchPrefix() const { return fMessagesPrefixedWithArchitecture; }
335 void gotoClassicLinker(int argc, const char* argv[]);
336 bool sharedRegionEligible() const { return fSharedRegionEligible; }
337 bool printOrderFileStatistics() const { return fPrintOrderFileStatistics; }
338 const char* dTraceScriptName() { return fDtraceScriptName; }
339 bool dTrace() { return (fDtraceScriptName != NULL); }
340 unsigned long orderedSymbolsCount() const { return fOrderedSymbols.size(); }
341 OrderedSymbolsIterator orderedSymbolsBegin() const { return &fOrderedSymbols[0]; }
342 OrderedSymbolsIterator orderedSymbolsEnd() const { return &fOrderedSymbols[fOrderedSymbols.size()]; }
343 bool splitSeg() const { return fSplitSegs; }
344 uint64_t baseWritableAddress() { return fBaseWritableAddress; }
345 uint64_t segmentAlignment() const { return fSegmentAlignment; }
346 uint64_t segPageSize(const char* segName) const;
347 uint64_t customSegmentAddress(const char* segName) const;
348 bool hasCustomSegmentAddress(const char* segName) const;
349 bool hasCustomSectionAlignment(const char* segName, const char* sectName) const;
350 uint8_t customSectionAlignment(const char* segName, const char* sectName) const;
351 uint32_t initialSegProtection(const char*) const;
352 uint32_t maxSegProtection(const char*) const;
353 bool saveTempFiles() const { return fSaveTempFiles; }
354 const std::vector<const char*>& rpaths() const { return fRPaths; }
355 bool readOnlyx86Stubs() { return fReadOnlyx86Stubs; }
356 const std::vector<DylibOverride>& dylibOverrides() const { return fDylibOverrides; }
357 const char* generatedMapPath() const { return fMapPath; }
358 bool positionIndependentExecutable() const { return fPositionIndependentExecutable; }
359 Options::FileInfo findFileUsingPaths(const std::string &path) const;
360 bool deadStripDylibs() const { return fDeadStripDylibs; }
361 bool allowedUndefined(const char* name) const { return ( fAllowedUndefined.find(name) != fAllowedUndefined.end() ); }
362 bool someAllowedUndefines() const { return (fAllowedUndefined.size() != 0); }
363 LocalSymbolHandling localSymbolHandling() { return fLocalSymbolHandling; }
364 bool keepLocalSymbol(const char* symbolName) const;
365 bool allowTextRelocs() const { return fAllowTextRelocs; }
366 bool warnAboutTextRelocs() const { return fWarnTextRelocs; }
367 bool kextsUseStubs() const { return fKextsUseStubs; }
368 bool usingLazyDylibLinking() const { return fUsingLazyDylibLinking; }
369 bool verbose() const { return fVerbose; }
370 bool makeEncryptable() const { return fEncryptable; }
371 bool needsUnwindInfoSection() const { return fAddCompactUnwindEncoding; }
372 const std::vector<const char*>& llvmOptions() const{ return fLLVMOptions; }
373 const std::vector<const char*>& segmentOrder() const{ return fSegmentOrder; }
374 bool segmentOrderAfterFixedAddressSegment(const char* segName) const;
375 const std::vector<const char*>* sectionOrder(const char* segName) const;
376 const std::vector<const char*>& dyldEnvironExtras() const{ return fDyldEnvironExtras; }
377 const std::vector<const char*>& astFilePaths() const{ return fASTFilePaths; }
378 bool makeCompressedDyldInfo() const { return fMakeCompressedDyldInfo; }
379 bool hasExportedSymbolOrder();
380 bool exportedSymbolOrder(const char* sym, unsigned int* order) const;
381 bool orderData() { return fOrderData; }
382 bool errorOnOtherArchFiles() const { return fErrorOnOtherArchFiles; }
383 bool markAutoDeadStripDylib() const { return fMarkDeadStrippableDylib; }
384 bool removeEHLabels() const { return fNoEHLabels; }
385 bool useSimplifiedDylibReExports() const { return fUseSimplifiedDylibReExports; }
386 bool objCABIVersion2POverride() const { return fObjCABIVersion2Override; }
387 bool useUpwardDylibs() const { return fCanUseUpwardDylib; }
388 bool fullyLoadArchives() const { return fFullyLoadArchives; }
389 bool loadAllObjcObjectsFromArchives() const { return fLoadAllObjcObjectsFromArchives; }
390 bool autoOrderInitializers() const { return fAutoOrderInitializers; }
391 bool optimizeZeroFill() const { return fOptimizeZeroFill; }
392 bool mergeZeroFill() const { return fMergeZeroFill; }
393 bool logAllFiles() const { return fLogAllFiles; }
394 DebugInfoStripping debugInfoStripping() const { return fDebugInfoStripping; }
395 bool flatNamespace() const { return fFlatNamespace; }
396 bool linkingMainExecutable() const { return fLinkingMainExecutable; }
397 bool implicitlyLinkIndirectPublicDylibs() const { return fImplicitlyLinkPublicDylibs; }
398 bool whyLoad() const { return fWhyLoad; }
399 const char* traceOutputFile() const { return fTraceOutputFile; }
400 bool outputSlidable() const { return fOutputSlidable; }
401 bool haveCmdLineAliases() const { return (fAliases.size() != 0); }
402 const std::vector<AliasPair>& cmdLineAliases() const { return fAliases; }
403 bool makeTentativeDefinitionsReal() const { return fMakeTentativeDefinitionsReal; }
404 const char* dyldInstallPath() const { return fDyldInstallPath; }
405 bool warnWeakExports() const { return fWarnWeakExports; }
406 bool objcGcCompaction() const { return fObjcGcCompaction; }
407 bool objcGc() const { return fObjCGc; }
408 bool objcGcOnly() const { return fObjCGcOnly; }
409 bool canUseThreadLocalVariables() const { return fTLVSupport; }
410 bool addVersionLoadCommand() const { return fVersionLoadCommand && (fPlatform != kPlatformUnknown); }
411 bool addFunctionStarts() const { return fFunctionStartsLoadCommand; }
412 bool addDataInCodeInfo() const { return fDataInCodeInfoLoadCommand; }
413 bool canReExportSymbols() const { return fCanReExportSymbols; }
414 const char* tempLtoObjectPath() const { return fTempLtoObjectPath; }
415 const char* overridePathlibLTO() const { return fOverridePathlibLTO; }
416 const char* mcpuLTO() const { return fLtoCpu; }
417 bool objcCategoryMerging() const { return fObjcCategoryMerging; }
418 bool pageAlignDataAtoms() const { return fPageAlignDataAtoms; }
419 bool keepDwarfUnwind() const { return fKeepDwarfUnwind; }
420 bool verboseOptimizationHints() const { return fVerboseOptimizationHints; }
421 bool ignoreOptimizationHints() const { return fIgnoreOptimizationHints; }
422 bool generateDtraceDOF() const { return fGenerateDtraceDOF; }
423 bool allowBranchIslands() const { return fAllowBranchIslands; }
424 bool traceSymbolLayout() const { return fTraceSymbolLayout; }
425 bool markAppExtensionSafe() const { return fMarkAppExtensionSafe; }
426 bool checkDylibsAreAppExtensionSafe() const { return fCheckAppExtensionSafe; }
427 bool forceLoadSwiftLibs() const { return fForceLoadSwiftLibs; }
428 bool bundleBitcode() const { return fBundleBitcode; }
429 bool hideSymbols() const { return fHideSymbols; }
430 bool verifyBitcode() const { return fVerifyBitcode; }
431 bool renameReverseSymbolMap() const { return fReverseMapUUIDRename; }
432 bool deduplicateFunctions() const { return fDeDupe; }
433 bool verboseDeduplicate() const { return fVerboseDeDupe; }
434 const char* reverseSymbolMapPath() const { return fReverseMapPath; }
435 std::string reverseMapTempPath() const { return fReverseMapTempPath; }
436 bool ltoCodegenOnly() const { return fLTOCodegenOnly; }
437 bool ignoreAutoLink() const { return fIgnoreAutoLink; }
438 bool allowDeadDuplicates() const { return fAllowDeadDups; }
439 BitcodeMode bitcodeKind() const { return fBitcodeKind; }
440 bool sharedRegionEncodingV2() const { return fSharedRegionEncodingV2; }
441 bool useDataConstSegment() const { return fUseDataConstSegment; }
442 bool hasWeakBitTweaks() const;
443 bool forceWeak(const char* symbolName) const;
444 bool forceNotWeak(const char* symbolName) const;
445 bool forceWeakNonWildCard(const char* symbolName) const;
446 bool forceNotWeakNonWildcard(const char* symbolName) const;
447 bool forceCoalesce(const char* symbolName) const;
448 Snapshot& snapshot() const { return fLinkSnapshot; }
449 bool errorBecauseOfWarnings() const;
450 bool needsThreadLoadCommand() const { return fNeedsThreadLoadCommand; }
451 bool needsEntryPointLoadCommand() const { return fEntryPointLoadCommand; }
452 bool needsSourceVersionLoadCommand() const { return fSourceVersionLoadCommand; }
453 bool canUseAbsoluteSymbols() const { return fAbsoluteSymbols; }
454 bool allowSimulatorToLinkWithMacOSX() const { return fAllowSimulatorToLinkWithMacOSX; }
455 uint64_t sourceVersion() const { return fSourceVersion; }
456 uint32_t sdkVersion() const { return fSDKVersion; }
457 const char* demangleSymbol(const char* sym) const;
458 bool pipelineEnabled() const { return fPipelineFifo != NULL; }
459 const char* pipelineFifo() const { return fPipelineFifo; }
460 bool dumpDependencyInfo() const { return (fDependencyInfoPath != NULL); }
461 const char* dependencyInfoPath() const { return fDependencyInfoPath; }
462 bool targetIOSSimulator() const { return fTargetIOSSimulator; }
463 ld::relocatable::File::LinkerOptionsList&
464 linkerOptions() const { return fLinkerOptions; }
465 FileInfo findFramework(const char* frameworkName) const;
466 FileInfo findLibrary(const char* rootName, bool dylibsOnly=false) const;
467 bool armUsesZeroCostExceptions() const;
468 const std::vector<SectionRename>& sectionRenames() const { return fSectionRenames; }
469 const std::vector<SegmentRename>& segmentRenames() const { return fSegmentRenames; }
470 bool moveRoSymbol(const char* symName, const char* filePath, const char*& seg, bool& wildCardMatch) const;
471 bool moveRwSymbol(const char* symName, const char* filePath, const char*& seg, bool& wildCardMatch) const;
472 Platform platform() const { return fPlatform; }
473 const std::vector<const char*>& sdkPaths() const { return fSDKPaths; }
474 std::vector<std::string> writeBitcodeLinkOptions() const;
475 std::string getSDKVersionStr() const;
476 std::string getPlatformStr() const;
477 uint8_t maxDefaultCommonAlign() const { return fMaxDefaultCommonAlign; }
479 static uint32_t parseVersionNumber32(const char*);
481 private:
482 typedef std::unordered_map<const char*, unsigned int, ld::CStringHash, ld::CStringEquals> NameToOrder;
483 typedef std::unordered_set<const char*, ld::CStringHash, ld::CStringEquals> NameSet;
484 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
485 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
486 enum InterposeMode { kInterposeNone, kInterposeAllExternal, kInterposeSome };
487 enum FilePreference { kModTime, kTextBasedStub, kMachO };
489 class SetWithWildcards {
490 public:
491 void insert(const char*);
492 bool contains(const char*, bool* wildCardMatch=NULL) const;
493 bool containsWithPrefix(const char* symbol, const char* file, bool& wildCardMatch) const;
494 bool containsNonWildcard(const char*) const;
495 bool empty() const { return fRegular.empty() && fWildCard.empty(); }
496 bool hasWildCards() const { return !fWildCard.empty(); }
497 NameSet::iterator regularBegin() const { return fRegular.begin(); }
498 NameSet::iterator regularEnd() const { return fRegular.end(); }
499 void remove(const NameSet&);
500 std::vector<const char*> data() const;
501 private:
502 static bool hasWildCards(const char*);
503 bool wildCardMatch(const char* pattern, const char* candidate) const;
504 bool inCharRange(const char*& range, unsigned char c) const;
506 NameSet fRegular;
507 std::vector<const char*> fWildCard;
510 struct SymbolsMove {
511 const char* toSegment;
512 SetWithWildcards symbols;
515 void parse(int argc, const char* argv[]);
516 void checkIllegalOptionCombinations();
517 void buildSearchPaths(int argc, const char* argv[]);
518 void parseArch(const char* architecture);
519 FileInfo findFramework(const char* rootName, const char* suffix) const;
520 bool checkForFile(const char* format, const char* dir, const char* rootName,
521 FileInfo& result) const;
522 uint64_t parseVersionNumber64(const char*);
523 std::string getVersionString32(uint32_t ver) const;
524 std::string getVersionString64(uint64_t ver) const;
525 bool parsePackedVersion32(const std::string& versionStr, uint32_t &result);
526 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
527 void parseOrderFile(const char* path, bool cstring);
528 void addSection(const char* segment, const char* section, const char* path);
529 void addSubLibrary(const char* name);
530 void loadFileList(const char* fileOfPaths, ld::File::Ordinal baseOrdinal);
531 uint64_t parseAddress(const char* addr);
532 void loadExportFile(const char* fileOfExports, const char* option, SetWithWildcards& set);
533 void parseAliasFile(const char* fileOfAliases);
534 void parsePreCommandLineEnvironmentSettings();
535 void parsePostCommandLineEnvironmentSettings();
536 void setUndefinedTreatment(const char* treatment);
537 void setMacOSXVersionMin(const char* version);
538 void setIOSVersionMin(const char* version);
539 void setWatchOSVersionMin(const char* version);
540 void setWeakReferenceMismatchTreatment(const char* treatment);
541 void addDylibOverride(const char* paths);
542 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
543 CommonsMode parseCommonsTreatment(const char* mode);
544 Treatment parseTreatment(const char* treatment);
545 void reconfigureDefaults();
546 void checkForClassic(int argc, const char* argv[]);
547 void parseSegAddrTable(const char* segAddrPath, const char* installPath);
548 void addLibrary(const FileInfo& info);
549 void warnObsolete(const char* arg);
550 uint32_t parseProtection(const char* prot);
551 void loadSymbolOrderFile(const char* fileOfExports, NameToOrder& orderMapping);
552 void addSectionRename(const char* srcSegment, const char* srcSection, const char* dstSegment, const char* dstSection);
553 void addSegmentRename(const char* srcSegment, const char* dstSegment);
554 void addSymbolMove(const char* dstSegment, const char* symbolList, std::vector<SymbolsMove>& list, const char* optionName);
555 void cannotBeUsedWithBitcode(const char* arg);
558 // ObjectFile::ReaderOptions fReaderOptions;
559 const char* fOutputFile;
560 std::vector<Options::FileInfo> fInputFiles;
561 cpu_type_t fArchitecture;
562 cpu_subtype_t fSubArchitecture;
563 const char* fArchitectureName;
564 OutputKind fOutputKind;
565 bool fHasPreferredSubType;
566 bool fArchSupportsThumb2;
567 bool fPrebind;
568 bool fBindAtLoad;
569 bool fKeepPrivateExterns;
570 bool fNeedsModuleTable;
571 bool fIgnoreOtherArchFiles;
572 bool fErrorOnOtherArchFiles;
573 bool fForceSubtypeAll;
574 InterposeMode fInterposeMode;
575 bool fDeadStrip;
576 NameSpace fNameSpace;
577 uint32_t fDylibCompatVersion;
578 uint64_t fDylibCurrentVersion;
579 const char* fDylibInstallName;
580 const char* fFinalName;
581 const char* fEntryName;
582 uint64_t fBaseAddress;
583 uint64_t fMaxAddress;
584 uint64_t fBaseWritableAddress;
585 bool fSplitSegs;
586 SetWithWildcards fExportSymbols;
587 SetWithWildcards fDontExportSymbols;
588 SetWithWildcards fInterposeList;
589 SetWithWildcards fForceWeakSymbols;
590 SetWithWildcards fForceNotWeakSymbols;
591 SetWithWildcards fReExportSymbols;
592 SetWithWildcards fForceCoalesceSymbols;
593 NameSet fRemovedExports;
594 NameToOrder fExportSymbolsOrder;
595 ExportMode fExportMode;
596 LibrarySearchMode fLibrarySearchMode;
597 UndefinedTreatment fUndefinedTreatment;
598 bool fMessagesPrefixedWithArchitecture;
599 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
600 std::vector<const char*> fSubUmbellas;
601 std::vector<const char*> fSubLibraries;
602 std::vector<const char*> fAllowableClients;
603 std::vector<const char*> fRPaths;
604 const char* fClientName;
605 const char* fUmbrellaName;
606 const char* fInitFunctionName;
607 const char* fDotOutputFile;
608 const char* fExecutablePath;
609 const char* fBundleLoader;
610 const char* fDtraceScriptName;
611 const char* fSegAddrTablePath;
612 const char* fMapPath;
613 const char* fDyldInstallPath;
614 const char* fTempLtoObjectPath;
615 const char* fOverridePathlibLTO;
616 const char* fLtoCpu;
617 uint64_t fZeroPageSize;
618 uint64_t fStackSize;
619 uint64_t fStackAddr;
620 uint64_t fSourceVersion;
621 uint32_t fSDKVersion;
622 bool fExecutableStack;
623 bool fNonExecutableHeap;
624 bool fDisableNonExecutableHeap;
625 uint32_t fMinimumHeaderPad;
626 uint64_t fSegmentAlignment;
627 CommonsMode fCommonsMode;
628 enum UUIDMode fUUIDMode;
629 SetWithWildcards fLocalSymbolsIncluded;
630 SetWithWildcards fLocalSymbolsExcluded;
631 LocalSymbolHandling fLocalSymbolHandling;
632 bool fWarnCommons;
633 bool fVerbose;
634 bool fKeepRelocations;
635 bool fWarnStabs;
636 bool fTraceDylibSearching;
637 bool fPause;
638 bool fStatistics;
639 bool fPrintOptions;
640 bool fSharedRegionEligible;
641 bool fSharedRegionEligibleForceOff;
642 bool fPrintOrderFileStatistics;
643 bool fReadOnlyx86Stubs;
644 bool fPositionIndependentExecutable;
645 bool fPIEOnCommandLine;
646 bool fDisablePositionIndependentExecutable;
647 bool fMaxMinimumHeaderPad;
648 bool fDeadStripDylibs;
649 bool fAllowTextRelocs;
650 bool fWarnTextRelocs;
651 bool fKextsUseStubs;
652 bool fUsingLazyDylibLinking;
653 bool fEncryptable;
654 bool fEncryptableForceOn;
655 bool fEncryptableForceOff;
656 bool fOrderData;
657 bool fMarkDeadStrippableDylib;
658 bool fMakeCompressedDyldInfo;
659 bool fMakeCompressedDyldInfoForceOff;
660 bool fNoEHLabels;
661 bool fAllowCpuSubtypeMismatches;
662 bool fEnforceDylibSubtypesMatch;
663 bool fUseSimplifiedDylibReExports;
664 bool fObjCABIVersion2Override;
665 bool fObjCABIVersion1Override;
666 bool fCanUseUpwardDylib;
667 bool fFullyLoadArchives;
668 bool fLoadAllObjcObjectsFromArchives;
669 bool fFlatNamespace;
670 bool fLinkingMainExecutable;
671 bool fForFinalLinkedImage;
672 bool fForStatic;
673 bool fForDyld;
674 bool fMakeTentativeDefinitionsReal;
675 bool fWhyLoad;
676 bool fRootSafe;
677 bool fSetuidSafe;
678 bool fImplicitlyLinkPublicDylibs;
679 bool fAddCompactUnwindEncoding;
680 bool fWarnCompactUnwind;
681 bool fRemoveDwarfUnwindIfCompactExists;
682 bool fAutoOrderInitializers;
683 bool fOptimizeZeroFill;
684 bool fMergeZeroFill;
685 bool fLogObjectFiles;
686 bool fLogAllFiles;
687 bool fTraceDylibs;
688 bool fTraceIndirectDylibs;
689 bool fTraceArchives;
690 bool fOutputSlidable;
691 bool fWarnWeakExports;
692 bool fObjcGcCompaction;
693 bool fObjCGc;
694 bool fObjCGcOnly;
695 bool fDemangle;
696 bool fTLVSupport;
697 bool fVersionLoadCommand;
698 bool fVersionLoadCommandForcedOn;
699 bool fVersionLoadCommandForcedOff;
700 bool fFunctionStartsLoadCommand;
701 bool fFunctionStartsForcedOn;
702 bool fFunctionStartsForcedOff;
703 bool fDataInCodeInfoLoadCommand;
704 bool fDataInCodeInfoLoadCommandForcedOn;
705 bool fDataInCodeInfoLoadCommandForcedOff;
706 bool fCanReExportSymbols;
707 bool fObjcCategoryMerging;
708 bool fPageAlignDataAtoms;
709 bool fNeedsThreadLoadCommand;
710 bool fEntryPointLoadCommand;
711 bool fEntryPointLoadCommandForceOn;
712 bool fEntryPointLoadCommandForceOff;
713 bool fSourceVersionLoadCommand;
714 bool fSourceVersionLoadCommandForceOn;
715 bool fSourceVersionLoadCommandForceOff;
716 bool fTargetIOSSimulator;
717 bool fExportDynamic;
718 bool fAbsoluteSymbols;
719 bool fAllowSimulatorToLinkWithMacOSX;
720 bool fKeepDwarfUnwind;
721 bool fKeepDwarfUnwindForcedOn;
722 bool fKeepDwarfUnwindForcedOff;
723 bool fVerboseOptimizationHints;
724 bool fIgnoreOptimizationHints;
725 bool fGenerateDtraceDOF;
726 bool fAllowBranchIslands;
727 bool fTraceSymbolLayout;
728 bool fMarkAppExtensionSafe;
729 bool fCheckAppExtensionSafe;
730 bool fForceLoadSwiftLibs;
731 bool fSharedRegionEncodingV2;
732 bool fUseDataConstSegment;
733 bool fUseDataConstSegmentForceOn;
734 bool fUseDataConstSegmentForceOff;
735 bool fBundleBitcode;
736 bool fHideSymbols;
737 bool fVerifyBitcode;
738 bool fReverseMapUUIDRename;
739 bool fDeDupe;
740 bool fVerboseDeDupe;
741 const char* fReverseMapPath;
742 std::string fReverseMapTempPath;
743 bool fLTOCodegenOnly;
744 bool fIgnoreAutoLink;
745 bool fAllowDeadDups;
746 BitcodeMode fBitcodeKind;
747 Platform fPlatform;
748 DebugInfoStripping fDebugInfoStripping;
749 const char* fTraceOutputFile;
750 ld::MacVersionMin fMacVersionMin;
751 ld::IOSVersionMin fIOSVersionMin;
752 ld::WatchOSVersionMin fWatchOSVersionMin;
753 std::vector<AliasPair> fAliases;
754 std::vector<const char*> fInitialUndefines;
755 NameSet fAllowedUndefined;
756 SetWithWildcards fWhyLive;
757 std::vector<ExtraSection> fExtraSections;
758 std::vector<SectionAlignment> fSectionAlignments;
759 std::vector<OrderedSymbol> fOrderedSymbols;
760 std::vector<SegmentStart> fCustomSegmentAddresses;
761 std::vector<SegmentSize> fCustomSegmentSizes;
762 std::vector<SegmentProtect> fCustomSegmentProtections;
763 std::vector<DylibOverride> fDylibOverrides;
764 std::vector<const char*> fLLVMOptions;
765 std::vector<const char*> fLibrarySearchPaths;
766 std::vector<const char*> fFrameworkSearchPaths;
767 std::vector<const char*> fSDKPaths;
768 std::vector<const char*> fDyldEnvironExtras;
769 std::vector<const char*> fSegmentOrder;
770 std::vector<const char*> fASTFilePaths;
771 std::vector<SectionOrderList> fSectionOrder;
772 std::vector< std::vector<const char*> > fLinkerOptions;
773 std::vector<SectionRename> fSectionRenames;
774 std::vector<SegmentRename> fSegmentRenames;
775 std::vector<SymbolsMove> fSymbolsMovesData;
776 std::vector<SymbolsMove> fSymbolsMovesCode;
777 std::vector<SymbolsMove> fSymbolsMovesZeroFill;
778 bool fSaveTempFiles;
779 mutable Snapshot fLinkSnapshot;
780 bool fSnapshotRequested;
781 const char* fPipelineFifo;
782 const char* fDependencyInfoPath;
783 mutable int fDependencyFileDescriptor;
784 uint8_t fMaxDefaultCommonAlign;
785 FilePreference fFilePreference;
786 bool fForceTextBasedStub;
791 #endif // __OPTIONS__