1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
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
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.
22 * @APPLE_LICENSE_HEADER_END@
30 #include <mach/machine.h>
33 #include <ext/hash_set>
35 #include "ObjectFile.h"
37 void throwf (const char* format
, ...) __attribute__ ((noreturn
));
39 class DynamicLibraryOptions
42 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fBundleLoader(false), fInstallPathOverride(NULL
) {}
47 const char* fInstallPathOverride
;
51 // The public interface to the Options class is the abstract representation of what work the linker
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).
62 Options(int argc
, const char* argv
[]);
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
};
80 DynamicLibraryOptions options
;
84 const char* segmentName
;
85 const char* sectionName
;
91 struct SectionAlignment
{
92 const char* segmentName
;
93 const char* sectionName
;
97 const ObjectFile::ReaderOptions
& readerOptions();
98 const char* getOutputFilePath();
99 std::vector
<FileInfo
>& getInputFiles();
101 cpu_type_t
architecture();
102 OutputKind
outputKind();
103 bool stripLocalSymbols();
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();
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();
149 bool keepRelocations();
150 std::vector
<const char*>& traceSymbols();
151 FileInfo
findFile(const char* path
);
154 bool pauseAtEnd() { return fPause
; }
155 bool printStatistics() { return fStatistics
; }
156 bool printArchPrefix() { return fMessagesPrefixedWithArchitecture
; }
157 bool makeTentativeDefinitionsReal() { return fMakeTentativeDefinitionsReal
; }
163 bool operator()(const char* left
, const char* right
) const { return (strcmp(left
, right
) == 0); }
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
};
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
,
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();
198 ObjectFile::ReaderOptions fReaderOptions
;
199 const char* fOutputFile
;
200 std::vector
<Options::FileInfo
> fInputFiles
;
201 cpu_type_t fArchitecture
;
202 OutputKind fOutputKind
;
205 bool fStripLocalSymbols
;
206 bool fKeepPrivateExterns
;
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
;
241 bool fExecutableStack
;
242 uint32_t fMinimumHeaderPad
;
243 CommonsMode fCommonsMode
;
246 bool fKeepRelocations
;
249 bool fTraceDylibSearching
;
253 bool fMakeTentativeDefinitionsReal
;
254 std::vector
<const char*> fInitialUndefines
;
256 std::vector
<const char*> fTraceSymbols
;
257 unsigned long fLimitUndefinedSymbols
;
258 std::vector
<ExtraSection
> fExtraSections
;
259 std::vector
<SectionAlignment
> fSectionAlignments
;
261 std::vector
<const char*> fLibrarySearchPaths
;
262 std::vector
<const char*> fFrameworkSearchPaths
;
263 std::vector
<const char*> fSDKPaths
;
264 bool fAllowStackExecute
;
271 #endif // __OPTIONS__