]> git.saurik.com Git - apple/ld64.git/blob - src/Options.h
ld64-21.tar.gz
[apple/ld64.git] / src / Options.h
1 /*
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef __OPTIONS__
25 #define __OPTIONS__
26
27
28 #include <stdint.h>
29 #include <mach/machine.h>
30
31 #ifndef CPU_TYPE_POWERPC64
32 #define CPU_TYPE_POWERPC64 0x1000012
33 #endif
34
35
36 #include <vector>
37 #include <ext/hash_set>
38
39 #include "ObjectFile.h"
40
41 extern __attribute__((noreturn)) void throwf(const char* format, ...);
42
43
44 class DynamicLibraryOptions
45 {
46 public:
47 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fInstallPathOverride(NULL) {}
48
49 bool fWeakImport;
50 bool fReExport;
51 const char* fInstallPathOverride;
52 };
53
54
55 class Options
56 {
57 public:
58 Options(int argc, const char* argv[]);
59 ~Options();
60
61 enum OutputKind { kDynamicExecutable, kStaticExecutable, kDynamicLibrary, kDynamicBundle, kObjectFile, kDyld };
62 enum NameSpace { kTwoLevelNameSpace, kFlatNameSpace, kForceFlatNameSpace };
63 enum UndefinedTreatment { kUndefinedError, kUndefinedWarning, kUndefinedSuppress, kUndefinedDynamicLookup };
64 enum PICTreatment { kPICError, kPICWarning, kPICSuppress };
65 enum WeakReferenceMismatchTreatment { kWeakReferenceMismatchError, kWeakReferenceMismatchWeak, kWeakReferenceMismatchNonWeak };
66 enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
67
68 struct FileInfo {
69 const char* path;
70 uint64_t fileLen;
71 DynamicLibraryOptions options;
72 };
73
74 struct ExtraSection {
75 const char* segmentName;
76 const char* sectionName;
77 const char* path;
78 const uint8_t* data;
79 uint64_t dataLen;
80 };
81
82 struct SectionAlignment {
83 const char* segmentName;
84 const char* sectionName;
85 uint8_t alignment;
86 };
87
88 ObjectFile::ReaderOptions& readerOptions();
89 const char* getOutputFilePath();
90 std::vector<FileInfo>& getInputFiles();
91
92 cpu_type_t architecture();
93 OutputKind outputKind();
94 bool stripLocalSymbols();
95 bool stripDebugInfo();
96 bool bindAtLoad();
97 bool fullyLoadArchives();
98 NameSpace nameSpace();
99 const char* installPath(); // only for kDynamicLibrary
100 uint32_t currentVersion(); // only for kDynamicLibrary
101 uint32_t compatibilityVersion(); // only for kDynamicLibrary
102 const char* entryName(); // only for kDynamicExecutable or kStaticExecutable
103 uint64_t baseAddress();
104 bool keepPrivateExterns(); // only for kObjectFile
105 bool interposable(); // only for kDynamicLibrary
106 bool hasExportRestrictList();
107 bool shouldExport(const char*);
108 bool ignoreOtherArchInputFiles();
109 bool forceCpuSubtypeAll();
110 bool traceDylibs();
111 bool traceArchives();
112 UndefinedTreatment undefinedTreatment();
113 bool messagesPrefixedWithArchitecture();
114 PICTreatment picTreatment();
115 WeakReferenceMismatchTreatment weakReferenceMismatchTreatment();
116 const char* umbrellaName();
117 const char* initFunctionName(); // only for kDynamicLibrary
118 uint64_t zeroPageSize();
119 bool hasCustomStack();
120 uint64_t customStackSize();
121 uint64_t customStackAddr();
122 std::vector<const char*>& initialUndefines();
123 uint32_t minimumHeaderPad();
124 std::vector<ExtraSection>& extraSections();
125 std::vector<SectionAlignment>& sectionAlignments();
126 CommonsMode commonsMode();
127 bool warnCommons();
128
129 private:
130 class CStringEquals
131 {
132 public:
133 bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); }
134 };
135
136 typedef __gnu_cxx::hash_set<const char*, __gnu_cxx::hash<const char*>, CStringEquals> NameSet;
137 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
138 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
139
140 void parse(int argc, const char* argv[]);
141 void checkIllegalOptionCombinations();
142 void buildSearchPaths(int argc, const char* argv[]);
143 void parseArch(const char* architecture);
144 FileInfo findLibrary(const char* rootName);
145 FileInfo findFramework(const char* rootName);
146 FileInfo makeFileInfo(const char* path);
147 bool checkForFile(const char* format, const char* dir, const char* rootName, FileInfo& result);
148 uint32_t parseVersionNumber(const char*);
149 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
150 void addSection(const char* segment, const char* section, const char* path);
151 void addSubLibrary(const char* name);
152 void loadFileList(const char* fileOfPaths);
153 uint64_t parseAddress(const char* addr);
154 void loadExportFile(const char* fileOfExports, const char* option, NameSet& set);
155 void parsePreCommandLineEnvironmentSettings();
156 void parsePostCommandLineEnvironmentSettings();
157 void setUndefinedTreatment(const char* treatment);
158 void setPICTreatment(const char* treatment);
159 void setReadOnlyRelocTreatment(const char* treatment);
160 void setWeakReferenceMismatchTreatment(const char* treatment);
161 void setDylibInstallNameOverride(const char* paths);
162 void setExecutablePath(const char* path);
163 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
164 CommonsMode parseCommonsTreatment(const char* mode);
165
166
167
168 ObjectFile::ReaderOptions fReaderOptions;
169 const char* fOutputFile;
170 std::vector<Options::FileInfo> fInputFiles;
171 cpu_type_t fArchitecture;
172 OutputKind fOutputKind;
173 bool fBindAtLoad;
174 bool fStripLocalSymbols;
175 bool fKeepPrivateExterns;
176 bool fInterposable;
177 bool fIgnoreOtherArchFiles;
178 bool fForceSubtypeAll;
179 NameSpace fNameSpace;
180 uint32_t fDylibCompatVersion;
181 uint32_t fDylibCurrentVersion;
182 const char* fDylibInstallName;
183 const char* fEntryName;
184 uint64_t fBaseAddress;
185 NameSet fExportSymbols;
186 NameSet fDontExportSymbols;
187 ExportMode fExportMode;
188 LibrarySearchMode fLibrarySearchMode;
189 UndefinedTreatment fUndefinedTreatment;
190 bool fMessagesPrefixedWithArchitecture;
191 PICTreatment fPICTreatment;
192 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
193 std::vector<const char*> fSubUmbellas;
194 std::vector<const char*> fSubLibraries;
195 const char* fUmbrellaName;
196 const char* fInitFunctionName;
197 uint64_t fZeroPageSize;
198 uint64_t fStackSize;
199 uint64_t fStackAddr;
200 uint32_t fMinimumHeaderPad;
201 CommonsMode fCommonsMode;
202 bool fWarnCommons;
203 std::vector<const char*> fInitialUndefines;
204 std::vector<ExtraSection> fExtraSections;
205 std::vector<SectionAlignment> fSectionAlignments;
206
207 std::vector<const char*> fLibrarySearchPaths;
208 std::vector<const char*> fFrameworkSearchPaths;
209
210 };
211
212
213
214
215 #endif // __OPTIONS__
216
217
218
219
220
221
222
223
224
225
226