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>
32 #ifndef CPU_TYPE_POWERPC64
33 #define CPU_TYPE_POWERPC64 0x1000012
38 #include <ext/hash_set>
40 #include "ObjectFile.h"
42 extern __attribute__((noreturn
)) void throwf(const char* format
, ...);
45 class DynamicLibraryOptions
48 DynamicLibraryOptions() : fWeakImport(false), fReExport(false), fInstallPathOverride(NULL
) {}
52 const char* fInstallPathOverride
;
59 Options(int argc
, const char* argv
[]);
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
};
72 DynamicLibraryOptions options
;
76 const char* segmentName
;
77 const char* sectionName
;
83 struct SectionAlignment
{
84 const char* segmentName
;
85 const char* sectionName
;
89 ObjectFile::ReaderOptions
& readerOptions();
90 const char* getOutputFilePath();
91 std::vector
<FileInfo
>& getInputFiles();
93 cpu_type_t
architecture();
94 OutputKind
outputKind();
95 bool stripLocalSymbols();
96 bool stripDebugInfo();
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();
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();
129 FileInfo
findFile(const char* path
);
135 bool operator()(const char* left
, const char* right
) const { return (strcmp(left
, right
) == 0); }
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
};
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
);
169 ObjectFile::ReaderOptions fReaderOptions
;
170 const char* fOutputFile
;
171 std::vector
<Options::FileInfo
> fInputFiles
;
172 cpu_type_t fArchitecture
;
173 OutputKind fOutputKind
;
175 bool fStripLocalSymbols
;
176 bool fKeepPrivateExterns
;
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
;
201 uint32_t fMinimumHeaderPad
;
202 CommonsMode fCommonsMode
;
205 std::vector
<const char*> fInitialUndefines
;
206 std::vector
<ExtraSection
> fExtraSections
;
207 std::vector
<SectionAlignment
> fSectionAlignments
;
209 std::vector
<const char*> fLibrarySearchPaths
;
210 std::vector
<const char*> fFrameworkSearchPaths
;
211 std::vector
<const char*> fSDKPaths
;
218 #endif // __OPTIONS__