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