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