]> git.saurik.com Git - apple/ld64.git/blame - src/Options.h
ld64-62.1.tar.gz
[apple/ld64.git] / src / Options.h
CommitLineData
d696c285 1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
6e880c60 2 *
c2646906
A
3 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
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
d696c285 37void throwf (const char* format, ...) __attribute__ ((noreturn));
c2646906 38
d696c285 39class DynamicLibraryOptions
c2646906
A
40{
41public:
69a49097 42 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false), fInstallPathOverride(NULL) {}
d696c285 43
c2646906
A
44 bool fWeakImport;
45 bool fReExport;
69a49097 46 bool fBundleLoader;
c2646906
A
47 const char* fInstallPathOverride;
48};
49
d696c285
A
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//
c2646906
A
59class Options
60{
61public:
d696c285
A
62 Options(int argc, const char* argv[]);
63 ~Options();
c2646906
A
64
65 enum OutputKind { kDynamicExecutable, kStaticExecutable, kDynamicLibrary, kDynamicBundle, kObjectFile, kDyld };
66 enum NameSpace { kTwoLevelNameSpace, kFlatNameSpace, kForceFlatNameSpace };
d696c285
A
67 // Standard treatment for many options.
68 enum Treatment { kError, kWarning, kSuppress, kNULL, kInvalid };
c2646906 69 enum UndefinedTreatment { kUndefinedError, kUndefinedWarning, kUndefinedSuppress, kUndefinedDynamicLookup };
d696c285
A
70 enum WeakReferenceMismatchTreatment { kWeakReferenceMismatchError, kWeakReferenceMismatchWeak,
71 kWeakReferenceMismatchNonWeak };
c2646906 72 enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
d696c285 73 enum DeadStripMode { kDeadStripOff, kDeadStripOn, kDeadStripOnPlusUnusedInits };
69a49097 74 enum VersionMin { kMinUnset, k10_1, k10_2, k10_3, k10_4, k10_5 };
c2646906
A
75
76 struct FileInfo {
77 const char* path;
78 uint64_t fileLen;
d696c285 79 time_t modTime;
c2646906
A
80 DynamicLibraryOptions options;
81 };
d696c285 82
c2646906
A
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 };
d696c285 90
c2646906
A
91 struct SectionAlignment {
92 const char* segmentName;
93 const char* sectionName;
94 uint8_t alignment;
95 };
96
d696c285
A
97 const ObjectFile::ReaderOptions& readerOptions();
98 const char* getOutputFilePath();
99 std::vector<FileInfo>& getInputFiles();
100
c2646906
A
101 cpu_type_t architecture();
102 OutputKind outputKind();
103 bool stripLocalSymbols();
d696c285 104 bool prebind();
c2646906
A
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
d696c285 112 const char* executablePath();
c2646906
A
113 uint64_t baseAddress();
114 bool keepPrivateExterns(); // only for kObjectFile
d696c285 115 bool interposable(); // only for kDynamicLibrary
c2646906 116 bool hasExportRestrictList();
69a49097 117 bool allGlobalsAreDeadStripRoots();
c2646906
A
118 bool shouldExport(const char*);
119 bool ignoreOtherArchInputFiles();
120 bool forceCpuSubtypeAll();
121 bool traceDylibs();
122 bool traceArchives();
d696c285 123 DeadStripMode deadStrip();
c2646906 124 UndefinedTreatment undefinedTreatment();
d696c285 125 VersionMin macosxVersionMin();
c2646906 126 bool messagesPrefixedWithArchitecture();
d696c285 127 Treatment picTreatment();
c2646906 128 WeakReferenceMismatchTreatment weakReferenceMismatchTreatment();
d696c285
A
129 Treatment multipleDefinitionsInDylibs();
130 Treatment overridingDefinitionInDependentDylib();
131 bool warnOnMultipleDefinitionsInObjectFiles();
c2646906 132 const char* umbrellaName();
d696c285
A
133 std::vector<const char*>& allowableClients();
134 const char* clientName();
c2646906 135 const char* initFunctionName(); // only for kDynamicLibrary
d696c285 136 const char* dotOutputFile();
c2646906
A
137 uint64_t zeroPageSize();
138 bool hasCustomStack();
139 uint64_t customStackSize();
140 uint64_t customStackAddr();
d696c285 141 bool hasExecutableStack();
c2646906 142 std::vector<const char*>& initialUndefines();
69a49097 143 bool printWhyLive(const char* name);
c2646906
A
144 uint32_t minimumHeaderPad();
145 std::vector<ExtraSection>& extraSections();
146 std::vector<SectionAlignment>& sectionAlignments();
147 CommonsMode commonsMode();
148 bool warnCommons();
d696c285
A
149 bool keepRelocations();
150 std::vector<const char*>& traceSymbols();
6e880c60 151 FileInfo findFile(const char* path);
d696c285
A
152 bool emitUUID();
153 bool warnStabs();
154 bool pauseAtEnd() { return fPause; }
155 bool printStatistics() { return fStatistics; }
69a49097
A
156 bool printArchPrefix() { return fMessagesPrefixedWithArchitecture; }
157 bool makeTentativeDefinitionsReal() { return fMakeTentativeDefinitionsReal; }
c2646906
A
158
159private:
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);
74cfe461
A
175 FileInfo findFramework(const char* frameworkName);
176 FileInfo findFramework(const char* rootName, const char* suffix);
d696c285
A
177 bool checkForFile(const char* format, const char* dir, const char* rootName,
178 FileInfo& result);
c2646906
A
179 uint32_t parseVersionNumber(const char*);
180 void parseSectionOrderFile(const char* segment, const char* section, const char* path);
181 void addSection(const char* segment, const char* section, const char* path);
182 void addSubLibrary(const char* name);
183 void loadFileList(const char* fileOfPaths);
184 uint64_t parseAddress(const char* addr);
185 void loadExportFile(const char* fileOfExports, const char* option, NameSet& set);
186 void parsePreCommandLineEnvironmentSettings();
187 void parsePostCommandLineEnvironmentSettings();
188 void setUndefinedTreatment(const char* treatment);
d696c285 189 void setVersionMin(const char* version);
c2646906
A
190 void setWeakReferenceMismatchTreatment(const char* treatment);
191 void setDylibInstallNameOverride(const char* paths);
c2646906
A
192 void addSectionAlignment(const char* segment, const char* section, const char* alignment);
193 CommonsMode parseCommonsTreatment(const char* mode);
d696c285 194 Treatment parseTreatment(const char* treatment);
69a49097 195 void reconfigureDefaults();
d696c285
A
196
197
c2646906
A
198 ObjectFile::ReaderOptions fReaderOptions;
199 const char* fOutputFile;
200 std::vector<Options::FileInfo> fInputFiles;
201 cpu_type_t fArchitecture;
202 OutputKind fOutputKind;
d696c285 203 bool fPrebind;
c2646906
A
204 bool fBindAtLoad;
205 bool fStripLocalSymbols;
206 bool fKeepPrivateExterns;
207 bool fInterposable;
208 bool fIgnoreOtherArchFiles;
209 bool fForceSubtypeAll;
d696c285
A
210 DeadStripMode fDeadStrip;
211 VersionMin fVersionMin;
c2646906
A
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;
d696c285 224 Treatment fPICTreatment;
c2646906 225 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment;
d696c285
A
226 Treatment fMultiplyDefinedDynamic;
227 Treatment fMultiplyDefinedUnused;
228 bool fWarnOnMultiplyDefined;
c2646906
A
229 std::vector<const char*> fSubUmbellas;
230 std::vector<const char*> fSubLibraries;
d696c285
A
231 std::vector<const char*> fAllowableClients;
232 const char* fClientName;
c2646906
A
233 const char* fUmbrellaName;
234 const char* fInitFunctionName;
d696c285
A
235 const char* fDotOutputFile;
236 const char* fExecutablePath;
69a49097 237 const char* fBundleLoader;
c2646906
A
238 uint64_t fZeroPageSize;
239 uint64_t fStackSize;
240 uint64_t fStackAddr;
d696c285 241 bool fExecutableStack;
c2646906
A
242 uint32_t fMinimumHeaderPad;
243 CommonsMode fCommonsMode;
244 bool fWarnCommons;
6e880c60 245 bool fVerbose;
d696c285
A
246 bool fKeepRelocations;
247 bool fEmitUUID;
248 bool fWarnStabs;
249 bool fTraceDylibSearching;
250 bool fPause;
251 bool fStatistics;
252 bool fPrintOptions;
69a49097 253 bool fMakeTentativeDefinitionsReal;
c2646906 254 std::vector<const char*> fInitialUndefines;
69a49097 255 NameSet fWhyLive;
d696c285
A
256 std::vector<const char*> fTraceSymbols;
257 unsigned long fLimitUndefinedSymbols;
c2646906
A
258 std::vector<ExtraSection> fExtraSections;
259 std::vector<SectionAlignment> fSectionAlignments;
d696c285 260
c2646906
A
261 std::vector<const char*> fLibrarySearchPaths;
262 std::vector<const char*> fFrameworkSearchPaths;
6e880c60 263 std::vector<const char*> fSDKPaths;
d696c285 264 bool fAllowStackExecute;
c2646906
A
265
266};
267
268
269
270
271#endif // __OPTIONS__