]> git.saurik.com Git - apple/ld64.git/blame - src/Options.h
ld64-85.tar.gz
[apple/ld64.git] / src / Options.h
CommitLineData
d696c285 1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
6e880c60 2 *
a61fdf0a 3 * Copyright (c) 2005-2007 Apple Inc. All rights reserved.
c2646906
A
4 *
5 * @APPLE_LICENSE_HEADER_START@
d696c285 6 *
c2646906
A
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
d696c285 13 *
c2646906
A
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
d696c285 21 *
c2646906
A
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25#ifndef __OPTIONS__
26#define __OPTIONS__
27
28
29#include <stdint.h>
30#include <mach/machine.h>
31
c2646906
A
32#include <vector>
33#include <ext/hash_set>
34
35#include "ObjectFile.h"
36
2f2f92e4
A
37extern void throwf (const char* format, ...) __attribute__ ((noreturn));
38extern void warning(const char* format, ...);
c2646906 39
d696c285 40class DynamicLibraryOptions
c2646906
A
41{
42public:
2f2f92e4 43 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false), fLazyLoad(false) {}
d696c285 44
c2646906
A
45 bool fWeakImport;
46 bool fReExport;
69a49097 47 bool fBundleLoader;
2f2f92e4 48 bool fLazyLoad;
c2646906
A
49};
50
d696c285
A
51//
52// The public interface to the Options class is the abstract representation of what work the linker
53// should do.
54//
55// This abstraction layer will make it easier to support a future where the linker is a shared library
56// invoked directly from Xcode. The target settings in Xcode would be used to directly construct an Options
57// object (without building a command line which is then parsed).
58//
59//
c2646906
A
60class Options
61{
62public:
d696c285
A
63 Options(int argc, const char* argv[]);
64 ~Options();
c2646906
A
65
66 enum OutputKind { kDynamicExecutable, kStaticExecutable, kDynamicLibrary, kDynamicBundle, kObjectFile, kDyld };
67 enum NameSpace { kTwoLevelNameSpace, kFlatNameSpace, kForceFlatNameSpace };
d696c285
A
68 // Standard treatment for many options.
69 enum Treatment { kError, kWarning, kSuppress, kNULL, kInvalid };
c2646906 70 enum UndefinedTreatment { kUndefinedError, kUndefinedWarning, kUndefinedSuppress, kUndefinedDynamicLookup };
d696c285
A
71 enum WeakReferenceMismatchTreatment { kWeakReferenceMismatchError, kWeakReferenceMismatchWeak,
72 kWeakReferenceMismatchNonWeak };
c2646906 73 enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
d696c285 74 enum DeadStripMode { kDeadStripOff, kDeadStripOn, kDeadStripOnPlusUnusedInits };
a61fdf0a
A
75 enum UUIDMode { kUUIDNone, kUUIDRandom, kUUIDContent };
76 enum LocalSymbolHandling { kLocalSymbolsAll, kLocalSymbolsNone, kLocalSymbolsSelectiveInclude, kLocalSymbolsSelectiveExclude };
c2646906
A
77
78 struct FileInfo {
79 const char* path;
80 uint64_t fileLen;
d696c285 81 time_t modTime;
c2646906
A
82 DynamicLibraryOptions options;
83 };
d696c285 84
c2646906
A
85 struct ExtraSection {
86 const char* segmentName;
87 const char* sectionName;
88 const char* path;
89 const uint8_t* data;
90 uint64_t dataLen;
91 };
d696c285 92
c2646906
A
93 struct SectionAlignment {
94 const char* segmentName;
95 const char* sectionName;
96 uint8_t alignment;
97 };
98
a61fdf0a
A
99 struct OrderedSymbol {
100 const char* symbolName;
101 const char* objectFileName;
102 };
103
104 struct SegmentStart {
105 const char* name;
106 uint64_t address;
107 };
108
109 struct SegmentProtect {
110 const char* name;
111 uint32_t max;
112 uint32_t init;
113 };
114
115 struct DylibOverride {
116 const char* installName;
117 const char* useInstead;
118 };
119
120
d696c285
A
121 const ObjectFile::ReaderOptions& readerOptions();
122 const char* getOutputFilePath();
123 std::vector<FileInfo>& getInputFiles();
124
2f2f92e4
A
125 cpu_type_t architecture() { return fArchitecture; }
126 bool preferSubArchitecture() { return fHasPreferredSubType; }
127 cpu_subtype_t subArchitecture() { return fSubArchitecture; }
c2646906 128 OutputKind outputKind();
d696c285 129 bool prebind();
c2646906
A
130 bool bindAtLoad();
131 bool fullyLoadArchives();
132 NameSpace nameSpace();
133 const char* installPath(); // only for kDynamicLibrary
134 uint32_t currentVersion(); // only for kDynamicLibrary
135 uint32_t compatibilityVersion(); // only for kDynamicLibrary
136 const char* entryName(); // only for kDynamicExecutable or kStaticExecutable
d696c285 137 const char* executablePath();
c2646906 138 uint64_t baseAddress();
2f2f92e4
A
139 bool keepPrivateExterns(); // only for kObjectFile
140 bool needsModuleTable(); // only for kDynamicLibrary
141 bool interposable(const char* name);
c2646906 142 bool hasExportRestrictList();
2f2f92e4
A
143 bool hasExportMaskList();
144 bool hasWildCardExportRestrictList();
69a49097 145 bool allGlobalsAreDeadStripRoots();
c2646906
A
146 bool shouldExport(const char*);
147 bool ignoreOtherArchInputFiles();
148 bool forceCpuSubtypeAll();
149 bool traceDylibs();
150 bool traceArchives();
d696c285 151 DeadStripMode deadStrip();
c2646906 152 UndefinedTreatment undefinedTreatment();
a61fdf0a 153 ObjectFile::ReaderOptions::VersionMin macosxVersionMin();
c2646906 154 bool messagesPrefixedWithArchitecture();
d696c285 155 Treatment picTreatment();
c2646906
A
156 WeakReferenceMismatchTreatment weakReferenceMismatchTreatment();
157 const char* umbrellaName();
d696c285
A
158 std::vector<const char*>& allowableClients();
159 const char* clientName();
c2646906 160 const char* initFunctionName(); // only for kDynamicLibrary
d696c285 161 const char* dotOutputFile();
c2646906
A
162 uint64_t zeroPageSize();
163 bool hasCustomStack();
164 uint64_t customStackSize();
165 uint64_t customStackAddr();
d696c285 166 bool hasExecutableStack();
c2646906 167 std::vector<const char*>& initialUndefines();
69a49097 168 bool printWhyLive(const char* name);
c2646906 169 uint32_t minimumHeaderPad();
a61fdf0a 170 bool maxMminimumHeaderPad() { return fMaxMinimumHeaderPad; }
c2646906
A
171 std::vector<ExtraSection>& extraSections();
172 std::vector<SectionAlignment>& sectionAlignments();
173 CommonsMode commonsMode();
174 bool warnCommons();
d696c285 175 bool keepRelocations();
6e880c60 176 FileInfo findFile(const char* path);
a61fdf0a 177 UUIDMode getUUIDMode() { return fUUIDMode; }
d696c285
A
178 bool warnStabs();
179 bool pauseAtEnd() { return fPause; }
180 bool printStatistics() { return fStatistics; }
69a49097 181 bool printArchPrefix() { return fMessagesPrefixedWithArchitecture; }
a61fdf0a
A
182 void gotoClassicLinker(int argc, const char* argv[]);
183 bool sharedRegionEligible() { return fSharedRegionEligible; }
184 bool printOrderFileStatistics() { return fPrintOrderFileStatistics; }
185 const char* dTraceScriptName() { return fDtraceScriptName; }
186 bool dTrace() { return (fDtraceScriptName != NULL); }
187 std::vector<OrderedSymbol>& orderedSymbols() { return fOrderedSymbols; }
188 bool splitSeg() { return fSplitSegs; }
189 uint64_t baseWritableAddress() { return fBaseWritableAddress; }
190 std::vector<SegmentStart>& customSegmentAddresses() { return fCustomSegmentAddresses; }
191 std::vector<SegmentProtect>& customSegmentProtections() { return fCustomSegmentProtections; }
192 bool saveTempFiles() { return fSaveTempFiles; }
193 const std::vector<const char*>& rpaths() { return fRPaths; }
194 bool readOnlyx86Stubs() { return fReadOnlyx86Stubs; }
2f2f92e4 195 bool slowx86Stubs() { return fReaderOptions.fSlowx86Stubs; }
a61fdf0a
A
196 std::vector<DylibOverride>& dylibOverrides() { return fDylibOverrides; }
197 const char* generatedMapPath() { return fMapPath; }
198 bool positionIndependentExecutable() { return fPositionIndependentExecutable; }
199 Options::FileInfo findFileUsingPaths(const char* path);
200 bool deadStripDylibs() { return fDeadStripDylibs; }
201 bool allowedUndefined(const char* name) { return ( fAllowedUndefined.find(name) != fAllowedUndefined.end() ); }
202 bool someAllowedUndefines() { return (fAllowedUndefined.size() != 0); }
203 LocalSymbolHandling localSymbolHandling() { return fLocalSymbolHandling; }
204 bool keepLocalSymbol(const char* symbolName);
2f2f92e4
A
205 bool allowTextRelocs() { return fAllowTextRelocs; }
206 bool warnAboutTextRelocs() { return fWarnTextRelocs; }
207 bool usingLazyDylibLinking() { return fUsingLazyDylibLinking; }
208 bool verbose() { return fVerbose; }
209 bool makeEncryptable() { return fEncryptable; }
c2646906
A
210
211private:
212 class CStringEquals
213 {
214 public:
215 bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); }
216 };
217
218 typedef __gnu_cxx::hash_set<const char*, __gnu_cxx::hash<const char*>, CStringEquals> NameSet;
219 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
220 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
2f2f92e4 221 enum InterposeMode { kInterposeNone, kInterposeAllExternal, kInterposeSome };
c2646906 222
a61fdf0a
A
223 class SetWithWildcards {
224 public:
225 void insert(const char*);
226 bool contains(const char*);
2f2f92e4 227 bool hasWildCards() { return !fWildCard.empty(); }
a61fdf0a
A
228 NameSet::iterator regularBegin() { return fRegular.begin(); }
229 NameSet::iterator regularEnd() { return fRegular.end(); }
230 private:
2f2f92e4 231 static bool hasWildCards(const char*);
a61fdf0a
A
232 bool wildCardMatch(const char* pattern, const char* candidate);
233 bool inCharRange(const char*& range, unsigned char c);
234
235 NameSet fRegular;
236 std::vector<const char*> fWildCard;
237 };
238
239
c2646906
A
240 void parse(int argc, const char* argv[]);
241 void checkIllegalOptionCombinations();
242 void buildSearchPaths(int argc, const char* argv[]);
243 void parseArch(const char* architecture);
2f2f92e4 244 FileInfo findLibrary(const char* rootName, bool dylibsOnly=false);
74cfe461
A
245 FileInfo findFramework(const char* frameworkName);
246 FileInfo findFramework(const char* rootName, const char* suffix);
d696c285
A
247 bool checkForFile(const char* format, const char* dir, const char* rootName,
248 FileInfo& result);
c2646906
A
249 uint32_t parseVersionNumber(const char*);
250 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
a61fdf0a 251 void parseOrderFile(const char* path, bool cstring);
c2646906
A
252 void addSection(const char* segment, const char* section, const char* path);
253 void addSubLibrary(const char* name);
254 void loadFileList(const char* fileOfPaths);
255 uint64_t parseAddress(const char* addr);
a61fdf0a
A
256 void loadExportFile(const char* fileOfExports, const char* option, SetWithWildcards& set);
257 void parseAliasFile(const char* fileOfAliases);
c2646906
A
258 void parsePreCommandLineEnvironmentSettings();
259 void parsePostCommandLineEnvironmentSettings();
260 void setUndefinedTreatment(const char* treatment);
2f2f92e4
A
261 void setMacOSXVersionMin(const char* version);
262 void setIPhoneVersionMin(const char* version);
c2646906 263 void setWeakReferenceMismatchTreatment(const char* treatment);
a61fdf0a 264 void addDylibOverride(const char* paths);
c2646906
A
265 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
266 CommonsMode parseCommonsTreatment(const char* mode);
d696c285 267 Treatment parseTreatment(const char* treatment);
69a49097 268 void reconfigureDefaults();
a61fdf0a
A
269 void checkForClassic(int argc, const char* argv[]);
270 void parseSegAddrTable(const char* segAddrPath, const char* installPath);
271 void addLibrary(const FileInfo& info);
272 void warnObsolete(const char* arg);
273 uint32_t parseProtection(const char* prot);
d696c285
A
274
275
c2646906
A
276 ObjectFile::ReaderOptions fReaderOptions;
277 const char* fOutputFile;
278 std::vector<Options::FileInfo> fInputFiles;
279 cpu_type_t fArchitecture;
2f2f92e4 280 cpu_subtype_t fSubArchitecture;
c2646906 281 OutputKind fOutputKind;
2f2f92e4 282 bool fHasPreferredSubType;
d696c285 283 bool fPrebind;
c2646906 284 bool fBindAtLoad;
c2646906 285 bool fKeepPrivateExterns;
a61fdf0a 286 bool fNeedsModuleTable;
c2646906
A
287 bool fIgnoreOtherArchFiles;
288 bool fForceSubtypeAll;
2f2f92e4 289 InterposeMode fInterposeMode;
d696c285 290 DeadStripMode fDeadStrip;
c2646906
A
291 NameSpace fNameSpace;
292 uint32_t fDylibCompatVersion;
293 uint32_t fDylibCurrentVersion;
294 const char* fDylibInstallName;
a61fdf0a 295 const char* fFinalName;
c2646906
A
296 const char* fEntryName;
297 uint64_t fBaseAddress;
a61fdf0a
A
298 uint64_t fBaseWritableAddress;
299 bool fSplitSegs;
300 SetWithWildcards fExportSymbols;
301 SetWithWildcards fDontExportSymbols;
2f2f92e4 302 SetWithWildcards fInterposeList;
c2646906
A
303 ExportMode fExportMode;
304 LibrarySearchMode fLibrarySearchMode;
305 UndefinedTreatment fUndefinedTreatment;
306 bool fMessagesPrefixedWithArchitecture;
c2646906
A
307 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
308 std::vector<const char*> fSubUmbellas;
309 std::vector<const char*> fSubLibraries;
d696c285 310 std::vector<const char*> fAllowableClients;
a61fdf0a 311 std::vector<const char*> fRPaths;
d696c285 312 const char* fClientName;
c2646906
A
313 const char* fUmbrellaName;
314 const char* fInitFunctionName;
d696c285
A
315 const char* fDotOutputFile;
316 const char* fExecutablePath;
69a49097 317 const char* fBundleLoader;
a61fdf0a
A
318 const char* fDtraceScriptName;
319 const char* fSegAddrTablePath;
320 const char* fMapPath;
c2646906
A
321 uint64_t fZeroPageSize;
322 uint64_t fStackSize;
323 uint64_t fStackAddr;
d696c285 324 bool fExecutableStack;
c2646906
A
325 uint32_t fMinimumHeaderPad;
326 CommonsMode fCommonsMode;
a61fdf0a
A
327 UUIDMode fUUIDMode;
328 SetWithWildcards fLocalSymbolsIncluded;
329 SetWithWildcards fLocalSymbolsExcluded;
330 LocalSymbolHandling fLocalSymbolHandling;
c2646906 331 bool fWarnCommons;
6e880c60 332 bool fVerbose;
d696c285 333 bool fKeepRelocations;
d696c285
A
334 bool fWarnStabs;
335 bool fTraceDylibSearching;
336 bool fPause;
337 bool fStatistics;
338 bool fPrintOptions;
a61fdf0a
A
339 bool fSharedRegionEligible;
340 bool fPrintOrderFileStatistics;
341 bool fReadOnlyx86Stubs;
342 bool fPositionIndependentExecutable;
343 bool fMaxMinimumHeaderPad;
344 bool fDeadStripDylibs;
2f2f92e4
A
345 bool fAllowTextRelocs;
346 bool fWarnTextRelocs;
347 bool fUsingLazyDylibLinking;
348 bool fEncryptable;
c2646906 349 std::vector<const char*> fInitialUndefines;
a61fdf0a 350 NameSet fAllowedUndefined;
69a49097 351 NameSet fWhyLive;
c2646906
A
352 std::vector<ExtraSection> fExtraSections;
353 std::vector<SectionAlignment> fSectionAlignments;
a61fdf0a
A
354 std::vector<OrderedSymbol> fOrderedSymbols;
355 std::vector<SegmentStart> fCustomSegmentAddresses;
356 std::vector<SegmentProtect> fCustomSegmentProtections;
357 std::vector<DylibOverride> fDylibOverrides;
d696c285 358
c2646906
A
359 std::vector<const char*> fLibrarySearchPaths;
360 std::vector<const char*> fFrameworkSearchPaths;
6e880c60 361 std::vector<const char*> fSDKPaths;
a61fdf0a 362 bool fSaveTempFiles;
c2646906
A
363};
364
365
366
c2646906 367#endif // __OPTIONS__