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