]> git.saurik.com Git - apple/ld64.git/blame - src/ld/Options.h
ld64-264.3.101.tar.gz
[apple/ld64.git] / src / ld / Options.h
CommitLineData
d696c285 1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
6e880c60 2 *
a645023d 3 * Copyright (c) 2005-2010 Apple Inc. All rights reserved.
c2646906
A
4 *
5 * @APPLE_LICENSE_HEADER_START@
d696c285 6 *
c2646906
A
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.
d696c285 13 *
c2646906
A
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.
d696c285 21 *
c2646906
A
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
c2646906 32#include <vector>
d425e388
A
33#include <unordered_set>
34#include <unordered_map>
c2646906 35
a645023d 36#include "ld.hpp"
ebf6f434 37#include "Snapshot.h"
eaf282aa 38#include "MachOFileAbstraction.hpp"
c2646906 39
fb24a050
A
40extern void throwf (const char* format, ...) __attribute__ ((noreturn,format(printf, 1, 2)));
41extern void warning(const char* format, ...) __attribute__((format(printf, 1, 2)));
c2646906 42
ebf6f434
A
43class Snapshot;
44
55e3d2f6 45class LibraryOptions
c2646906
A
46{
47public:
a645023d 48 LibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false),
f80fe69f
A
49 fLazyLoad(false), fUpward(false), fIndirectDylib(false),
50 fForceLoad(false) {}
55e3d2f6 51 // for dynamic libraries
c2646906
A
52 bool fWeakImport;
53 bool fReExport;
69a49097 54 bool fBundleLoader;
2f2f92e4 55 bool fLazyLoad;
a645023d 56 bool fUpward;
f80fe69f 57 bool fIndirectDylib;
55e3d2f6
A
58 // for static libraries
59 bool fForceLoad;
c2646906
A
60};
61
55e3d2f6
A
62
63
d696c285
A
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//
c2646906
A
73class Options
74{
75public:
d696c285
A
76 Options(int argc, const char* argv[]);
77 ~Options();
c2646906 78
55e3d2f6 79 enum OutputKind { kDynamicExecutable, kStaticExecutable, kDynamicLibrary, kDynamicBundle, kObjectFile, kDyld, kPreload, kKextBundle };
c2646906 80 enum NameSpace { kTwoLevelNameSpace, kFlatNameSpace, kForceFlatNameSpace };
d696c285
A
81 // Standard treatment for many options.
82 enum Treatment { kError, kWarning, kSuppress, kNULL, kInvalid };
c2646906 83 enum UndefinedTreatment { kUndefinedError, kUndefinedWarning, kUndefinedSuppress, kUndefinedDynamicLookup };
d696c285
A
84 enum WeakReferenceMismatchTreatment { kWeakReferenceMismatchError, kWeakReferenceMismatchWeak,
85 kWeakReferenceMismatchNonWeak };
c2646906 86 enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
a61fdf0a
A
87 enum UUIDMode { kUUIDNone, kUUIDRandom, kUUIDContent };
88 enum LocalSymbolHandling { kLocalSymbolsAll, kLocalSymbolsNone, kLocalSymbolsSelectiveInclude, kLocalSymbolsSelectiveExclude };
dd9e569f 89 enum BitcodeMode { kBitcodeProcess, kBitcodeAsData, kBitcodeMarker, kBitcodeStrip };
a645023d 90 enum DebugInfoStripping { kDebugInfoNone, kDebugInfoMinimal, kDebugInfoFull };
eaf282aa
A
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
96
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
109 }
110 assert(!lc && "unknown LC_VERSION_MIN load command");
111 return kPlatformUnknown;
112 }
113
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)";
129 }
130 }
c2646906 131
ebf6f434
A
132 class FileInfo {
133 public:
c2646906
A
134 const char* path;
135 uint64_t fileLen;
d696c285 136 time_t modTime;
55e3d2f6 137 LibraryOptions options;
ebf6f434
A
138 ld::File::Ordinal ordinal;
139 bool fromFileList;
140
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;
144
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; };
149
ec29ba20
A
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;
160 }
161
ebf6f434
A
162 // Create an empty FileInfo. The path can be set implicitly by checkFileExists().
163 FileInfo() : path(NULL), fileLen(0), modTime(0), options(), fromFileList(false) {};
164
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) {};
167
168 ~FileInfo() { if (path) ::free((void*)path); }
169
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.
f80fe69f 174 bool checkFileExists(const Options& options, const char *p=NULL);
ebf6f434
A
175
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; }
f80fe69f 179 };
d696c285 180
c2646906
A
181 struct ExtraSection {
182 const char* segmentName;
183 const char* sectionName;
184 const char* path;
185 const uint8_t* data;
186 uint64_t dataLen;
a645023d
A
187 typedef ExtraSection* iterator;
188 typedef const ExtraSection* const_iterator;
c2646906 189 };
d696c285 190
c2646906
A
191 struct SectionAlignment {
192 const char* segmentName;
193 const char* sectionName;
194 uint8_t alignment;
195 };
196
599556ff
A
197 struct SectionOrderList {
198 const char* segmentName;
199 std::vector<const char*> sectionOrder;
200 };
201
a61fdf0a
A
202 struct OrderedSymbol {
203 const char* symbolName;
204 const char* objectFileName;
205 };
a645023d 206 typedef const OrderedSymbol* OrderedSymbolsIterator;
a61fdf0a
A
207
208 struct SegmentStart {
209 const char* name;
210 uint64_t address;
211 };
212
55e3d2f6
A
213 struct SegmentSize {
214 const char* name;
215 uint64_t size;
216 };
217
a61fdf0a
A
218 struct SegmentProtect {
219 const char* name;
220 uint32_t max;
221 uint32_t init;
222 };
223
224 struct DylibOverride {
225 const char* installName;
226 const char* useInstead;
227 };
228
a645023d
A
229 struct AliasPair {
230 const char* realName;
231 const char* alias;
232 };
233
9543cb2f
A
234 struct SectionRename {
235 const char* fromSegment;
236 const char* fromSection;
237 const char* toSegment;
238 const char* toSection;
239 };
240
599556ff
A
241 struct SegmentRename {
242 const char* fromSegment;
243 const char* toSegment;
244 };
9543cb2f 245
f80fe69f
A
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 };
250
251 void dumpDependency(uint8_t, const char* path) const;
252
a645023d 253 typedef const char* const* UndefinesIterator;
a61fdf0a 254
a645023d
A
255// const ObjectFile::ReaderOptions& readerOptions();
256 const char* outputFilePath() const { return fOutputFile; }
257 const std::vector<FileInfo>& getInputFiles() const { return fInputFiles; }
d696c285 258
a645023d
A
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; }
ec29ba20 263 bool enforceDylibSubtypesMatch() const { return fEnforceDylibSubtypesMatch; }
a645023d
A
264 bool forceCpuSubtypeAll() const { return fForceSubtypeAll; }
265 const char* architectureName() const { return fArchitectureName; }
eaf282aa 266 void setArchitecture(cpu_type_t, cpu_subtype_t subtype, Options::Platform platform);
afe874b1 267 bool archSupportsThumb2() const { return fArchSupportsThumb2; }
a645023d
A
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
b2fa67a8
A
273 uint64_t currentVersion() const { return fDylibCurrentVersion; } // only for kDynamicLibrary
274 uint32_t currentVersion32() const; // only for kDynamicLibrary
a645023d
A
275 uint32_t compatibilityVersion() const { return fDylibCompatVersion; } // only for kDynamicLibrary
276 const char* entryName() const { return fEntryName; } // only for kDynamicExecutable or kStaticExecutable
d696c285 277 const char* executablePath();
a645023d
A
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;
eaf282aa 291 std::vector<const char*> exportsData() const;
a645023d
A
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; }
afe874b1 298 ld::IOSVersionMin iOSVersionMin() const { return fIOSVersionMin; }
eaf282aa
A
299 ld::WatchOSVersionMin watchOSVersionMin() const { return fWatchOSVersionMin; }
300 uint32_t minOSversion() const;
afe874b1 301 bool minOS(ld::MacVersionMin mac, ld::IOSVersionMin iPhoneOS);
eaf282aa 302 bool min_iOS(ld::IOSVersionMin requirediOSMin);
c2646906 303 bool messagesPrefixedWithArchitecture();
d696c285 304 Treatment picTreatment();
a645023d
A
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
d696c285 310 const char* dotOutputFile();
a645023d
A
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()]; }
599556ff 319 const std::vector<const char*>& initialUndefines() const { return fInitialUndefines; }
a645023d
A
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; }
d696c285 327 bool keepRelocations();
eaf282aa 328 FileInfo findFile(const std::string &path) const;
ec29ba20 329 bool findFile(const std::string &path, const std::vector<std::string> &tbdExtensions, FileInfo& result) const;
a645023d 330 UUIDMode UUIDMode() const { return fUUIDMode; }
d696c285
A
331 bool warnStabs();
332 bool pauseAtEnd() { return fPause; }
a645023d
A
333 bool printStatistics() const { return fStatistics; }
334 bool printArchPrefix() const { return fMessagesPrefixedWithArchitecture; }
a61fdf0a 335 void gotoClassicLinker(int argc, const char* argv[]);
a645023d
A
336 bool sharedRegionEligible() const { return fSharedRegionEligible; }
337 bool printOrderFileStatistics() const { return fPrintOrderFileStatistics; }
a61fdf0a
A
338 const char* dTraceScriptName() { return fDtraceScriptName; }
339 bool dTrace() { return (fDtraceScriptName != NULL); }
a645023d
A
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; }
a61fdf0a 344 uint64_t baseWritableAddress() { return fBaseWritableAddress; }
a645023d
A
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; }
a61fdf0a 355 bool readOnlyx86Stubs() { return fReadOnlyx86Stubs; }
a645023d
A
356 const std::vector<DylibOverride>& dylibOverrides() const { return fDylibOverrides; }
357 const char* generatedMapPath() const { return fMapPath; }
358 bool positionIndependentExecutable() const { return fPositionIndependentExecutable; }
eaf282aa 359 Options::FileInfo findFileUsingPaths(const std::string &path) const;
a645023d
A
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); }
a61fdf0a 363 LocalSymbolHandling localSymbolHandling() { return fLocalSymbolHandling; }
a645023d
A
364 bool keepLocalSymbol(const char* symbolName) const;
365 bool allowTextRelocs() const { return fAllowTextRelocs; }
366 bool warnAboutTextRelocs() const { return fWarnTextRelocs; }
ebf6f434 367 bool kextsUseStubs() const { return fKextsUseStubs; }
a645023d
A
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; }
599556ff 373 const std::vector<const char*>& segmentOrder() const{ return fSegmentOrder; }
eaf282aa 374 bool segmentOrderAfterFixedAddressSegment(const char* segName) const;
599556ff 375 const std::vector<const char*>* sectionOrder(const char* segName) const;
a645023d 376 const std::vector<const char*>& dyldEnvironExtras() const{ return fDyldEnvironExtras; }
599556ff 377 const std::vector<const char*>& astFilePaths() const{ return fASTFilePaths; }
a645023d 378 bool makeCompressedDyldInfo() const { return fMakeCompressedDyldInfo; }
55e3d2f6 379 bool hasExportedSymbolOrder();
a645023d 380 bool exportedSymbolOrder(const char* sym, unsigned int* order) const;
55e3d2f6 381 bool orderData() { return fOrderData; }
a645023d
A
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; }
afe874b1 392 bool mergeZeroFill() const { return fMergeZeroFill; }
a645023d
A
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; }
eaf282aa 410 bool addVersionLoadCommand() const { return fVersionLoadCommand && (fPlatform != kPlatformUnknown); }
a645023d 411 bool addFunctionStarts() const { return fFunctionStartsLoadCommand; }
ebf6f434 412 bool addDataInCodeInfo() const { return fDataInCodeInfoLoadCommand; }
a645023d
A
413 bool canReExportSymbols() const { return fCanReExportSymbols; }
414 const char* tempLtoObjectPath() const { return fTempLtoObjectPath; }
ebf6f434 415 const char* overridePathlibLTO() const { return fOverridePathlibLTO; }
f80fe69f 416 const char* mcpuLTO() const { return fLtoCpu; }
a645023d 417 bool objcCategoryMerging() const { return fObjcCategoryMerging; }
afe874b1 418 bool pageAlignDataAtoms() const { return fPageAlignDataAtoms; }
f80fe69f 419 bool keepDwarfUnwind() const { return fKeepDwarfUnwind; }
9543cb2f
A
420 bool verboseOptimizationHints() const { return fVerboseOptimizationHints; }
421 bool ignoreOptimizationHints() const { return fIgnoreOptimizationHints; }
f80fe69f 422 bool generateDtraceDOF() const { return fGenerateDtraceDOF; }
9543cb2f 423 bool allowBranchIslands() const { return fAllowBranchIslands; }
599556ff
A
424 bool traceSymbolLayout() const { return fTraceSymbolLayout; }
425 bool markAppExtensionSafe() const { return fMarkAppExtensionSafe; }
426 bool checkDylibsAreAppExtensionSafe() const { return fCheckAppExtensionSafe; }
427 bool forceLoadSwiftLibs() const { return fForceLoadSwiftLibs; }
eaf282aa
A
428 bool bundleBitcode() const { return fBundleBitcode; }
429 bool hideSymbols() const { return fHideSymbols; }
dd9e569f 430 bool verifyBitcode() const { return fVerifyBitcode; }
eaf282aa 431 bool renameReverseSymbolMap() const { return fReverseMapUUIDRename; }
ec29ba20
A
432 bool deduplicateFunctions() const { return fDeDupe; }
433 bool verboseDeduplicate() const { return fVerboseDeDupe; }
eaf282aa
A
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; }
dd9e569f
A
438 bool allowDeadDuplicates() const { return fAllowDeadDups; }
439 BitcodeMode bitcodeKind() const { return fBitcodeKind; }
eaf282aa
A
440 bool sharedRegionEncodingV2() const { return fSharedRegionEncodingV2; }
441 bool useDataConstSegment() const { return fUseDataConstSegment; }
a645023d
A
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;
f80fe69f 447 bool forceCoalesce(const char* symbolName) const;
ebf6f434 448 Snapshot& snapshot() const { return fLinkSnapshot; }
b2fa67a8 449 bool errorBecauseOfWarnings() const;
ebf6f434
A
450 bool needsThreadLoadCommand() const { return fNeedsThreadLoadCommand; }
451 bool needsEntryPointLoadCommand() const { return fEntryPointLoadCommand; }
452 bool needsSourceVersionLoadCommand() const { return fSourceVersionLoadCommand; }
f80fe69f
A
453 bool canUseAbsoluteSymbols() const { return fAbsoluteSymbols; }
454 bool allowSimulatorToLinkWithMacOSX() const { return fAllowSimulatorToLinkWithMacOSX; }
ebf6f434
A
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; }
f80fe69f
A
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;
ba348e21 467 bool armUsesZeroCostExceptions() const;
9543cb2f 468 const std::vector<SectionRename>& sectionRenames() const { return fSectionRenames; }
599556ff
A
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;
eaf282aa
A
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;
ec29ba20
A
477 uint8_t maxDefaultCommonAlign() const { return fMaxDefaultCommonAlign; }
478
479 static uint32_t parseVersionNumber32(const char*);
f80fe69f 480
c2646906 481private:
d425e388
A
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;
c2646906
A
484 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
485 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
2f2f92e4 486 enum InterposeMode { kInterposeNone, kInterposeAllExternal, kInterposeSome };
ec29ba20 487 enum FilePreference { kModTime, kTextBasedStub, kMachO };
c2646906 488
a61fdf0a
A
489 class SetWithWildcards {
490 public:
491 void insert(const char*);
599556ff
A
492 bool contains(const char*, bool* wildCardMatch=NULL) const;
493 bool containsWithPrefix(const char* symbol, const char* file, bool& wildCardMatch) const;
a645023d
A
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&);
eaf282aa 500 std::vector<const char*> data() const;
a61fdf0a 501 private:
2f2f92e4 502 static bool hasWildCards(const char*);
a645023d
A
503 bool wildCardMatch(const char* pattern, const char* candidate) const;
504 bool inCharRange(const char*& range, unsigned char c) const;
a61fdf0a
A
505
506 NameSet fRegular;
507 std::vector<const char*> fWildCard;
508 };
509
599556ff
A
510 struct SymbolsMove {
511 const char* toSegment;
512 SetWithWildcards symbols;
513 };
a61fdf0a 514
c2646906
A
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);
f80fe69f 519 FileInfo findFramework(const char* rootName, const char* suffix) const;
d696c285 520 bool checkForFile(const char* format, const char* dir, const char* rootName,
a645023d 521 FileInfo& result) const;
b2fa67a8 522 uint64_t parseVersionNumber64(const char*);
eaf282aa
A
523 std::string getVersionString32(uint32_t ver) const;
524 std::string getVersionString64(uint64_t ver) const;
ec29ba20 525 bool parsePackedVersion32(const std::string& versionStr, uint32_t &result);
c2646906 526 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
a61fdf0a 527 void parseOrderFile(const char* path, bool cstring);
c2646906
A
528 void addSection(const char* segment, const char* section, const char* path);
529 void addSubLibrary(const char* name);
ebf6f434 530 void loadFileList(const char* fileOfPaths, ld::File::Ordinal baseOrdinal);
c2646906 531 uint64_t parseAddress(const char* addr);
a61fdf0a
A
532 void loadExportFile(const char* fileOfExports, const char* option, SetWithWildcards& set);
533 void parseAliasFile(const char* fileOfAliases);
c2646906
A
534 void parsePreCommandLineEnvironmentSettings();
535 void parsePostCommandLineEnvironmentSettings();
536 void setUndefinedTreatment(const char* treatment);
2f2f92e4 537 void setMacOSXVersionMin(const char* version);
afe874b1 538 void setIOSVersionMin(const char* version);
eaf282aa 539 void setWatchOSVersionMin(const char* version);
c2646906 540 void setWeakReferenceMismatchTreatment(const char* treatment);
a61fdf0a 541 void addDylibOverride(const char* paths);
c2646906
A
542 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
543 CommonsMode parseCommonsTreatment(const char* mode);
d696c285 544 Treatment parseTreatment(const char* treatment);
69a49097 545 void reconfigureDefaults();
a61fdf0a
A
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);
55e3d2f6 551 void loadSymbolOrderFile(const char* fileOfExports, NameToOrder& orderMapping);
9543cb2f 552 void addSectionRename(const char* srcSegment, const char* srcSection, const char* dstSegment, const char* dstSection);
599556ff
A
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);
eaf282aa 555 void cannotBeUsedWithBitcode(const char* arg);
d696c285 556
a645023d
A
557
558// ObjectFile::ReaderOptions fReaderOptions;
c2646906
A
559 const char* fOutputFile;
560 std::vector<Options::FileInfo> fInputFiles;
561 cpu_type_t fArchitecture;
2f2f92e4 562 cpu_subtype_t fSubArchitecture;
a645023d 563 const char* fArchitectureName;
c2646906 564 OutputKind fOutputKind;
2f2f92e4 565 bool fHasPreferredSubType;
afe874b1 566 bool fArchSupportsThumb2;
d696c285 567 bool fPrebind;
c2646906 568 bool fBindAtLoad;
c2646906 569 bool fKeepPrivateExterns;
a61fdf0a 570 bool fNeedsModuleTable;
c2646906 571 bool fIgnoreOtherArchFiles;
55e3d2f6 572 bool fErrorOnOtherArchFiles;
c2646906 573 bool fForceSubtypeAll;
2f2f92e4 574 InterposeMode fInterposeMode;
a645023d 575 bool fDeadStrip;
c2646906
A
576 NameSpace fNameSpace;
577 uint32_t fDylibCompatVersion;
b2fa67a8 578 uint64_t fDylibCurrentVersion;
c2646906 579 const char* fDylibInstallName;
a61fdf0a 580 const char* fFinalName;
c2646906
A
581 const char* fEntryName;
582 uint64_t fBaseAddress;
a645023d 583 uint64_t fMaxAddress;
a61fdf0a
A
584 uint64_t fBaseWritableAddress;
585 bool fSplitSegs;
586 SetWithWildcards fExportSymbols;
587 SetWithWildcards fDontExportSymbols;
2f2f92e4 588 SetWithWildcards fInterposeList;
a645023d
A
589 SetWithWildcards fForceWeakSymbols;
590 SetWithWildcards fForceNotWeakSymbols;
591 SetWithWildcards fReExportSymbols;
f80fe69f 592 SetWithWildcards fForceCoalesceSymbols;
a645023d 593 NameSet fRemovedExports;
55e3d2f6 594 NameToOrder fExportSymbolsOrder;
c2646906
A
595 ExportMode fExportMode;
596 LibrarySearchMode fLibrarySearchMode;
597 UndefinedTreatment fUndefinedTreatment;
598 bool fMessagesPrefixedWithArchitecture;
c2646906
A
599 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
600 std::vector<const char*> fSubUmbellas;
601 std::vector<const char*> fSubLibraries;
d696c285 602 std::vector<const char*> fAllowableClients;
a61fdf0a 603 std::vector<const char*> fRPaths;
d696c285 604 const char* fClientName;
c2646906
A
605 const char* fUmbrellaName;
606 const char* fInitFunctionName;
d696c285
A
607 const char* fDotOutputFile;
608 const char* fExecutablePath;
69a49097 609 const char* fBundleLoader;
a61fdf0a
A
610 const char* fDtraceScriptName;
611 const char* fSegAddrTablePath;
612 const char* fMapPath;
a645023d
A
613 const char* fDyldInstallPath;
614 const char* fTempLtoObjectPath;
ebf6f434 615 const char* fOverridePathlibLTO;
f80fe69f 616 const char* fLtoCpu;
c2646906
A
617 uint64_t fZeroPageSize;
618 uint64_t fStackSize;
619 uint64_t fStackAddr;
ebf6f434
A
620 uint64_t fSourceVersion;
621 uint32_t fSDKVersion;
d696c285 622 bool fExecutableStack;
a645023d
A
623 bool fNonExecutableHeap;
624 bool fDisableNonExecutableHeap;
c2646906 625 uint32_t fMinimumHeaderPad;
55e3d2f6 626 uint64_t fSegmentAlignment;
c2646906 627 CommonsMode fCommonsMode;
a645023d 628 enum UUIDMode fUUIDMode;
a61fdf0a
A
629 SetWithWildcards fLocalSymbolsIncluded;
630 SetWithWildcards fLocalSymbolsExcluded;
631 LocalSymbolHandling fLocalSymbolHandling;
c2646906 632 bool fWarnCommons;
6e880c60 633 bool fVerbose;
d696c285 634 bool fKeepRelocations;
d696c285
A
635 bool fWarnStabs;
636 bool fTraceDylibSearching;
637 bool fPause;
638 bool fStatistics;
639 bool fPrintOptions;
a61fdf0a 640 bool fSharedRegionEligible;
eaf282aa 641 bool fSharedRegionEligibleForceOff;
a61fdf0a
A
642 bool fPrintOrderFileStatistics;
643 bool fReadOnlyx86Stubs;
644 bool fPositionIndependentExecutable;
a645023d 645 bool fPIEOnCommandLine;
d9246299 646 bool fDisablePositionIndependentExecutable;
a61fdf0a
A
647 bool fMaxMinimumHeaderPad;
648 bool fDeadStripDylibs;
2f2f92e4
A
649 bool fAllowTextRelocs;
650 bool fWarnTextRelocs;
ebf6f434 651 bool fKextsUseStubs;
2f2f92e4
A
652 bool fUsingLazyDylibLinking;
653 bool fEncryptable;
eaf282aa
A
654 bool fEncryptableForceOn;
655 bool fEncryptableForceOff;
55e3d2f6
A
656 bool fOrderData;
657 bool fMarkDeadStrippableDylib;
55e3d2f6 658 bool fMakeCompressedDyldInfo;
a645023d 659 bool fMakeCompressedDyldInfoForceOff;
55e3d2f6
A
660 bool fNoEHLabels;
661 bool fAllowCpuSubtypeMismatches;
ec29ba20 662 bool fEnforceDylibSubtypesMatch;
fb24a050 663 bool fUseSimplifiedDylibReExports;
a645023d
A
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;
afe874b1 684 bool fMergeZeroFill;
a645023d
A
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;
afe874b1
A
698 bool fVersionLoadCommandForcedOn;
699 bool fVersionLoadCommandForcedOff;
a645023d 700 bool fFunctionStartsLoadCommand;
afe874b1
A
701 bool fFunctionStartsForcedOn;
702 bool fFunctionStartsForcedOff;
ebf6f434 703 bool fDataInCodeInfoLoadCommand;
b1f7435d
A
704 bool fDataInCodeInfoLoadCommandForcedOn;
705 bool fDataInCodeInfoLoadCommandForcedOff;
a645023d
A
706 bool fCanReExportSymbols;
707 bool fObjcCategoryMerging;
afe874b1 708 bool fPageAlignDataAtoms;
ebf6f434
A
709 bool fNeedsThreadLoadCommand;
710 bool fEntryPointLoadCommand;
711 bool fEntryPointLoadCommandForceOn;
712 bool fEntryPointLoadCommandForceOff;
713 bool fSourceVersionLoadCommand;
714 bool fSourceVersionLoadCommandForceOn;
715 bool fSourceVersionLoadCommandForceOff;
f80fe69f
A
716 bool fTargetIOSSimulator;
717 bool fExportDynamic;
718 bool fAbsoluteSymbols;
719 bool fAllowSimulatorToLinkWithMacOSX;
720 bool fKeepDwarfUnwind;
721 bool fKeepDwarfUnwindForcedOn;
722 bool fKeepDwarfUnwindForcedOff;
9543cb2f
A
723 bool fVerboseOptimizationHints;
724 bool fIgnoreOptimizationHints;
f80fe69f 725 bool fGenerateDtraceDOF;
9543cb2f 726 bool fAllowBranchIslands;
599556ff
A
727 bool fTraceSymbolLayout;
728 bool fMarkAppExtensionSafe;
729 bool fCheckAppExtensionSafe;
730 bool fForceLoadSwiftLibs;
eaf282aa
A
731 bool fSharedRegionEncodingV2;
732 bool fUseDataConstSegment;
733 bool fUseDataConstSegmentForceOn;
734 bool fUseDataConstSegmentForceOff;
735 bool fBundleBitcode;
736 bool fHideSymbols;
dd9e569f 737 bool fVerifyBitcode;
eaf282aa 738 bool fReverseMapUUIDRename;
ec29ba20
A
739 bool fDeDupe;
740 bool fVerboseDeDupe;
eaf282aa
A
741 const char* fReverseMapPath;
742 std::string fReverseMapTempPath;
743 bool fLTOCodegenOnly;
744 bool fIgnoreAutoLink;
dd9e569f
A
745 bool fAllowDeadDups;
746 BitcodeMode fBitcodeKind;
eaf282aa 747 Platform fPlatform;
a645023d
A
748 DebugInfoStripping fDebugInfoStripping;
749 const char* fTraceOutputFile;
750 ld::MacVersionMin fMacVersionMin;
afe874b1 751 ld::IOSVersionMin fIOSVersionMin;
eaf282aa 752 ld::WatchOSVersionMin fWatchOSVersionMin;
a645023d 753 std::vector<AliasPair> fAliases;
c2646906 754 std::vector<const char*> fInitialUndefines;
a61fdf0a 755 NameSet fAllowedUndefined;
eaf282aa 756 SetWithWildcards fWhyLive;
c2646906
A
757 std::vector<ExtraSection> fExtraSections;
758 std::vector<SectionAlignment> fSectionAlignments;
a61fdf0a
A
759 std::vector<OrderedSymbol> fOrderedSymbols;
760 std::vector<SegmentStart> fCustomSegmentAddresses;
55e3d2f6 761 std::vector<SegmentSize> fCustomSegmentSizes;
a61fdf0a
A
762 std::vector<SegmentProtect> fCustomSegmentProtections;
763 std::vector<DylibOverride> fDylibOverrides;
55e3d2f6 764 std::vector<const char*> fLLVMOptions;
c2646906
A
765 std::vector<const char*> fLibrarySearchPaths;
766 std::vector<const char*> fFrameworkSearchPaths;
6e880c60 767 std::vector<const char*> fSDKPaths;
a645023d 768 std::vector<const char*> fDyldEnvironExtras;
599556ff
A
769 std::vector<const char*> fSegmentOrder;
770 std::vector<const char*> fASTFilePaths;
771 std::vector<SectionOrderList> fSectionOrder;
f80fe69f 772 std::vector< std::vector<const char*> > fLinkerOptions;
9543cb2f 773 std::vector<SectionRename> fSectionRenames;
599556ff
A
774 std::vector<SegmentRename> fSegmentRenames;
775 std::vector<SymbolsMove> fSymbolsMovesData;
776 std::vector<SymbolsMove> fSymbolsMovesCode;
777 std::vector<SymbolsMove> fSymbolsMovesZeroFill;
a61fdf0a 778 bool fSaveTempFiles;
f80fe69f
A
779 mutable Snapshot fLinkSnapshot;
780 bool fSnapshotRequested;
781 const char* fPipelineFifo;
782 const char* fDependencyInfoPath;
783 mutable int fDependencyFileDescriptor;
ec29ba20
A
784 uint8_t fMaxDefaultCommonAlign;
785 FilePreference fFilePreference;
786 bool fForceTextBasedStub;
c2646906
A
787};
788
789
790
c2646906 791#endif // __OPTIONS__