]> git.saurik.com Git - apple/ld64.git/blob - src/Options.h
dcedf8e76942b5942e069aa0654f2c0dc1b36147
[apple/ld64.git] / src / Options.h
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2005 Apple Computer, 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 <ext/hash_set>
34
35 #include "ObjectFile.h"
36
37 void throwf (const char* format, ...) __attribute__ ((noreturn));
38
39 class DynamicLibraryOptions
40 {
41 public:
42 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false), fInstallPathOverride(NULL) {}
43
44 bool fWeakImport;
45 bool fReExport;
46 bool fBundleLoader;
47 const char* fInstallPathOverride;
48 };
49
50 //
51 // The public interface to the Options class is the abstract representation of what work the linker
52 // should do.
53 //
54 // This abstraction layer will make it easier to support a future where the linker is a shared library
55 // invoked directly from Xcode. The target settings in Xcode would be used to directly construct an Options
56 // object (without building a command line which is then parsed).
57 //
58 //
59 class Options
60 {
61 public:
62 Options(int argc, const char* argv[]);
63 ~Options();
64
65 enum OutputKind { kDynamicExecutable, kStaticExecutable, kDynamicLibrary, kDynamicBundle, kObjectFile, kDyld };
66 enum NameSpace { kTwoLevelNameSpace, kFlatNameSpace, kForceFlatNameSpace };
67 // Standard treatment for many options.
68 enum Treatment { kError, kWarning, kSuppress, kNULL, kInvalid };
69 enum UndefinedTreatment { kUndefinedError, kUndefinedWarning, kUndefinedSuppress, kUndefinedDynamicLookup };
70 enum WeakReferenceMismatchTreatment { kWeakReferenceMismatchError, kWeakReferenceMismatchWeak,
71 kWeakReferenceMismatchNonWeak };
72 enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
73 enum DeadStripMode { kDeadStripOff, kDeadStripOn, kDeadStripOnPlusUnusedInits };
74 enum VersionMin { kMinUnset, k10_1, k10_2, k10_3, k10_4, k10_5 };
75
76 struct FileInfo {
77 const char* path;
78 uint64_t fileLen;
79 time_t modTime;
80 DynamicLibraryOptions options;
81 };
82
83 struct ExtraSection {
84 const char* segmentName;
85 const char* sectionName;
86 const char* path;
87 const uint8_t* data;
88 uint64_t dataLen;
89 };
90
91 struct SectionAlignment {
92 const char* segmentName;
93 const char* sectionName;
94 uint8_t alignment;
95 };
96
97 const ObjectFile::ReaderOptions& readerOptions();
98 const char* getOutputFilePath();
99 std::vector<FileInfo>& getInputFiles();
100
101 cpu_type_t architecture();
102 OutputKind outputKind();
103 bool stripLocalSymbols();
104 bool prebind();
105 bool bindAtLoad();
106 bool fullyLoadArchives();
107 NameSpace nameSpace();
108 const char* installPath(); // only for kDynamicLibrary
109 uint32_t currentVersion(); // only for kDynamicLibrary
110 uint32_t compatibilityVersion(); // only for kDynamicLibrary
111 const char* entryName(); // only for kDynamicExecutable or kStaticExecutable
112 const char* executablePath();
113 uint64_t baseAddress();
114 bool keepPrivateExterns(); // only for kObjectFile
115 bool interposable(); // only for kDynamicLibrary
116 bool hasExportRestrictList();
117 bool allGlobalsAreDeadStripRoots();
118 bool shouldExport(const char*);
119 bool ignoreOtherArchInputFiles();
120 bool forceCpuSubtypeAll();
121 bool traceDylibs();
122 bool traceArchives();
123 DeadStripMode deadStrip();
124 UndefinedTreatment undefinedTreatment();
125 VersionMin macosxVersionMin();
126 bool messagesPrefixedWithArchitecture();
127 Treatment picTreatment();
128 WeakReferenceMismatchTreatment weakReferenceMismatchTreatment();
129 Treatment multipleDefinitionsInDylibs();
130 Treatment overridingDefinitionInDependentDylib();
131 bool warnOnMultipleDefinitionsInObjectFiles();
132 const char* umbrellaName();
133 std::vector<const char*>& allowableClients();
134 const char* clientName();
135 const char* initFunctionName(); // only for kDynamicLibrary
136 const char* dotOutputFile();
137 uint64_t zeroPageSize();
138 bool hasCustomStack();
139 uint64_t customStackSize();
140 uint64_t customStackAddr();
141 bool hasExecutableStack();
142 std::vector<const char*>& initialUndefines();
143 bool printWhyLive(const char* name);
144 uint32_t minimumHeaderPad();
145 std::vector<ExtraSection>& extraSections();
146 std::vector<SectionAlignment>& sectionAlignments();
147 CommonsMode commonsMode();
148 bool warnCommons();
149 bool keepRelocations();
150 std::vector<const char*>& traceSymbols();
151 FileInfo findFile(const char* path);
152 bool emitUUID();
153 bool warnStabs();
154 bool pauseAtEnd() { return fPause; }
155 bool printStatistics() { return fStatistics; }
156 bool printArchPrefix() { return fMessagesPrefixedWithArchitecture; }
157 bool makeTentativeDefinitionsReal() { return fMakeTentativeDefinitionsReal; }
158
159 private:
160 class CStringEquals
161 {
162 public:
163 bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); }
164 };
165
166 typedef __gnu_cxx::hash_set<const char*, __gnu_cxx::hash<const char*>, CStringEquals> NameSet;
167 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
168 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
169
170 void parse(int argc, const char* argv[]);
171 void checkIllegalOptionCombinations();
172 void buildSearchPaths(int argc, const char* argv[]);
173 void parseArch(const char* architecture);
174 FileInfo findLibrary(const char* rootName);
175 FileInfo findFramework(const char* rootName);
176 bool checkForFile(const char* format, const char* dir, const char* rootName,
177 FileInfo& result);
178 uint32_t parseVersionNumber(const char*);
179 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
180 void addSection(const char* segment, const char* section, const char* path);
181 void addSubLibrary(const char* name);
182 void loadFileList(const char* fileOfPaths);
183 uint64_t parseAddress(const char* addr);
184 void loadExportFile(const char* fileOfExports, const char* option, NameSet& set);
185 void parsePreCommandLineEnvironmentSettings();
186 void parsePostCommandLineEnvironmentSettings();
187 void setUndefinedTreatment(const char* treatment);
188 void setVersionMin(const char* version);
189 void setWeakReferenceMismatchTreatment(const char* treatment);
190 void setDylibInstallNameOverride(const char* paths);
191 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
192 CommonsMode parseCommonsTreatment(const char* mode);
193 Treatment parseTreatment(const char* treatment);
194 void reconfigureDefaults();
195
196
197
198 ObjectFile::ReaderOptions fReaderOptions;
199 const char* fOutputFile;
200 std::vector<Options::FileInfo> fInputFiles;
201 cpu_type_t fArchitecture;
202 OutputKind fOutputKind;
203 bool fPrebind;
204 bool fBindAtLoad;
205 bool fStripLocalSymbols;
206 bool fKeepPrivateExterns;
207 bool fInterposable;
208 bool fIgnoreOtherArchFiles;
209 bool fForceSubtypeAll;
210 DeadStripMode fDeadStrip;
211 VersionMin fVersionMin;
212 NameSpace fNameSpace;
213 uint32_t fDylibCompatVersion;
214 uint32_t fDylibCurrentVersion;
215 const char* fDylibInstallName;
216 const char* fEntryName;
217 uint64_t fBaseAddress;
218 NameSet fExportSymbols;
219 NameSet fDontExportSymbols;
220 ExportMode fExportMode;
221 LibrarySearchMode fLibrarySearchMode;
222 UndefinedTreatment fUndefinedTreatment;
223 bool fMessagesPrefixedWithArchitecture;
224 Treatment fPICTreatment;
225 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
226 Treatment fMultiplyDefinedDynamic;
227 Treatment fMultiplyDefinedUnused;
228 bool fWarnOnMultiplyDefined;
229 std::vector<const char*> fSubUmbellas;
230 std::vector<const char*> fSubLibraries;
231 std::vector<const char*> fAllowableClients;
232 const char* fClientName;
233 const char* fUmbrellaName;
234 const char* fInitFunctionName;
235 const char* fDotOutputFile;
236 const char* fExecutablePath;
237 const char* fBundleLoader;
238 uint64_t fZeroPageSize;
239 uint64_t fStackSize;
240 uint64_t fStackAddr;
241 bool fExecutableStack;
242 uint32_t fMinimumHeaderPad;
243 CommonsMode fCommonsMode;
244 bool fWarnCommons;
245 bool fVerbose;
246 bool fKeepRelocations;
247 bool fEmitUUID;
248 bool fWarnStabs;
249 bool fTraceDylibSearching;
250 bool fPause;
251 bool fStatistics;
252 bool fPrintOptions;
253 bool fMakeTentativeDefinitionsReal;
254 std::vector<const char*> fInitialUndefines;
255 NameSet fWhyLive;
256 std::vector<const char*> fTraceSymbols;
257 unsigned long fLimitUndefinedSymbols;
258 std::vector<ExtraSection> fExtraSections;
259 std::vector<SectionAlignment> fSectionAlignments;
260
261 std::vector<const char*> fLibrarySearchPaths;
262 std::vector<const char*> fFrameworkSearchPaths;
263 std::vector<const char*> fSDKPaths;
264 bool fAllowStackExecute;
265
266 };
267
268
269
270
271 #endif // __OPTIONS__