2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
29 #include <mach/machine.h>
31 #ifndef CPU_TYPE_POWERPC64
32 #define CPU_TYPE_POWERPC64 0x1000012
37 #include <ext/hash_set>
39 #include "ObjectFile.h"
41 extern __attribute__((noreturn
)) void throwf(const char* format
, ...);
44 class DynamicLibraryOptions
47 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fInstallPathOverride(NULL
) {}
51 const char* fInstallPathOverride
;
58 Options(int argc
, const char* argv
[]);
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
};
71 DynamicLibraryOptions options
;
75 const char* segmentName
;
76 const char* sectionName
;
82 struct SectionAlignment
{
83 const char* segmentName
;
84 const char* sectionName
;
88 ObjectFile::ReaderOptions
& readerOptions();
89 const char* getOutputFilePath();
90 std::vector
<FileInfo
>& getInputFiles();
92 cpu_type_t
architecture();
93 OutputKind
outputKind();
94 bool stripLocalSymbols();
95 bool stripDebugInfo();
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();
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();
133 bool operator()(const char* left
, const char* right
) const { return (strcmp(left
, right
) == 0); }
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
};
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
);
168 ObjectFile::ReaderOptions fReaderOptions
;
169 const char* fOutputFile
;
170 std::vector
<Options::FileInfo
> fInputFiles
;
171 cpu_type_t fArchitecture
;
172 OutputKind fOutputKind
;
174 bool fStripLocalSymbols
;
175 bool fKeepPrivateExterns
;
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
;
200 uint32_t fMinimumHeaderPad
;
201 CommonsMode fCommonsMode
;
203 std::vector
<const char*> fInitialUndefines
;
204 std::vector
<ExtraSection
> fExtraSections
;
205 std::vector
<SectionAlignment
> fSectionAlignments
;
207 std::vector
<const char*> fLibrarySearchPaths
;
208 std::vector
<const char*> fFrameworkSearchPaths
;
215 #endif // __OPTIONS__