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), fInstallPathOverride(NULL
) {}
46 const char* fInstallPathOverride
;
50 // The public interface to the Options class is the abstract representation of what work the linker
53 // This abstraction layer will make it easier to support a future where the linker is a shared library
54 // invoked directly from Xcode. The target settings in Xcode would be used to directly construct an Options
55 // object (without building a command line which is then parsed).
61 Options(int argc
, const char* argv
[]);
64 enum OutputKind
{ kDynamicExecutable
, kStaticExecutable
, kDynamicLibrary
, kDynamicBundle
, kObjectFile
, kDyld
};
65 enum NameSpace
{ kTwoLevelNameSpace
, kFlatNameSpace
, kForceFlatNameSpace
};
66 // Standard treatment for many options.
67 enum Treatment
{ kError
, kWarning
, kSuppress
, kNULL
, kInvalid
};
68 enum UndefinedTreatment
{ kUndefinedError
, kUndefinedWarning
, kUndefinedSuppress
, kUndefinedDynamicLookup
};
69 enum WeakReferenceMismatchTreatment
{ kWeakReferenceMismatchError
, kWeakReferenceMismatchWeak
,
70 kWeakReferenceMismatchNonWeak
};
71 enum CommonsMode
{ kCommonsIgnoreDylibs
, kCommonsOverriddenByDylibs
, kCommonsConflictsDylibsError
};
72 enum DeadStripMode
{ kDeadStripOff
, kDeadStripOn
, kDeadStripOnPlusUnusedInits
};
73 enum VersionMin
{ k10_1
, k10_2
, k10_3
, k10_4
, k10_5
};
79 DynamicLibraryOptions options
;
83 const char* segmentName
;
84 const char* sectionName
;
90 struct SectionAlignment
{
91 const char* segmentName
;
92 const char* sectionName
;
96 const ObjectFile::ReaderOptions
& readerOptions();
97 const char* getOutputFilePath();
98 std::vector
<FileInfo
>& getInputFiles();
100 cpu_type_t
architecture();
101 OutputKind
outputKind();
102 bool stripLocalSymbols();
105 bool fullyLoadArchives();
106 NameSpace
nameSpace();
107 const char* installPath(); // only for kDynamicLibrary
108 uint32_t currentVersion(); // only for kDynamicLibrary
109 uint32_t compatibilityVersion(); // only for kDynamicLibrary
110 const char* entryName(); // only for kDynamicExecutable or kStaticExecutable
111 const char* executablePath();
112 uint64_t baseAddress();
113 bool keepPrivateExterns(); // only for kObjectFile
114 bool interposable(); // only for kDynamicLibrary
115 bool hasExportRestrictList();
116 bool shouldExport(const char*);
117 bool ignoreOtherArchInputFiles();
118 bool forceCpuSubtypeAll();
120 bool traceArchives();
121 DeadStripMode
deadStrip();
122 UndefinedTreatment
undefinedTreatment();
123 VersionMin
macosxVersionMin();
124 bool messagesPrefixedWithArchitecture();
125 Treatment
picTreatment();
126 WeakReferenceMismatchTreatment
weakReferenceMismatchTreatment();
127 Treatment
multipleDefinitionsInDylibs();
128 Treatment
overridingDefinitionInDependentDylib();
129 bool warnOnMultipleDefinitionsInObjectFiles();
130 const char* umbrellaName();
131 std::vector
<const char*>& allowableClients();
132 const char* clientName();
133 const char* initFunctionName(); // only for kDynamicLibrary
134 const char* dotOutputFile();
135 uint64_t zeroPageSize();
136 bool hasCustomStack();
137 uint64_t customStackSize();
138 uint64_t customStackAddr();
139 bool hasExecutableStack();
140 std::vector
<const char*>& initialUndefines();
141 uint32_t minimumHeaderPad();
142 std::vector
<ExtraSection
>& extraSections();
143 std::vector
<SectionAlignment
>& sectionAlignments();
144 CommonsMode
commonsMode();
146 bool keepRelocations();
147 std::vector
<const char*>& traceSymbols();
148 FileInfo
findFile(const char* path
);
151 bool pauseAtEnd() { return fPause
; }
152 bool printStatistics() { return fStatistics
; }
158 bool operator()(const char* left
, const char* right
) const { return (strcmp(left
, right
) == 0); }
161 typedef __gnu_cxx::hash_set
<const char*, __gnu_cxx::hash
<const char*>, CStringEquals
> NameSet
;
162 enum ExportMode
{ kExportDefault
, kExportSome
, kDontExportSome
};
163 enum LibrarySearchMode
{ kSearchDylibAndArchiveInEachDir
, kSearchAllDirsForDylibsThenAllDirsForArchives
};
165 void parse(int argc
, const char* argv
[]);
166 void checkIllegalOptionCombinations();
167 void buildSearchPaths(int argc
, const char* argv
[]);
168 void parseArch(const char* architecture
);
169 FileInfo
findLibrary(const char* rootName
);
170 FileInfo
findFramework(const char* rootName
);
171 bool checkForFile(const char* format
, const char* dir
, const char* rootName
,
173 uint32_t parseVersionNumber(const char*);
174 void parseSectionOrderFile(const char* segment
, const char* section
, const char* path
);
175 void addSection(const char* segment
, const char* section
, const char* path
);
176 void addSubLibrary(const char* name
);
177 void loadFileList(const char* fileOfPaths
);
178 uint64_t parseAddress(const char* addr
);
179 void loadExportFile(const char* fileOfExports
, const char* option
, NameSet
& set
);
180 void parsePreCommandLineEnvironmentSettings();
181 void parsePostCommandLineEnvironmentSettings();
182 void setUndefinedTreatment(const char* treatment
);
183 void setVersionMin(const char* version
);
184 void setWeakReferenceMismatchTreatment(const char* treatment
);
185 void setDylibInstallNameOverride(const char* paths
);
186 void addSectionAlignment(const char* segment
, const char* section
, const char* alignment
);
187 CommonsMode
parseCommonsTreatment(const char* mode
);
188 Treatment
parseTreatment(const char* treatment
);
192 ObjectFile::ReaderOptions fReaderOptions
;
193 const char* fOutputFile
;
194 std::vector
<Options::FileInfo
> fInputFiles
;
195 cpu_type_t fArchitecture
;
196 OutputKind fOutputKind
;
199 bool fStripLocalSymbols
;
200 bool fKeepPrivateExterns
;
202 bool fIgnoreOtherArchFiles
;
203 bool fForceSubtypeAll
;
204 DeadStripMode fDeadStrip
;
205 VersionMin fVersionMin
;
206 NameSpace fNameSpace
;
207 uint32_t fDylibCompatVersion
;
208 uint32_t fDylibCurrentVersion
;
209 const char* fDylibInstallName
;
210 const char* fEntryName
;
211 uint64_t fBaseAddress
;
212 NameSet fExportSymbols
;
213 NameSet fDontExportSymbols
;
214 ExportMode fExportMode
;
215 LibrarySearchMode fLibrarySearchMode
;
216 UndefinedTreatment fUndefinedTreatment
;
217 bool fMessagesPrefixedWithArchitecture
;
218 Treatment fPICTreatment
;
219 WeakReferenceMismatchTreatment fWeakReferenceMismatchTreatment
;
220 Treatment fMultiplyDefinedDynamic
;
221 Treatment fMultiplyDefinedUnused
;
222 bool fWarnOnMultiplyDefined
;
223 std::vector
<const char*> fSubUmbellas
;
224 std::vector
<const char*> fSubLibraries
;
225 std::vector
<const char*> fAllowableClients
;
226 const char* fClientName
;
227 const char* fUmbrellaName
;
228 const char* fInitFunctionName
;
229 const char* fDotOutputFile
;
230 const char* fExecutablePath
;
231 uint64_t fZeroPageSize
;
234 bool fExecutableStack
;
235 uint32_t fMinimumHeaderPad
;
236 CommonsMode fCommonsMode
;
239 bool fKeepRelocations
;
242 bool fTraceDylibSearching
;
246 std::vector
<const char*> fInitialUndefines
;
247 std::vector
<const char*> fTraceSymbols
;
248 unsigned long fLimitUndefinedSymbols
;
249 std::vector
<ExtraSection
> fExtraSections
;
250 std::vector
<SectionAlignment
> fSectionAlignments
;
252 std::vector
<const char*> fLibrarySearchPaths
;
253 std::vector
<const char*> fFrameworkSearchPaths
;
254 std::vector
<const char*> fSDKPaths
;
255 bool fAllowStackExecute
;
262 #endif // __OPTIONS__