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