]> git.saurik.com Git - apple/ld64.git/blame_incremental - src/ld/Options.h
ld64-305.tar.gz
[apple/ld64.git] / src / ld / Options.h
... / ...
CommitLineData
1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2005-2010 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
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.
13 *
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.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25#ifndef __OPTIONS__
26#define __OPTIONS__
27
28
29#include <stdint.h>
30#include <mach/machine.h>
31
32#include <vector>
33#include <unordered_set>
34#include <unordered_map>
35
36#include "ld.hpp"
37#include "Snapshot.h"
38#include "MachOFileAbstraction.hpp"
39
40extern void throwf (const char* format, ...) __attribute__ ((noreturn,format(printf, 1, 2)));
41extern void warning(const char* format, ...) __attribute__((format(printf, 1, 2)));
42
43class Snapshot;
44
45class LibraryOptions
46{
47public:
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;
60};
61
62
63
64//
65// The public interface to the Options class is the abstract representation of what work the linker
66// should do.
67//
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).
71//
72//
73class Options
74{
75public:
76 Options(int argc, const char* argv[]);
77 ~Options();
78
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 enum UnalignedPointerTreatment { kUnalignedPointerError, kUnalignedPointerWarning, kUnalignedPointerIgnore };
92#if SUPPORT_APPLE_TV
93 enum Platform { kPlatformUnknown, kPlatformOSX=1, kPlatformiOS=2, kPlatformWatchOS=3, kPlatform_tvOS=4, kPlatform_bridgeOS=5 };
94#else
95 enum Platform { kPlatformUnknown, kPlatformOSX, kPlatformiOS, kPlatformWatchOS };
96#endif
97
98 static Platform platformForLoadCommand(uint32_t lc) {
99 switch (lc) {
100 case LC_VERSION_MIN_MACOSX:
101 return kPlatformOSX;
102 case LC_VERSION_MIN_IPHONEOS:
103 return kPlatformiOS;
104 case LC_VERSION_MIN_WATCHOS:
105 return kPlatformWatchOS;
106 #if SUPPORT_APPLE_TV
107 case LC_VERSION_MIN_TVOS:
108 return kPlatform_tvOS;
109 #endif
110 }
111 assert(!lc && "unknown LC_VERSION_MIN load command");
112 return kPlatformUnknown;
113 }
114
115 static const char* platformName(Platform platform) {
116 switch (platform) {
117 case kPlatformOSX:
118 return "OSX";
119 case kPlatformiOS:
120 return "iOS";
121 case kPlatformWatchOS:
122 return "watchOS";
123 #if SUPPORT_APPLE_TV
124 case kPlatform_tvOS:
125 return "tvOS";
126 #endif
127 case kPlatform_bridgeOS:
128 return "bridgeOS";
129 case kPlatformUnknown:
130 default:
131 return "(unknown)";
132 }
133 }
134
135 static void userReadableSwiftVersion(uint8_t value, char versionString[64])
136 {
137 switch (value) {
138 case 1:
139 strcpy(versionString, "1.0");
140 break;
141 case 2:
142 strcpy(versionString, "1.1");
143 break;
144 case 3:
145 strcpy(versionString, "2.0");
146 break;
147 case 4:
148 strcpy(versionString, "3.0");
149 break;
150 case 5:
151 strcpy(versionString, "4.0");
152 break;
153 default:
154 sprintf(versionString, "unknown ABI version 0x%02X", value);
155 }
156 }
157
158
159 class FileInfo {
160 public:
161 const char* path;
162 time_t modTime;
163 LibraryOptions options;
164 ld::File::Ordinal ordinal;
165 bool fromFileList;
166
167 // These are used by the threaded input file parsing engine.
168 mutable int inputFileSlot; // The input file "slot" assigned to this particular file
169 bool readyToParse;
170
171 // The use pattern for FileInfo is to create one on the stack in a leaf function and return
172 // it to the calling frame by copy. Therefore the copy constructor steals the path string from
173 // the source, which dies with the stack frame.
174 FileInfo(FileInfo const &other) : path(other.path), modTime(other.modTime), options(other.options), ordinal(other.ordinal), fromFileList(other.fromFileList), inputFileSlot(-1) { ((FileInfo&)other).path = NULL; };
175
176 FileInfo &operator=(FileInfo other) {
177 std::swap(path, other.path);
178 std::swap(modTime, other.modTime);
179 std::swap(options, other.options);
180 std::swap(ordinal, other.ordinal);
181 std::swap(fromFileList, other.fromFileList);
182 std::swap(inputFileSlot, other.inputFileSlot);
183 std::swap(readyToParse, other.readyToParse);
184 return *this;
185 }
186
187 // Create an empty FileInfo. The path can be set implicitly by checkFileExists().
188 FileInfo() : path(NULL), modTime(-1), options(), fromFileList(false) {};
189
190 // Create a FileInfo for a specific path, but does not stat the file.
191 FileInfo(const char *_path) : path(strdup(_path)), modTime(-1), options(), fromFileList(false) {};
192
193 ~FileInfo() { if (path) ::free((void*)path); }
194
195 // Stat the file and update fileLen and modTime.
196 // If the object already has a path the p must be NULL.
197 // 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.
198 // Returns true if the file exists, false if not.
199 bool checkFileExists(const Options& options, const char *p=NULL);
200
201 // Returns true if a previous call to checkFileExists() succeeded.
202 // Returns false if the file does not exist of checkFileExists() has never been called.
203 bool missing() const { return modTime == -1; }
204 };
205
206 struct ExtraSection {
207 const char* segmentName;
208 const char* sectionName;
209 const char* path;
210 const uint8_t* data;
211 uint64_t dataLen;
212 typedef ExtraSection* iterator;
213 typedef const ExtraSection* const_iterator;
214 };
215
216 struct SectionAlignment {
217 const char* segmentName;
218 const char* sectionName;
219 uint8_t alignment;
220 };
221
222 struct SectionOrderList {
223 const char* segmentName;
224 std::vector<const char*> sectionOrder;
225 };
226
227 struct OrderedSymbol {
228 const char* symbolName;
229 const char* objectFileName;
230 };
231 typedef const OrderedSymbol* OrderedSymbolsIterator;
232
233 struct SegmentStart {
234 const char* name;
235 uint64_t address;
236 };
237
238 struct SegmentSize {
239 const char* name;
240 uint64_t size;
241 };
242
243 struct SegmentProtect {
244 const char* name;
245 uint32_t max;
246 uint32_t init;
247 };
248
249 struct DylibOverride {
250 const char* installName;
251 const char* useInstead;
252 };
253
254 struct AliasPair {
255 const char* realName;
256 const char* alias;
257 };
258
259 struct SectionRename {
260 const char* fromSegment;
261 const char* fromSection;
262 const char* toSegment;
263 const char* toSection;
264 };
265
266 struct SegmentRename {
267 const char* fromSegment;
268 const char* toSegment;
269 };
270
271 enum { depLinkerVersion=0x00, depObjectFile=0x10, depDirectDylib=0x10, depIndirectDylib=0x10,
272 depUpwardDirectDylib=0x10, depUpwardIndirectDylib=0x10, depArchive=0x10,
273 depFileList=0x10, depSection=0x10, depBundleLoader=0x10, depMisc=0x10, depNotFound=0x11,
274 depOutputFile = 0x40 };
275
276 void dumpDependency(uint8_t, const char* path) const;
277
278 typedef const char* const* UndefinesIterator;
279
280// const ObjectFile::ReaderOptions& readerOptions();
281 const char* outputFilePath() const { return fOutputFile; }
282 const std::vector<FileInfo>& getInputFiles() const { return fInputFiles; }
283
284 cpu_type_t architecture() const { return fArchitecture; }
285 bool preferSubArchitecture() const { return fHasPreferredSubType; }
286 cpu_subtype_t subArchitecture() const { return fSubArchitecture; }
287 bool allowSubArchitectureMismatches() const { return fAllowCpuSubtypeMismatches; }
288 bool enforceDylibSubtypesMatch() const { return fEnforceDylibSubtypesMatch; }
289 bool forceCpuSubtypeAll() const { return fForceSubtypeAll; }
290 const char* architectureName() const { return fArchitectureName; }
291 void setArchitecture(cpu_type_t, cpu_subtype_t subtype, Options::Platform platform);
292 bool archSupportsThumb2() const { return fArchSupportsThumb2; }
293 OutputKind outputKind() const { return fOutputKind; }
294 bool prebind() const { return fPrebind; }
295 bool bindAtLoad() const { return fBindAtLoad; }
296 NameSpace nameSpace() const { return fNameSpace; }
297 const char* installPath() const; // only for kDynamicLibrary
298 uint64_t currentVersion() const { return fDylibCurrentVersion; } // only for kDynamicLibrary
299 uint32_t currentVersion32() const; // only for kDynamicLibrary
300 uint32_t compatibilityVersion() const { return fDylibCompatVersion; } // only for kDynamicLibrary
301 const char* entryName() const { return fEntryName; } // only for kDynamicExecutable or kStaticExecutable
302 const char* executablePath();
303 uint64_t baseAddress() const { return fBaseAddress; }
304 uint64_t maxAddress() const { return fMaxAddress; }
305 bool keepPrivateExterns() const { return fKeepPrivateExterns; } // only for kObjectFile
306 bool needsModuleTable() const { return fNeedsModuleTable; } // only for kDynamicLibrary
307 bool interposable(const char* name) const;
308 bool hasExportRestrictList() const { return (fExportMode != kExportDefault); } // -exported_symbol or -unexported_symbol
309 bool hasExportMaskList() const { return (fExportMode == kExportSome); } // just -exported_symbol
310 bool hasWildCardExportRestrictList() const;
311 bool hasReExportList() const { return ! fReExportSymbols.empty(); }
312 bool wasRemovedExport(const char* sym) const { return ( fRemovedExports.find(sym) != fRemovedExports.end() ); }
313 bool allGlobalsAreDeadStripRoots() const;
314 bool shouldExport(const char*) const;
315 bool shouldReExport(const char*) const;
316 std::vector<const char*> exportsData() const;
317 bool ignoreOtherArchInputFiles() const { return fIgnoreOtherArchFiles; }
318 bool traceDylibs() const { return fTraceDylibs; }
319 bool traceArchives() const { return fTraceArchives; }
320 bool traceEmitJSON() const { return fTraceEmitJSON; }
321 bool deadCodeStrip() const { return fDeadStrip; }
322 UndefinedTreatment undefinedTreatment() const { return fUndefinedTreatment; }
323 ld::MacVersionMin macosxVersionMin() const { return fMacVersionMin; }
324 ld::IOSVersionMin iOSVersionMin() const { return fIOSVersionMin; }
325 ld::WatchOSVersionMin watchOSVersionMin() const { return fWatchOSVersionMin; }
326 uint32_t minOSversion() const;
327 bool minOS(ld::MacVersionMin mac, ld::IOSVersionMin iPhoneOS);
328 bool min_iOS(ld::IOSVersionMin requirediOSMin);
329 bool messagesPrefixedWithArchitecture();
330 Treatment picTreatment();
331 WeakReferenceMismatchTreatment weakReferenceMismatchTreatment() const { return fWeakReferenceMismatchTreatment; }
332 const char* umbrellaName() const { return fUmbrellaName; }
333 const std::vector<const char*>& allowableClients() const { return fAllowableClients; }
334 const char* clientName() const { return fClientName; }
335 const char* initFunctionName() const { return fInitFunctionName; } // only for kDynamicLibrary
336 const char* dotOutputFile();
337 uint64_t pageZeroSize() const { return fZeroPageSize; }
338 bool hasCustomStack() const { return (fStackSize != 0); }
339 uint64_t customStackSize() const { return fStackSize; }
340 uint64_t customStackAddr() const { return fStackAddr; }
341 bool hasExecutableStack() const { return fExecutableStack; }
342 bool hasNonExecutableHeap() const { return fNonExecutableHeap; }
343 UndefinesIterator initialUndefinesBegin() const { return &fInitialUndefines[0]; }
344 UndefinesIterator initialUndefinesEnd() const { return &fInitialUndefines[fInitialUndefines.size()]; }
345 const std::vector<const char*>& initialUndefines() const { return fInitialUndefines; }
346 bool printWhyLive(const char* name) const;
347 uint32_t minimumHeaderPad() const { return fMinimumHeaderPad; }
348 bool maxMminimumHeaderPad() const { return fMaxMinimumHeaderPad; }
349 ExtraSection::const_iterator extraSectionsBegin() const { return &fExtraSections[0]; }
350 ExtraSection::const_iterator extraSectionsEnd() const { return &fExtraSections[fExtraSections.size()]; }
351 CommonsMode commonsMode() const { return fCommonsMode; }
352 bool warnCommons() const { return fWarnCommons; }
353 bool keepRelocations();
354 FileInfo findFile(const std::string &path, const ld::dylib::File* fromDylib=nullptr) const;
355 bool findFile(const std::string &path, const std::vector<std::string> &tbdExtensions, FileInfo& result) const;
356 UUIDMode UUIDMode() const { return fUUIDMode; }
357 bool warnStabs();
358 bool pauseAtEnd() { return fPause; }
359 bool printStatistics() const { return fStatistics; }
360 bool printArchPrefix() const { return fMessagesPrefixedWithArchitecture; }
361 void gotoClassicLinker(int argc, const char* argv[]);
362 bool sharedRegionEligible() const { return fSharedRegionEligible; }
363 bool printOrderFileStatistics() const { return fPrintOrderFileStatistics; }
364 const char* dTraceScriptName() { return fDtraceScriptName; }
365 bool dTrace() { return (fDtraceScriptName != NULL); }
366 unsigned long orderedSymbolsCount() const { return fOrderedSymbols.size(); }
367 OrderedSymbolsIterator orderedSymbolsBegin() const { return &fOrderedSymbols[0]; }
368 OrderedSymbolsIterator orderedSymbolsEnd() const { return &fOrderedSymbols[fOrderedSymbols.size()]; }
369 bool splitSeg() const { return fSplitSegs; }
370 uint64_t baseWritableAddress() { return fBaseWritableAddress; }
371 uint64_t segmentAlignment() const { return fSegmentAlignment; }
372 uint64_t segPageSize(const char* segName) const;
373 uint64_t customSegmentAddress(const char* segName) const;
374 bool hasCustomSegmentAddress(const char* segName) const;
375 bool hasCustomSectionAlignment(const char* segName, const char* sectName) const;
376 uint8_t customSectionAlignment(const char* segName, const char* sectName) const;
377 uint32_t initialSegProtection(const char*) const;
378 uint32_t maxSegProtection(const char*) const;
379 bool saveTempFiles() const { return fSaveTempFiles; }
380 const std::vector<const char*>& rpaths() const { return fRPaths; }
381 bool readOnlyx86Stubs() { return fReadOnlyx86Stubs; }
382 const std::vector<DylibOverride>& dylibOverrides() const { return fDylibOverrides; }
383 const char* generatedMapPath() const { return fMapPath; }
384 bool positionIndependentExecutable() const { return fPositionIndependentExecutable; }
385 Options::FileInfo findIndirectDylib(const std::string& installName, const ld::dylib::File* fromDylib) const;
386 bool deadStripDylibs() const { return fDeadStripDylibs; }
387 bool allowedUndefined(const char* name) const { return ( fAllowedUndefined.find(name) != fAllowedUndefined.end() ); }
388 bool someAllowedUndefines() const { return (fAllowedUndefined.size() != 0); }
389 LocalSymbolHandling localSymbolHandling() { return fLocalSymbolHandling; }
390 bool keepLocalSymbol(const char* symbolName) const;
391 bool allowTextRelocs() const { return fAllowTextRelocs; }
392 bool warnAboutTextRelocs() const { return fWarnTextRelocs; }
393 bool kextsUseStubs() const { return fKextsUseStubs; }
394 bool usingLazyDylibLinking() const { return fUsingLazyDylibLinking; }
395 bool verbose() const { return fVerbose; }
396 bool makeEncryptable() const { return fEncryptable; }
397 bool needsUnwindInfoSection() const { return fAddCompactUnwindEncoding; }
398 const std::vector<const char*>& llvmOptions() const{ return fLLVMOptions; }
399 const std::vector<const char*>& segmentOrder() const{ return fSegmentOrder; }
400 bool segmentOrderAfterFixedAddressSegment(const char* segName) const;
401 const std::vector<const char*>* sectionOrder(const char* segName) const;
402 const std::vector<const char*>& dyldEnvironExtras() const{ return fDyldEnvironExtras; }
403 const std::vector<const char*>& astFilePaths() const{ return fASTFilePaths; }
404 bool makeCompressedDyldInfo() const { return fMakeCompressedDyldInfo; }
405 bool hasExportedSymbolOrder();
406 bool exportedSymbolOrder(const char* sym, unsigned int* order) const;
407 bool orderData() { return fOrderData; }
408 bool errorOnOtherArchFiles() const { return fErrorOnOtherArchFiles; }
409 bool markAutoDeadStripDylib() const { return fMarkDeadStrippableDylib; }
410 bool removeEHLabels() const { return fNoEHLabels; }
411 bool useSimplifiedDylibReExports() const { return fUseSimplifiedDylibReExports; }
412 bool objCABIVersion2POverride() const { return fObjCABIVersion2Override; }
413 bool useUpwardDylibs() const { return fCanUseUpwardDylib; }
414 bool fullyLoadArchives() const { return fFullyLoadArchives; }
415 bool loadAllObjcObjectsFromArchives() const { return fLoadAllObjcObjectsFromArchives; }
416 bool autoOrderInitializers() const { return fAutoOrderInitializers; }
417 bool optimizeZeroFill() const { return fOptimizeZeroFill; }
418 bool mergeZeroFill() const { return fMergeZeroFill; }
419 bool logAllFiles() const { return fLogAllFiles; }
420 DebugInfoStripping debugInfoStripping() const { return fDebugInfoStripping; }
421 bool flatNamespace() const { return fFlatNamespace; }
422 bool linkingMainExecutable() const { return fLinkingMainExecutable; }
423 bool implicitlyLinkIndirectPublicDylibs() const { return fImplicitlyLinkPublicDylibs; }
424 bool whyLoad() const { return fWhyLoad; }
425 const char* traceOutputFile() const { return fTraceOutputFile; }
426 bool outputSlidable() const { return fOutputSlidable; }
427 bool haveCmdLineAliases() const { return (fAliases.size() != 0); }
428 const std::vector<AliasPair>& cmdLineAliases() const { return fAliases; }
429 bool makeTentativeDefinitionsReal() const { return fMakeTentativeDefinitionsReal; }
430 const char* dyldInstallPath() const { return fDyldInstallPath; }
431 bool warnWeakExports() const { return fWarnWeakExports; }
432 bool objcGcCompaction() const { return fObjcGcCompaction; }
433 bool objcGc() const { return fObjCGc; }
434 bool objcGcOnly() const { return fObjCGcOnly; }
435 bool canUseThreadLocalVariables() const { return fTLVSupport; }
436 bool addVersionLoadCommand() const { return fVersionLoadCommand && (fPlatform != kPlatformUnknown); }
437 bool addBuildVersionLoadCommand() const { return fBuildVersionLoadCommand; }
438 bool addFunctionStarts() const { return fFunctionStartsLoadCommand; }
439 bool addDataInCodeInfo() const { return fDataInCodeInfoLoadCommand; }
440 bool canReExportSymbols() const { return fCanReExportSymbols; }
441 const char* ltoCachePath() const { return fLtoCachePath; }
442 int ltoPruneInterval() const { return fLtoPruneInterval; }
443 int ltoPruneAfter() const { return fLtoPruneAfter; }
444 unsigned ltoMaxCacheSize() const { return fLtoMaxCacheSize; }
445 const char* tempLtoObjectPath() const { return fTempLtoObjectPath; }
446 const char* overridePathlibLTO() const { return fOverridePathlibLTO; }
447 const char* mcpuLTO() const { return fLtoCpu; }
448 bool objcCategoryMerging() const { return fObjcCategoryMerging; }
449 bool pageAlignDataAtoms() const { return fPageAlignDataAtoms; }
450 bool keepDwarfUnwind() const { return fKeepDwarfUnwind; }
451 bool verboseOptimizationHints() const { return fVerboseOptimizationHints; }
452 bool ignoreOptimizationHints() const { return fIgnoreOptimizationHints; }
453 bool generateDtraceDOF() const { return fGenerateDtraceDOF; }
454 bool allowBranchIslands() const { return fAllowBranchIslands; }
455 bool traceSymbolLayout() const { return fTraceSymbolLayout; }
456 bool markAppExtensionSafe() const { return fMarkAppExtensionSafe; }
457 bool checkDylibsAreAppExtensionSafe() const { return fCheckAppExtensionSafe; }
458 bool forceLoadSwiftLibs() const { return fForceLoadSwiftLibs; }
459 bool bundleBitcode() const { return fBundleBitcode; }
460 bool hideSymbols() const { return fHideSymbols; }
461 bool verifyBitcode() const { return fVerifyBitcode; }
462 bool renameReverseSymbolMap() const { return fReverseMapUUIDRename; }
463 bool deduplicateFunctions() const { return fDeDupe; }
464 bool verboseDeduplicate() const { return fVerboseDeDupe; }
465 const char* reverseSymbolMapPath() const { return fReverseMapPath; }
466 std::string reverseMapTempPath() const { return fReverseMapTempPath; }
467 bool ltoCodegenOnly() const { return fLTOCodegenOnly; }
468 bool ignoreAutoLink() const { return fIgnoreAutoLink; }
469 bool allowDeadDuplicates() const { return fAllowDeadDups; }
470 bool allowWeakImports() const { return fAllowWeakImports; }
471 bool noInitializers() const { return fNoInitializers; }
472 BitcodeMode bitcodeKind() const { return fBitcodeKind; }
473 bool sharedRegionEncodingV2() const { return fSharedRegionEncodingV2; }
474 bool useDataConstSegment() const { return fUseDataConstSegment; }
475 bool useTextExecSegment() const { return fUseTextExecSegment; }
476 bool hasWeakBitTweaks() const;
477 bool forceWeak(const char* symbolName) const;
478 bool forceNotWeak(const char* symbolName) const;
479 bool forceWeakNonWildCard(const char* symbolName) const;
480 bool forceNotWeakNonWildcard(const char* symbolName) const;
481 bool forceCoalesce(const char* symbolName) const;
482 Snapshot& snapshot() const { return fLinkSnapshot; }
483 bool errorBecauseOfWarnings() const;
484 bool needsThreadLoadCommand() const { return fNeedsThreadLoadCommand; }
485 bool needsEntryPointLoadCommand() const { return fEntryPointLoadCommand; }
486 bool needsSourceVersionLoadCommand() const { return fSourceVersionLoadCommand; }
487 bool canUseAbsoluteSymbols() const { return fAbsoluteSymbols; }
488 bool allowSimulatorToLinkWithMacOSX() const { return fAllowSimulatorToLinkWithMacOSX; }
489 uint64_t sourceVersion() const { return fSourceVersion; }
490 uint32_t sdkVersion() const { return fSDKVersion; }
491 const char* demangleSymbol(const char* sym) const;
492 bool pipelineEnabled() const { return fPipelineFifo != NULL; }
493 const char* pipelineFifo() const { return fPipelineFifo; }
494 bool dumpDependencyInfo() const { return (fDependencyInfoPath != NULL); }
495 const char* dependencyInfoPath() const { return fDependencyInfoPath; }
496 bool targetIOSSimulator() const { return fTargetIOSSimulator; }
497 ld::relocatable::File::LinkerOptionsList&
498 linkerOptions() const { return fLinkerOptions; }
499 FileInfo findFramework(const char* frameworkName) const;
500 FileInfo findLibrary(const char* rootName, bool dylibsOnly=false) const;
501 bool armUsesZeroCostExceptions() const;
502 const std::vector<SectionRename>& sectionRenames() const { return fSectionRenames; }
503 const std::vector<SegmentRename>& segmentRenames() const { return fSegmentRenames; }
504 bool moveRoSymbol(const char* symName, const char* filePath, const char*& seg, bool& wildCardMatch) const;
505 bool moveRwSymbol(const char* symName, const char* filePath, const char*& seg, bool& wildCardMatch) const;
506 Platform platform() const { return fPlatform; }
507 const std::vector<const char*>& sdkPaths() const { return fSDKPaths; }
508 std::vector<std::string> writeBitcodeLinkOptions() const;
509 std::string getSDKVersionStr() const;
510 std::string getPlatformStr() const;
511 uint8_t maxDefaultCommonAlign() const { return fMaxDefaultCommonAlign; }
512 bool hasDataSymbolMoves() const { return !fSymbolsMovesData.empty(); }
513 bool hasCodeSymbolMoves() const { return !fSymbolsMovesCode.empty(); }
514 void writeToTraceFile(const char* buffer, size_t len) const;
515 UnalignedPointerTreatment unalignedPointerTreatment() const { return fUnalignedPointerTreatment; }
516
517 static uint32_t parseVersionNumber32(const char*);
518
519private:
520 typedef std::unordered_map<const char*, unsigned int, ld::CStringHash, ld::CStringEquals> NameToOrder;
521 typedef std::unordered_set<const char*, ld::CStringHash, ld::CStringEquals> NameSet;
522 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
523 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
524 enum InterposeMode { kInterposeNone, kInterposeAllExternal, kInterposeSome };
525
526 class SetWithWildcards {
527 public:
528 void insert(const char*);
529 bool contains(const char*, bool* wildCardMatch=NULL) const;
530 bool containsWithPrefix(const char* symbol, const char* file, bool& wildCardMatch) const;
531 bool containsNonWildcard(const char*) const;
532 bool empty() const { return fRegular.empty() && fWildCard.empty(); }
533 bool hasWildCards() const { return !fWildCard.empty(); }
534 NameSet::iterator regularBegin() const { return fRegular.begin(); }
535 NameSet::iterator regularEnd() const { return fRegular.end(); }
536 void remove(const NameSet&);
537 std::vector<const char*> data() const;
538 private:
539 static bool hasWildCards(const char*);
540 bool wildCardMatch(const char* pattern, const char* candidate) const;
541 bool inCharRange(const char*& range, unsigned char c) const;
542
543 NameSet fRegular;
544 std::vector<const char*> fWildCard;
545 };
546
547 struct SymbolsMove {
548 const char* toSegment;
549 SetWithWildcards symbols;
550 };
551
552 void parse(int argc, const char* argv[]);
553 void checkIllegalOptionCombinations();
554 void buildSearchPaths(int argc, const char* argv[]);
555 void parseArch(const char* architecture);
556 FileInfo findFramework(const char* rootName, const char* suffix) const;
557 bool checkForFile(const char* format, const char* dir, const char* rootName,
558 FileInfo& result) const;
559 uint64_t parseVersionNumber64(const char*);
560 std::string getVersionString32(uint32_t ver) const;
561 std::string getVersionString64(uint64_t ver) const;
562 bool parsePackedVersion32(const std::string& versionStr, uint32_t &result);
563 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
564 void parseOrderFile(const char* path, bool cstring);
565 void addSection(const char* segment, const char* section, const char* path);
566 void addSubLibrary(const char* name);
567 void loadFileList(const char* fileOfPaths, ld::File::Ordinal baseOrdinal);
568 uint64_t parseAddress(const char* addr);
569 void loadExportFile(const char* fileOfExports, const char* option, SetWithWildcards& set);
570 void parseAliasFile(const char* fileOfAliases);
571 void parsePreCommandLineEnvironmentSettings();
572 void parsePostCommandLineEnvironmentSettings();
573 void setUndefinedTreatment(const char* treatment);
574 void setMacOSXVersionMin(const char* version);
575 void setIOSVersionMin(const char* version);
576 void setWatchOSVersionMin(const char* version);
577 void setWeakReferenceMismatchTreatment(const char* treatment);
578 void addDylibOverride(const char* paths);
579 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
580 CommonsMode parseCommonsTreatment(const char* mode);
581 Treatment parseTreatment(const char* treatment);
582 void reconfigureDefaults();
583 void checkForClassic(int argc, const char* argv[]);
584 void parseSegAddrTable(const char* segAddrPath, const char* installPath);
585 void addLibrary(const FileInfo& info);
586 void warnObsolete(const char* arg);
587 uint32_t parseProtection(const char* prot);
588 void loadSymbolOrderFile(const char* fileOfExports, NameToOrder& orderMapping);
589 void addSectionRename(const char* srcSegment, const char* srcSection, const char* dstSegment, const char* dstSection);
590 void addSegmentRename(const char* srcSegment, const char* dstSegment);
591 void addSymbolMove(const char* dstSegment, const char* symbolList, std::vector<SymbolsMove>& list, const char* optionName);
592 void cannotBeUsedWithBitcode(const char* arg);
593
594
595// ObjectFile::ReaderOptions fReaderOptions;
596 const char* fOutputFile;
597 std::vector<Options::FileInfo> fInputFiles;
598 cpu_type_t fArchitecture;
599 cpu_subtype_t fSubArchitecture;
600 const char* fArchitectureName;
601 OutputKind fOutputKind;
602 bool fHasPreferredSubType;
603 bool fArchSupportsThumb2;
604 bool fPrebind;
605 bool fBindAtLoad;
606 bool fKeepPrivateExterns;
607 bool fNeedsModuleTable;
608 bool fIgnoreOtherArchFiles;
609 bool fErrorOnOtherArchFiles;
610 bool fForceSubtypeAll;
611 InterposeMode fInterposeMode;
612 bool fDeadStrip;
613 NameSpace fNameSpace;
614 uint32_t fDylibCompatVersion;
615 uint64_t fDylibCurrentVersion;
616 const char* fDylibInstallName;
617 const char* fFinalName;
618 const char* fEntryName;
619 uint64_t fBaseAddress;
620 uint64_t fMaxAddress;
621 uint64_t fBaseWritableAddress;
622 bool fSplitSegs;
623 SetWithWildcards fExportSymbols;
624 SetWithWildcards fDontExportSymbols;
625 SetWithWildcards fInterposeList;
626 SetWithWildcards fForceWeakSymbols;
627 SetWithWildcards fForceNotWeakSymbols;
628 SetWithWildcards fReExportSymbols;
629 SetWithWildcards fForceCoalesceSymbols;
630 NameSet fRemovedExports;
631 NameToOrder fExportSymbolsOrder;
632 ExportMode fExportMode;
633 LibrarySearchMode fLibrarySearchMode;
634 UndefinedTreatment fUndefinedTreatment;
635 bool fMessagesPrefixedWithArchitecture;
636 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
637 std::vector<const char*> fSubUmbellas;
638 std::vector<const char*> fSubLibraries;
639 std::vector<const char*> fAllowableClients;
640 std::vector<const char*> fRPaths;
641 const char* fClientName;
642 const char* fUmbrellaName;
643 const char* fInitFunctionName;
644 const char* fDotOutputFile;
645 const char* fExecutablePath;
646 const char* fBundleLoader;
647 const char* fDtraceScriptName;
648 const char* fSegAddrTablePath;
649 const char* fMapPath;
650 const char* fDyldInstallPath;
651 const char* fLtoCachePath;
652 int fLtoPruneInterval;
653 int fLtoPruneAfter;
654 unsigned fLtoMaxCacheSize;
655 const char* fTempLtoObjectPath;
656 const char* fOverridePathlibLTO;
657 const char* fLtoCpu;
658 uint64_t fZeroPageSize;
659 uint64_t fStackSize;
660 uint64_t fStackAddr;
661 uint64_t fSourceVersion;
662 uint32_t fSDKVersion;
663 bool fExecutableStack;
664 bool fNonExecutableHeap;
665 bool fDisableNonExecutableHeap;
666 uint32_t fMinimumHeaderPad;
667 uint64_t fSegmentAlignment;
668 CommonsMode fCommonsMode;
669 enum UUIDMode fUUIDMode;
670 SetWithWildcards fLocalSymbolsIncluded;
671 SetWithWildcards fLocalSymbolsExcluded;
672 LocalSymbolHandling fLocalSymbolHandling;
673 bool fWarnCommons;
674 bool fVerbose;
675 bool fKeepRelocations;
676 bool fWarnStabs;
677 bool fTraceDylibSearching;
678 bool fPause;
679 bool fStatistics;
680 bool fPrintOptions;
681 bool fSharedRegionEligible;
682 bool fSharedRegionEligibleForceOff;
683 bool fPrintOrderFileStatistics;
684 bool fReadOnlyx86Stubs;
685 bool fPositionIndependentExecutable;
686 bool fPIEOnCommandLine;
687 bool fDisablePositionIndependentExecutable;
688 bool fMaxMinimumHeaderPad;
689 bool fDeadStripDylibs;
690 bool fAllowTextRelocs;
691 bool fWarnTextRelocs;
692 bool fKextsUseStubs;
693 bool fUsingLazyDylibLinking;
694 bool fEncryptable;
695 bool fEncryptableForceOn;
696 bool fEncryptableForceOff;
697 bool fOrderData;
698 bool fMarkDeadStrippableDylib;
699 bool fMakeCompressedDyldInfo;
700 bool fMakeCompressedDyldInfoForceOff;
701 bool fNoEHLabels;
702 bool fAllowCpuSubtypeMismatches;
703 bool fEnforceDylibSubtypesMatch;
704 bool fUseSimplifiedDylibReExports;
705 bool fObjCABIVersion2Override;
706 bool fObjCABIVersion1Override;
707 bool fCanUseUpwardDylib;
708 bool fFullyLoadArchives;
709 bool fLoadAllObjcObjectsFromArchives;
710 bool fFlatNamespace;
711 bool fLinkingMainExecutable;
712 bool fForFinalLinkedImage;
713 bool fForStatic;
714 bool fForDyld;
715 bool fMakeTentativeDefinitionsReal;
716 bool fWhyLoad;
717 bool fRootSafe;
718 bool fSetuidSafe;
719 bool fImplicitlyLinkPublicDylibs;
720 bool fAddCompactUnwindEncoding;
721 bool fWarnCompactUnwind;
722 bool fRemoveDwarfUnwindIfCompactExists;
723 bool fAutoOrderInitializers;
724 bool fOptimizeZeroFill;
725 bool fMergeZeroFill;
726 bool fLogObjectFiles;
727 bool fLogAllFiles;
728 bool fTraceDylibs;
729 bool fTraceIndirectDylibs;
730 bool fTraceArchives;
731 bool fTraceEmitJSON;
732 bool fOutputSlidable;
733 bool fWarnWeakExports;
734 bool fObjcGcCompaction;
735 bool fObjCGc;
736 bool fObjCGcOnly;
737 bool fDemangle;
738 bool fTLVSupport;
739 bool fVersionLoadCommand;
740 bool fVersionLoadCommandForcedOn;
741 bool fVersionLoadCommandForcedOff;
742 bool fBuildVersionLoadCommand;
743 bool fFunctionStartsLoadCommand;
744 bool fFunctionStartsForcedOn;
745 bool fFunctionStartsForcedOff;
746 bool fDataInCodeInfoLoadCommand;
747 bool fDataInCodeInfoLoadCommandForcedOn;
748 bool fDataInCodeInfoLoadCommandForcedOff;
749 bool fCanReExportSymbols;
750 bool fObjcCategoryMerging;
751 bool fPageAlignDataAtoms;
752 bool fNeedsThreadLoadCommand;
753 bool fEntryPointLoadCommand;
754 bool fEntryPointLoadCommandForceOn;
755 bool fEntryPointLoadCommandForceOff;
756 bool fSourceVersionLoadCommand;
757 bool fSourceVersionLoadCommandForceOn;
758 bool fSourceVersionLoadCommandForceOff;
759 bool fTargetIOSSimulator;
760 bool fExportDynamic;
761 bool fAbsoluteSymbols;
762 bool fAllowSimulatorToLinkWithMacOSX;
763 bool fKeepDwarfUnwind;
764 bool fKeepDwarfUnwindForcedOn;
765 bool fKeepDwarfUnwindForcedOff;
766 bool fVerboseOptimizationHints;
767 bool fIgnoreOptimizationHints;
768 bool fGenerateDtraceDOF;
769 bool fAllowBranchIslands;
770 bool fTraceSymbolLayout;
771 bool fMarkAppExtensionSafe;
772 bool fCheckAppExtensionSafe;
773 bool fForceLoadSwiftLibs;
774 bool fSharedRegionEncodingV2;
775 bool fUseDataConstSegment;
776 bool fUseDataConstSegmentForceOn;
777 bool fUseDataConstSegmentForceOff;
778 bool fUseTextExecSegment;
779 bool fBundleBitcode;
780 bool fHideSymbols;
781 bool fVerifyBitcode;
782 bool fReverseMapUUIDRename;
783 bool fDeDupe;
784 bool fVerboseDeDupe;
785 const char* fReverseMapPath;
786 std::string fReverseMapTempPath;
787 bool fLTOCodegenOnly;
788 bool fIgnoreAutoLink;
789 bool fAllowDeadDups;
790 bool fAllowWeakImports;
791 bool fNoInitializers;
792 BitcodeMode fBitcodeKind;
793 Platform fPlatform;
794 DebugInfoStripping fDebugInfoStripping;
795 const char* fTraceOutputFile;
796 ld::MacVersionMin fMacVersionMin;
797 ld::IOSVersionMin fIOSVersionMin;
798 ld::WatchOSVersionMin fWatchOSVersionMin;
799 std::vector<AliasPair> fAliases;
800 std::vector<const char*> fInitialUndefines;
801 NameSet fAllowedUndefined;
802 SetWithWildcards fWhyLive;
803 std::vector<ExtraSection> fExtraSections;
804 std::vector<SectionAlignment> fSectionAlignments;
805 std::vector<OrderedSymbol> fOrderedSymbols;
806 std::vector<SegmentStart> fCustomSegmentAddresses;
807 std::vector<SegmentSize> fCustomSegmentSizes;
808 std::vector<SegmentProtect> fCustomSegmentProtections;
809 std::vector<DylibOverride> fDylibOverrides;
810 std::vector<const char*> fLLVMOptions;
811 std::vector<const char*> fLibrarySearchPaths;
812 std::vector<const char*> fFrameworkSearchPaths;
813 std::vector<const char*> fSDKPaths;
814 std::vector<const char*> fDyldEnvironExtras;
815 std::vector<const char*> fSegmentOrder;
816 std::vector<const char*> fASTFilePaths;
817 std::vector<SectionOrderList> fSectionOrder;
818 std::vector< std::vector<const char*> > fLinkerOptions;
819 std::vector<SectionRename> fSectionRenames;
820 std::vector<SegmentRename> fSegmentRenames;
821 std::vector<SymbolsMove> fSymbolsMovesData;
822 std::vector<SymbolsMove> fSymbolsMovesCode;
823 bool fSaveTempFiles;
824 mutable Snapshot fLinkSnapshot;
825 bool fSnapshotRequested;
826 const char* fPipelineFifo;
827 const char* fDependencyInfoPath;
828 mutable int fDependencyFileDescriptor;
829 mutable int fTraceFileDescriptor;
830 uint8_t fMaxDefaultCommonAlign;
831 UnalignedPointerTreatment fUnalignedPointerTreatment;
832};
833
834
835
836#endif // __OPTIONS__