]> git.saurik.com Git - apple/ld64.git/blame - src/ld/Options.h
ld64-305.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 };
bee7e226 91 enum UnalignedPointerTreatment { kUnalignedPointerError, kUnalignedPointerWarning, kUnalignedPointerIgnore };
eaf282aa 92#if SUPPORT_APPLE_TV
bee7e226 93 enum Platform { kPlatformUnknown, kPlatformOSX=1, kPlatformiOS=2, kPlatformWatchOS=3, kPlatform_tvOS=4, kPlatform_bridgeOS=5 };
eaf282aa
A
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
bee7e226
A
127 case kPlatform_bridgeOS:
128 return "bridgeOS";
eaf282aa
A
129 case kPlatformUnknown:
130 default:
131 return "(unknown)";
132 }
133 }
c2646906 134
82b4b32b
A
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;
bee7e226
A
150 case 5:
151 strcpy(versionString, "4.0");
152 break;
82b4b32b
A
153 default:
154 sprintf(versionString, "unknown ABI version 0x%02X", value);
155 }
156 }
157
158
ebf6f434
A
159 class FileInfo {
160 public:
c2646906 161 const char* path;
d696c285 162 time_t modTime;
55e3d2f6 163 LibraryOptions options;
ebf6f434
A
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.
82b4b32b 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; };
ebf6f434 175
ec29ba20
A
176 FileInfo &operator=(FileInfo other) {
177 std::swap(path, other.path);
ec29ba20
A
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
ebf6f434 187 // Create an empty FileInfo. The path can be set implicitly by checkFileExists().
82b4b32b 188 FileInfo() : path(NULL), modTime(-1), options(), fromFileList(false) {};
ebf6f434
A
189
190 // Create a FileInfo for a specific path, but does not stat the file.
82b4b32b 191 FileInfo(const char *_path) : path(strdup(_path)), modTime(-1), options(), fromFileList(false) {};
ebf6f434
A
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.
f80fe69f 199 bool checkFileExists(const Options& options, const char *p=NULL);
ebf6f434
A
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.
0a8dc3df 203 bool missing() const { return modTime == -1; }
f80fe69f 204 };
d696c285 205
c2646906
A
206 struct ExtraSection {
207 const char* segmentName;
208 const char* sectionName;
209 const char* path;
210 const uint8_t* data;
211 uint64_t dataLen;
a645023d
A
212 typedef ExtraSection* iterator;
213 typedef const ExtraSection* const_iterator;
c2646906 214 };
d696c285 215
c2646906
A
216 struct SectionAlignment {
217 const char* segmentName;
218 const char* sectionName;
219 uint8_t alignment;
220 };
221
599556ff
A
222 struct SectionOrderList {
223 const char* segmentName;
224 std::vector<const char*> sectionOrder;
225 };
226
a61fdf0a
A
227 struct OrderedSymbol {
228 const char* symbolName;
229 const char* objectFileName;
230 };
a645023d 231 typedef const OrderedSymbol* OrderedSymbolsIterator;
a61fdf0a
A
232
233 struct SegmentStart {
234 const char* name;
235 uint64_t address;
236 };
237
55e3d2f6
A
238 struct SegmentSize {
239 const char* name;
240 uint64_t size;
241 };
242
a61fdf0a
A
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
a645023d
A
254 struct AliasPair {
255 const char* realName;
256 const char* alias;
257 };
258
9543cb2f
A
259 struct SectionRename {
260 const char* fromSegment;
261 const char* fromSection;
262 const char* toSegment;
263 const char* toSection;
264 };
265
599556ff
A
266 struct SegmentRename {
267 const char* fromSegment;
268 const char* toSegment;
269 };
9543cb2f 270
f80fe69f
A
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
a645023d 278 typedef const char* const* UndefinesIterator;
a61fdf0a 279
a645023d
A
280// const ObjectFile::ReaderOptions& readerOptions();
281 const char* outputFilePath() const { return fOutputFile; }
282 const std::vector<FileInfo>& getInputFiles() const { return fInputFiles; }
d696c285 283
a645023d
A
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; }
ec29ba20 288 bool enforceDylibSubtypesMatch() const { return fEnforceDylibSubtypesMatch; }
a645023d
A
289 bool forceCpuSubtypeAll() const { return fForceSubtypeAll; }
290 const char* architectureName() const { return fArchitectureName; }
eaf282aa 291 void setArchitecture(cpu_type_t, cpu_subtype_t subtype, Options::Platform platform);
afe874b1 292 bool archSupportsThumb2() const { return fArchSupportsThumb2; }
a645023d
A
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
b2fa67a8
A
298 uint64_t currentVersion() const { return fDylibCurrentVersion; } // only for kDynamicLibrary
299 uint32_t currentVersion32() const; // only for kDynamicLibrary
a645023d
A
300 uint32_t compatibilityVersion() const { return fDylibCompatVersion; } // only for kDynamicLibrary
301 const char* entryName() const { return fEntryName; } // only for kDynamicExecutable or kStaticExecutable
d696c285 302 const char* executablePath();
a645023d
A
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;
eaf282aa 316 std::vector<const char*> exportsData() const;
a645023d
A
317 bool ignoreOtherArchInputFiles() const { return fIgnoreOtherArchFiles; }
318 bool traceDylibs() const { return fTraceDylibs; }
319 bool traceArchives() const { return fTraceArchives; }
0a8dc3df 320 bool traceEmitJSON() const { return fTraceEmitJSON; }
a645023d
A
321 bool deadCodeStrip() const { return fDeadStrip; }
322 UndefinedTreatment undefinedTreatment() const { return fUndefinedTreatment; }
323 ld::MacVersionMin macosxVersionMin() const { return fMacVersionMin; }
afe874b1 324 ld::IOSVersionMin iOSVersionMin() const { return fIOSVersionMin; }
eaf282aa
A
325 ld::WatchOSVersionMin watchOSVersionMin() const { return fWatchOSVersionMin; }
326 uint32_t minOSversion() const;
afe874b1 327 bool minOS(ld::MacVersionMin mac, ld::IOSVersionMin iPhoneOS);
eaf282aa 328 bool min_iOS(ld::IOSVersionMin requirediOSMin);
c2646906 329 bool messagesPrefixedWithArchitecture();
d696c285 330 Treatment picTreatment();
a645023d
A
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
d696c285 336 const char* dotOutputFile();
a645023d
A
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()]; }
599556ff 345 const std::vector<const char*>& initialUndefines() const { return fInitialUndefines; }
a645023d
A
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; }
d696c285 353 bool keepRelocations();
0a8dc3df 354 FileInfo findFile(const std::string &path, const ld::dylib::File* fromDylib=nullptr) const;
ec29ba20 355 bool findFile(const std::string &path, const std::vector<std::string> &tbdExtensions, FileInfo& result) const;
a645023d 356 UUIDMode UUIDMode() const { return fUUIDMode; }
d696c285
A
357 bool warnStabs();
358 bool pauseAtEnd() { return fPause; }
a645023d
A
359 bool printStatistics() const { return fStatistics; }
360 bool printArchPrefix() const { return fMessagesPrefixedWithArchitecture; }
a61fdf0a 361 void gotoClassicLinker(int argc, const char* argv[]);
a645023d
A
362 bool sharedRegionEligible() const { return fSharedRegionEligible; }
363 bool printOrderFileStatistics() const { return fPrintOrderFileStatistics; }
a61fdf0a
A
364 const char* dTraceScriptName() { return fDtraceScriptName; }
365 bool dTrace() { return (fDtraceScriptName != NULL); }
a645023d
A
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; }
a61fdf0a 370 uint64_t baseWritableAddress() { return fBaseWritableAddress; }
a645023d
A
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; }
a61fdf0a 381 bool readOnlyx86Stubs() { return fReadOnlyx86Stubs; }
a645023d
A
382 const std::vector<DylibOverride>& dylibOverrides() const { return fDylibOverrides; }
383 const char* generatedMapPath() const { return fMapPath; }
384 bool positionIndependentExecutable() const { return fPositionIndependentExecutable; }
0a8dc3df 385 Options::FileInfo findIndirectDylib(const std::string& installName, const ld::dylib::File* fromDylib) const;
a645023d
A
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); }
a61fdf0a 389 LocalSymbolHandling localSymbolHandling() { return fLocalSymbolHandling; }
a645023d
A
390 bool keepLocalSymbol(const char* symbolName) const;
391 bool allowTextRelocs() const { return fAllowTextRelocs; }
392 bool warnAboutTextRelocs() const { return fWarnTextRelocs; }
ebf6f434 393 bool kextsUseStubs() const { return fKextsUseStubs; }
a645023d
A
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; }
599556ff 399 const std::vector<const char*>& segmentOrder() const{ return fSegmentOrder; }
eaf282aa 400 bool segmentOrderAfterFixedAddressSegment(const char* segName) const;
599556ff 401 const std::vector<const char*>* sectionOrder(const char* segName) const;
a645023d 402 const std::vector<const char*>& dyldEnvironExtras() const{ return fDyldEnvironExtras; }
599556ff 403 const std::vector<const char*>& astFilePaths() const{ return fASTFilePaths; }
a645023d 404 bool makeCompressedDyldInfo() const { return fMakeCompressedDyldInfo; }
55e3d2f6 405 bool hasExportedSymbolOrder();
a645023d 406 bool exportedSymbolOrder(const char* sym, unsigned int* order) const;
55e3d2f6 407 bool orderData() { return fOrderData; }
a645023d
A
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; }
afe874b1 418 bool mergeZeroFill() const { return fMergeZeroFill; }
a645023d
A
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; }
eaf282aa 436 bool addVersionLoadCommand() const { return fVersionLoadCommand && (fPlatform != kPlatformUnknown); }
bee7e226 437 bool addBuildVersionLoadCommand() const { return fBuildVersionLoadCommand; }
a645023d 438 bool addFunctionStarts() const { return fFunctionStartsLoadCommand; }
ebf6f434 439 bool addDataInCodeInfo() const { return fDataInCodeInfoLoadCommand; }
a645023d 440 bool canReExportSymbols() const { return fCanReExportSymbols; }
0a8dc3df
A
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; }
a645023d 445 const char* tempLtoObjectPath() const { return fTempLtoObjectPath; }
ebf6f434 446 const char* overridePathlibLTO() const { return fOverridePathlibLTO; }
f80fe69f 447 const char* mcpuLTO() const { return fLtoCpu; }
a645023d 448 bool objcCategoryMerging() const { return fObjcCategoryMerging; }
afe874b1 449 bool pageAlignDataAtoms() const { return fPageAlignDataAtoms; }
f80fe69f 450 bool keepDwarfUnwind() const { return fKeepDwarfUnwind; }
9543cb2f
A
451 bool verboseOptimizationHints() const { return fVerboseOptimizationHints; }
452 bool ignoreOptimizationHints() const { return fIgnoreOptimizationHints; }
f80fe69f 453 bool generateDtraceDOF() const { return fGenerateDtraceDOF; }
9543cb2f 454 bool allowBranchIslands() const { return fAllowBranchIslands; }
599556ff
A
455 bool traceSymbolLayout() const { return fTraceSymbolLayout; }
456 bool markAppExtensionSafe() const { return fMarkAppExtensionSafe; }
457 bool checkDylibsAreAppExtensionSafe() const { return fCheckAppExtensionSafe; }
458 bool forceLoadSwiftLibs() const { return fForceLoadSwiftLibs; }
eaf282aa
A
459 bool bundleBitcode() const { return fBundleBitcode; }
460 bool hideSymbols() const { return fHideSymbols; }
dd9e569f 461 bool verifyBitcode() const { return fVerifyBitcode; }
eaf282aa 462 bool renameReverseSymbolMap() const { return fReverseMapUUIDRename; }
ec29ba20
A
463 bool deduplicateFunctions() const { return fDeDupe; }
464 bool verboseDeduplicate() const { return fVerboseDeDupe; }
eaf282aa
A
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; }
dd9e569f 469 bool allowDeadDuplicates() const { return fAllowDeadDups; }
0a8dc3df 470 bool allowWeakImports() const { return fAllowWeakImports; }
bee7e226 471 bool noInitializers() const { return fNoInitializers; }
dd9e569f 472 BitcodeMode bitcodeKind() const { return fBitcodeKind; }
eaf282aa
A
473 bool sharedRegionEncodingV2() const { return fSharedRegionEncodingV2; }
474 bool useDataConstSegment() const { return fUseDataConstSegment; }
0a8dc3df 475 bool useTextExecSegment() const { return fUseTextExecSegment; }
a645023d
A
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;
f80fe69f 481 bool forceCoalesce(const char* symbolName) const;
ebf6f434 482 Snapshot& snapshot() const { return fLinkSnapshot; }
b2fa67a8 483 bool errorBecauseOfWarnings() const;
ebf6f434
A
484 bool needsThreadLoadCommand() const { return fNeedsThreadLoadCommand; }
485 bool needsEntryPointLoadCommand() const { return fEntryPointLoadCommand; }
486 bool needsSourceVersionLoadCommand() const { return fSourceVersionLoadCommand; }
f80fe69f
A
487 bool canUseAbsoluteSymbols() const { return fAbsoluteSymbols; }
488 bool allowSimulatorToLinkWithMacOSX() const { return fAllowSimulatorToLinkWithMacOSX; }
ebf6f434
A
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; }
f80fe69f
A
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;
ba348e21 501 bool armUsesZeroCostExceptions() const;
9543cb2f 502 const std::vector<SectionRename>& sectionRenames() const { return fSectionRenames; }
599556ff
A
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;
eaf282aa
A
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;
ec29ba20 511 uint8_t maxDefaultCommonAlign() const { return fMaxDefaultCommonAlign; }
0a8dc3df
A
512 bool hasDataSymbolMoves() const { return !fSymbolsMovesData.empty(); }
513 bool hasCodeSymbolMoves() const { return !fSymbolsMovesCode.empty(); }
82b4b32b 514 void writeToTraceFile(const char* buffer, size_t len) const;
bee7e226 515 UnalignedPointerTreatment unalignedPointerTreatment() const { return fUnalignedPointerTreatment; }
ec29ba20
A
516
517 static uint32_t parseVersionNumber32(const char*);
f80fe69f 518
c2646906 519private:
d425e388
A
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;
c2646906
A
522 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
523 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
2f2f92e4 524 enum InterposeMode { kInterposeNone, kInterposeAllExternal, kInterposeSome };
c2646906 525
a61fdf0a
A
526 class SetWithWildcards {
527 public:
528 void insert(const char*);
599556ff
A
529 bool contains(const char*, bool* wildCardMatch=NULL) const;
530 bool containsWithPrefix(const char* symbol, const char* file, bool& wildCardMatch) const;
a645023d
A
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&);
eaf282aa 537 std::vector<const char*> data() const;
a61fdf0a 538 private:
2f2f92e4 539 static bool hasWildCards(const char*);
a645023d
A
540 bool wildCardMatch(const char* pattern, const char* candidate) const;
541 bool inCharRange(const char*& range, unsigned char c) const;
a61fdf0a
A
542
543 NameSet fRegular;
544 std::vector<const char*> fWildCard;
545 };
546
599556ff
A
547 struct SymbolsMove {
548 const char* toSegment;
549 SetWithWildcards symbols;
550 };
a61fdf0a 551
c2646906
A
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);
f80fe69f 556 FileInfo findFramework(const char* rootName, const char* suffix) const;
d696c285 557 bool checkForFile(const char* format, const char* dir, const char* rootName,
a645023d 558 FileInfo& result) const;
b2fa67a8 559 uint64_t parseVersionNumber64(const char*);
eaf282aa
A
560 std::string getVersionString32(uint32_t ver) const;
561 std::string getVersionString64(uint64_t ver) const;
ec29ba20 562 bool parsePackedVersion32(const std::string& versionStr, uint32_t &result);
c2646906 563 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
a61fdf0a 564 void parseOrderFile(const char* path, bool cstring);
c2646906
A
565 void addSection(const char* segment, const char* section, const char* path);
566 void addSubLibrary(const char* name);
ebf6f434 567 void loadFileList(const char* fileOfPaths, ld::File::Ordinal baseOrdinal);
c2646906 568 uint64_t parseAddress(const char* addr);
a61fdf0a
A
569 void loadExportFile(const char* fileOfExports, const char* option, SetWithWildcards& set);
570 void parseAliasFile(const char* fileOfAliases);
c2646906
A
571 void parsePreCommandLineEnvironmentSettings();
572 void parsePostCommandLineEnvironmentSettings();
573 void setUndefinedTreatment(const char* treatment);
2f2f92e4 574 void setMacOSXVersionMin(const char* version);
afe874b1 575 void setIOSVersionMin(const char* version);
eaf282aa 576 void setWatchOSVersionMin(const char* version);
c2646906 577 void setWeakReferenceMismatchTreatment(const char* treatment);
a61fdf0a 578 void addDylibOverride(const char* paths);
c2646906
A
579 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
580 CommonsMode parseCommonsTreatment(const char* mode);
d696c285 581 Treatment parseTreatment(const char* treatment);
69a49097 582 void reconfigureDefaults();
a61fdf0a
A
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);
55e3d2f6 588 void loadSymbolOrderFile(const char* fileOfExports, NameToOrder& orderMapping);
9543cb2f 589 void addSectionRename(const char* srcSegment, const char* srcSection, const char* dstSegment, const char* dstSection);
599556ff
A
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);
eaf282aa 592 void cannotBeUsedWithBitcode(const char* arg);
d696c285 593
a645023d
A
594
595// ObjectFile::ReaderOptions fReaderOptions;
c2646906
A
596 const char* fOutputFile;
597 std::vector<Options::FileInfo> fInputFiles;
598 cpu_type_t fArchitecture;
2f2f92e4 599 cpu_subtype_t fSubArchitecture;
a645023d 600 const char* fArchitectureName;
c2646906 601 OutputKind fOutputKind;
2f2f92e4 602 bool fHasPreferredSubType;
afe874b1 603 bool fArchSupportsThumb2;
d696c285 604 bool fPrebind;
c2646906 605 bool fBindAtLoad;
c2646906 606 bool fKeepPrivateExterns;
a61fdf0a 607 bool fNeedsModuleTable;
c2646906 608 bool fIgnoreOtherArchFiles;
55e3d2f6 609 bool fErrorOnOtherArchFiles;
c2646906 610 bool fForceSubtypeAll;
2f2f92e4 611 InterposeMode fInterposeMode;
a645023d 612 bool fDeadStrip;
c2646906
A
613 NameSpace fNameSpace;
614 uint32_t fDylibCompatVersion;
b2fa67a8 615 uint64_t fDylibCurrentVersion;
c2646906 616 const char* fDylibInstallName;
a61fdf0a 617 const char* fFinalName;
c2646906
A
618 const char* fEntryName;
619 uint64_t fBaseAddress;
a645023d 620 uint64_t fMaxAddress;
a61fdf0a
A
621 uint64_t fBaseWritableAddress;
622 bool fSplitSegs;
623 SetWithWildcards fExportSymbols;
624 SetWithWildcards fDontExportSymbols;
2f2f92e4 625 SetWithWildcards fInterposeList;
a645023d
A
626 SetWithWildcards fForceWeakSymbols;
627 SetWithWildcards fForceNotWeakSymbols;
628 SetWithWildcards fReExportSymbols;
f80fe69f 629 SetWithWildcards fForceCoalesceSymbols;
a645023d 630 NameSet fRemovedExports;
55e3d2f6 631 NameToOrder fExportSymbolsOrder;
c2646906
A
632 ExportMode fExportMode;
633 LibrarySearchMode fLibrarySearchMode;
634 UndefinedTreatment fUndefinedTreatment;
635 bool fMessagesPrefixedWithArchitecture;
c2646906
A
636 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
637 std::vector<const char*> fSubUmbellas;
638 std::vector<const char*> fSubLibraries;
d696c285 639 std::vector<const char*> fAllowableClients;
a61fdf0a 640 std::vector<const char*> fRPaths;
d696c285 641 const char* fClientName;
c2646906
A
642 const char* fUmbrellaName;
643 const char* fInitFunctionName;
d696c285
A
644 const char* fDotOutputFile;
645 const char* fExecutablePath;
69a49097 646 const char* fBundleLoader;
a61fdf0a
A
647 const char* fDtraceScriptName;
648 const char* fSegAddrTablePath;
649 const char* fMapPath;
a645023d 650 const char* fDyldInstallPath;
0a8dc3df
A
651 const char* fLtoCachePath;
652 int fLtoPruneInterval;
653 int fLtoPruneAfter;
654 unsigned fLtoMaxCacheSize;
a645023d 655 const char* fTempLtoObjectPath;
ebf6f434 656 const char* fOverridePathlibLTO;
f80fe69f 657 const char* fLtoCpu;
c2646906
A
658 uint64_t fZeroPageSize;
659 uint64_t fStackSize;
660 uint64_t fStackAddr;
ebf6f434
A
661 uint64_t fSourceVersion;
662 uint32_t fSDKVersion;
d696c285 663 bool fExecutableStack;
a645023d
A
664 bool fNonExecutableHeap;
665 bool fDisableNonExecutableHeap;
c2646906 666 uint32_t fMinimumHeaderPad;
55e3d2f6 667 uint64_t fSegmentAlignment;
c2646906 668 CommonsMode fCommonsMode;
a645023d 669 enum UUIDMode fUUIDMode;
a61fdf0a
A
670 SetWithWildcards fLocalSymbolsIncluded;
671 SetWithWildcards fLocalSymbolsExcluded;
672 LocalSymbolHandling fLocalSymbolHandling;
c2646906 673 bool fWarnCommons;
6e880c60 674 bool fVerbose;
d696c285 675 bool fKeepRelocations;
d696c285
A
676 bool fWarnStabs;
677 bool fTraceDylibSearching;
678 bool fPause;
679 bool fStatistics;
680 bool fPrintOptions;
a61fdf0a 681 bool fSharedRegionEligible;
eaf282aa 682 bool fSharedRegionEligibleForceOff;
a61fdf0a
A
683 bool fPrintOrderFileStatistics;
684 bool fReadOnlyx86Stubs;
685 bool fPositionIndependentExecutable;
a645023d 686 bool fPIEOnCommandLine;
d9246299 687 bool fDisablePositionIndependentExecutable;
a61fdf0a
A
688 bool fMaxMinimumHeaderPad;
689 bool fDeadStripDylibs;
2f2f92e4
A
690 bool fAllowTextRelocs;
691 bool fWarnTextRelocs;
ebf6f434 692 bool fKextsUseStubs;
2f2f92e4
A
693 bool fUsingLazyDylibLinking;
694 bool fEncryptable;
eaf282aa
A
695 bool fEncryptableForceOn;
696 bool fEncryptableForceOff;
55e3d2f6
A
697 bool fOrderData;
698 bool fMarkDeadStrippableDylib;
55e3d2f6 699 bool fMakeCompressedDyldInfo;
a645023d 700 bool fMakeCompressedDyldInfoForceOff;
55e3d2f6
A
701 bool fNoEHLabels;
702 bool fAllowCpuSubtypeMismatches;
ec29ba20 703 bool fEnforceDylibSubtypesMatch;
fb24a050 704 bool fUseSimplifiedDylibReExports;
a645023d
A
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;
afe874b1 725 bool fMergeZeroFill;
a645023d
A
726 bool fLogObjectFiles;
727 bool fLogAllFiles;
728 bool fTraceDylibs;
729 bool fTraceIndirectDylibs;
730 bool fTraceArchives;
0a8dc3df 731 bool fTraceEmitJSON;
a645023d
A
732 bool fOutputSlidable;
733 bool fWarnWeakExports;
734 bool fObjcGcCompaction;
735 bool fObjCGc;
736 bool fObjCGcOnly;
737 bool fDemangle;
738 bool fTLVSupport;
739 bool fVersionLoadCommand;
afe874b1
A
740 bool fVersionLoadCommandForcedOn;
741 bool fVersionLoadCommandForcedOff;
bee7e226 742 bool fBuildVersionLoadCommand;
a645023d 743 bool fFunctionStartsLoadCommand;
afe874b1
A
744 bool fFunctionStartsForcedOn;
745 bool fFunctionStartsForcedOff;
ebf6f434 746 bool fDataInCodeInfoLoadCommand;
b1f7435d
A
747 bool fDataInCodeInfoLoadCommandForcedOn;
748 bool fDataInCodeInfoLoadCommandForcedOff;
a645023d
A
749 bool fCanReExportSymbols;
750 bool fObjcCategoryMerging;
afe874b1 751 bool fPageAlignDataAtoms;
ebf6f434
A
752 bool fNeedsThreadLoadCommand;
753 bool fEntryPointLoadCommand;
754 bool fEntryPointLoadCommandForceOn;
755 bool fEntryPointLoadCommandForceOff;
756 bool fSourceVersionLoadCommand;
757 bool fSourceVersionLoadCommandForceOn;
758 bool fSourceVersionLoadCommandForceOff;
f80fe69f
A
759 bool fTargetIOSSimulator;
760 bool fExportDynamic;
761 bool fAbsoluteSymbols;
762 bool fAllowSimulatorToLinkWithMacOSX;
763 bool fKeepDwarfUnwind;
764 bool fKeepDwarfUnwindForcedOn;
765 bool fKeepDwarfUnwindForcedOff;
9543cb2f
A
766 bool fVerboseOptimizationHints;
767 bool fIgnoreOptimizationHints;
f80fe69f 768 bool fGenerateDtraceDOF;
9543cb2f 769 bool fAllowBranchIslands;
599556ff
A
770 bool fTraceSymbolLayout;
771 bool fMarkAppExtensionSafe;
772 bool fCheckAppExtensionSafe;
773 bool fForceLoadSwiftLibs;
eaf282aa
A
774 bool fSharedRegionEncodingV2;
775 bool fUseDataConstSegment;
776 bool fUseDataConstSegmentForceOn;
777 bool fUseDataConstSegmentForceOff;
0a8dc3df 778 bool fUseTextExecSegment;
eaf282aa
A
779 bool fBundleBitcode;
780 bool fHideSymbols;
dd9e569f 781 bool fVerifyBitcode;
eaf282aa 782 bool fReverseMapUUIDRename;
ec29ba20
A
783 bool fDeDupe;
784 bool fVerboseDeDupe;
eaf282aa
A
785 const char* fReverseMapPath;
786 std::string fReverseMapTempPath;
787 bool fLTOCodegenOnly;
788 bool fIgnoreAutoLink;
dd9e569f 789 bool fAllowDeadDups;
0a8dc3df 790 bool fAllowWeakImports;
bee7e226 791 bool fNoInitializers;
dd9e569f 792 BitcodeMode fBitcodeKind;
eaf282aa 793 Platform fPlatform;
a645023d
A
794 DebugInfoStripping fDebugInfoStripping;
795 const char* fTraceOutputFile;
796 ld::MacVersionMin fMacVersionMin;
afe874b1 797 ld::IOSVersionMin fIOSVersionMin;
eaf282aa 798 ld::WatchOSVersionMin fWatchOSVersionMin;
a645023d 799 std::vector<AliasPair> fAliases;
c2646906 800 std::vector<const char*> fInitialUndefines;
a61fdf0a 801 NameSet fAllowedUndefined;
eaf282aa 802 SetWithWildcards fWhyLive;
c2646906
A
803 std::vector<ExtraSection> fExtraSections;
804 std::vector<SectionAlignment> fSectionAlignments;
a61fdf0a
A
805 std::vector<OrderedSymbol> fOrderedSymbols;
806 std::vector<SegmentStart> fCustomSegmentAddresses;
55e3d2f6 807 std::vector<SegmentSize> fCustomSegmentSizes;
a61fdf0a
A
808 std::vector<SegmentProtect> fCustomSegmentProtections;
809 std::vector<DylibOverride> fDylibOverrides;
55e3d2f6 810 std::vector<const char*> fLLVMOptions;
c2646906
A
811 std::vector<const char*> fLibrarySearchPaths;
812 std::vector<const char*> fFrameworkSearchPaths;
6e880c60 813 std::vector<const char*> fSDKPaths;
a645023d 814 std::vector<const char*> fDyldEnvironExtras;
599556ff
A
815 std::vector<const char*> fSegmentOrder;
816 std::vector<const char*> fASTFilePaths;
817 std::vector<SectionOrderList> fSectionOrder;
f80fe69f 818 std::vector< std::vector<const char*> > fLinkerOptions;
9543cb2f 819 std::vector<SectionRename> fSectionRenames;
599556ff
A
820 std::vector<SegmentRename> fSegmentRenames;
821 std::vector<SymbolsMove> fSymbolsMovesData;
822 std::vector<SymbolsMove> fSymbolsMovesCode;
a61fdf0a 823 bool fSaveTempFiles;
f80fe69f
A
824 mutable Snapshot fLinkSnapshot;
825 bool fSnapshotRequested;
826 const char* fPipelineFifo;
827 const char* fDependencyInfoPath;
828 mutable int fDependencyFileDescriptor;
82b4b32b 829 mutable int fTraceFileDescriptor;
ec29ba20 830 uint8_t fMaxDefaultCommonAlign;
bee7e226 831 UnalignedPointerTreatment fUnalignedPointerTreatment;
c2646906
A
832};
833
834
835
c2646906 836#endif // __OPTIONS__