]> git.saurik.com Git - apple/ld64.git/blob - src/Options.h
ld64-26.0.80.tar.gz
[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 #ifndef CPU_TYPE_POWERPC64
33 #define CPU_TYPE_POWERPC64 0x1000012
34 #endif
35
36
37 #include <vector>
38 #include <ext/hash_set>
39
40 #include "ObjectFile.h"
41
42 extern __attribute__((noreturn)) void throwf(const char* format, ...);
43
44
45 class DynamicLibraryOptions
46 {
47 public:
48 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fInstallPathOverride(NULL) {}
49
50 bool fWeakImport;
51 bool fReExport;
52 const char* fInstallPathOverride;
53 };
54
55
56 class Options
57 {
58 public:
59 Options(int argc, const char* argv[]);
60 ~Options();
61
62 enum OutputKind { kDynamicExecutable, kStaticExecutable, kDynamicLibrary, kDynamicBundle, kObjectFile, kDyld };
63 enum NameSpace { kTwoLevelNameSpace, kFlatNameSpace, kForceFlatNameSpace };
64 enum UndefinedTreatment { kUndefinedError, kUndefinedWarning, kUndefinedSuppress, kUndefinedDynamicLookup };
65 enum PICTreatment { kPICError, kPICWarning, kPICSuppress };
66 enum WeakReferenceMismatchTreatment { kWeakReferenceMismatchError, kWeakReferenceMismatchWeak, kWeakReferenceMismatchNonWeak };
67 enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
68
69 struct FileInfo {
70 const char* path;
71 uint64_t fileLen;
72 DynamicLibraryOptions options;
73 };
74
75 struct ExtraSection {
76 const char* segmentName;
77 const char* sectionName;
78 const char* path;
79 const uint8_t* data;
80 uint64_t dataLen;
81 };
82
83 struct SectionAlignment {
84 const char* segmentName;
85 const char* sectionName;
86 uint8_t alignment;
87 };
88
89 ObjectFile::ReaderOptions& readerOptions();
90 const char* getOutputFilePath();
91 std::vector<FileInfo>& getInputFiles();
92
93 cpu_type_t architecture();
94 OutputKind outputKind();
95 bool stripLocalSymbols();
96 bool stripDebugInfo();
97 bool bindAtLoad();
98 bool fullyLoadArchives();
99 NameSpace nameSpace();
100 const char* installPath(); // only for kDynamicLibrary
101 uint32_t currentVersion(); // only for kDynamicLibrary
102 uint32_t compatibilityVersion(); // only for kDynamicLibrary
103 const char* entryName(); // only for kDynamicExecutable or kStaticExecutable
104 uint64_t baseAddress();
105 bool keepPrivateExterns(); // only for kObjectFile
106 bool interposable(); // only for kDynamicLibrary
107 bool hasExportRestrictList();
108 bool shouldExport(const char*);
109 bool ignoreOtherArchInputFiles();
110 bool forceCpuSubtypeAll();
111 bool traceDylibs();
112 bool traceArchives();
113 UndefinedTreatment undefinedTreatment();
114 bool messagesPrefixedWithArchitecture();
115 PICTreatment picTreatment();
116 WeakReferenceMismatchTreatment weakReferenceMismatchTreatment();
117 const char* umbrellaName();
118 const char* initFunctionName(); // only for kDynamicLibrary
119 uint64_t zeroPageSize();
120 bool hasCustomStack();
121 uint64_t customStackSize();
122 uint64_t customStackAddr();
123 std::vector<const char*>& initialUndefines();
124 uint32_t minimumHeaderPad();
125 std::vector<ExtraSection>& extraSections();
126 std::vector<SectionAlignment>& sectionAlignments();
127 CommonsMode commonsMode();
128 bool warnCommons();
129 FileInfo findFile(const char* path);
130
131 private:
132 class CStringEquals
133 {
134 public:
135 bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); }
136 };
137
138 typedef __gnu_cxx::hash_set<const char*, __gnu_cxx::hash<const char*>, CStringEquals> NameSet;
139 enum ExportMode { kExportDefault, kExportSome, kDontExportSome };
140 enum LibrarySearchMode { kSearchDylibAndArchiveInEachDir, kSearchAllDirsForDylibsThenAllDirsForArchives };
141
142 void parse(int argc, const char* argv[]);
143 void checkIllegalOptionCombinations();
144 void buildSearchPaths(int argc, const char* argv[]);
145 void parseArch(const char* architecture);
146 FileInfo findLibrary(const char* rootName);
147 FileInfo findFramework(const char* rootName);
148 bool checkForFile(const char* format, const char* dir, const char* rootName, FileInfo& result);
149 uint32_t parseVersionNumber(const char*);
150 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
151 void addSection(const char* segment, const char* section, const char* path);
152 void addSubLibrary(const char* name);
153 void loadFileList(const char* fileOfPaths);
154 uint64_t parseAddress(const char* addr);
155 void loadExportFile(const char* fileOfExports, const char* option, NameSet& set);
156 void parsePreCommandLineEnvironmentSettings();
157 void parsePostCommandLineEnvironmentSettings();
158 void setUndefinedTreatment(const char* treatment);
159 void setPICTreatment(const char* treatment);
160 void setReadOnlyRelocTreatment(const char* treatment);
161 void setWeakReferenceMismatchTreatment(const char* treatment);
162 void setDylibInstallNameOverride(const char* paths);
163 void setExecutablePath(const char* path);
164 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
165 CommonsMode parseCommonsTreatment(const char* mode);
166
167
168
169 ObjectFile::ReaderOptions fReaderOptions;
170 const char* fOutputFile;
171 std::vector<Options::FileInfo> fInputFiles;
172 cpu_type_t fArchitecture;
173 OutputKind fOutputKind;
174 bool fBindAtLoad;
175 bool fStripLocalSymbols;
176 bool fKeepPrivateExterns;
177 bool fInterposable;
178 bool fIgnoreOtherArchFiles;
179 bool fForceSubtypeAll;
180 NameSpace fNameSpace;
181 uint32_t fDylibCompatVersion;
182 uint32_t fDylibCurrentVersion;
183 const char* fDylibInstallName;
184 const char* fEntryName;
185 uint64_t fBaseAddress;
186 NameSet fExportSymbols;
187 NameSet fDontExportSymbols;
188 ExportMode fExportMode;
189 LibrarySearchMode fLibrarySearchMode;
190 UndefinedTreatment fUndefinedTreatment;
191 bool fMessagesPrefixedWithArchitecture;
192 PICTreatment fPICTreatment;
193 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
194 std::vector<const char*> fSubUmbellas;
195 std::vector<const char*> fSubLibraries;
196 const char* fUmbrellaName;
197 const char* fInitFunctionName;
198 uint64_t fZeroPageSize;
199 uint64_t fStackSize;
200 uint64_t fStackAddr;
201 uint32_t fMinimumHeaderPad;
202 CommonsMode fCommonsMode;
203 bool fWarnCommons;
204 bool fVerbose;
205 std::vector<const char*> fInitialUndefines;
206 std::vector<ExtraSection> fExtraSections;
207 std::vector<SectionAlignment> fSectionAlignments;
208
209 std::vector<const char*> fLibrarySearchPaths;
210 std::vector<const char*> fFrameworkSearchPaths;
211 std::vector<const char*> fSDKPaths;
212
213 };
214
215
216
217
218 #endif // __OPTIONS__
219
220
221
222
223
224
225
226
227
228
229