]> git.saurik.com Git - apple/dyld.git/blob - dyld3/shared-cache/Manifest.h
dyld-519.2.2.tar.gz
[apple/dyld.git] / dyld3 / shared-cache / Manifest.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 #ifndef Manifest_h
26 #define Manifest_h
27
28 #include <map>
29 #include <set>
30 #include <memory>
31 #include <string>
32 #include <vector>
33
34 #include <unordered_map>
35 #include <unordered_set>
36
37 #include <assert.h>
38 #include <uuid/uuid.h>
39
40 #import <Foundation/Foundation.h>
41
42 #include "MachOParser.h"
43 #include "DyldSharedCache.h"
44 #include "Diagnostics.h"
45
46 extern std::string toolDir();
47
48 namespace dyld3 {
49
50 struct BuildQueueEntry {
51 DyldSharedCache::CreateOptions options;
52 std::vector<DyldSharedCache::MappedMachO> dylibsForCache;
53 std::vector<DyldSharedCache::MappedMachO> otherDylibsAndBundles;
54 std::vector<DyldSharedCache::MappedMachO> mainExecutables;
55 std::string outputPath;
56 std::set<std::string> configNames;
57 };
58
59 struct Manifest {
60 struct UUIDInfo {
61 const mach_header* mh;
62 uint64_t sliceFileOffset;
63 std::size_t size;
64 std::string runtimePath;
65 std::string buildPath;
66 std::string installName;
67 std::string arch;
68 UUID uuid;
69 UUIDInfo(const mach_header* M, std::size_t S, uint64_t SO, UUID U, std::string A, std::string RP, std::string BP, std::string IN)
70 : mh(M), size(S), arch(A), uuid(U), runtimePath(RP), buildPath(BP), installName(IN), sliceFileOffset(SO) {}
71 UUIDInfo() : UUIDInfo(nullptr, 0, 0, UUID(), "", "", "", "") {}
72 };
73
74 struct Project {
75 std::vector<std::string> sources;
76 };
77
78 struct File {
79 MachOParser* parser;
80 File(MachOParser* P)
81 : parser(P)
82 {
83 }
84 };
85
86 struct SegmentInfo {
87 std::string name;
88 uint64_t startAddr;
89 uint64_t endAddr;
90 };
91
92 struct CacheInfo {
93 std::vector<SegmentInfo> regions;
94 std::string cdHash;
95 };
96
97 struct CacheImageInfo {
98 bool included;
99 std::string exclusionInfo;
100 UUID uuid;
101 std::string installname;
102 std::vector<SegmentInfo> segments;
103 CacheImageInfo(void)
104 : included(true)
105 {
106 }
107 };
108
109 struct Results {
110 std::string failure;
111 std::map<UUID, CacheImageInfo> dylibs;
112 std::map<UUID, CacheImageInfo> bundles;
113 std::map<UUID, CacheImageInfo> executables;
114
115 std::set<std::string> warnings;
116 CacheInfo developmentCache;
117 CacheInfo productionCache;
118 CacheImageInfo& dylibForInstallname(const std::string& installname);
119 void exclude(MachOParser* parser, const std::string& reason);
120 void exclude(Manifest& manifest, const UUID& uuid, const std::string& reason);
121 };
122
123 struct Architecture {
124 mutable Results results;
125
126 bool operator==(const Architecture& O) const;
127 bool operator!=(const Architecture& other) const;
128 };
129
130 struct Configuration {
131 std::string platformName;
132 std::string device;
133 std::string disposition;
134 std::string metabomTag;
135 std::set<std::string> metabomTags;
136 std::set<std::string> metabomExcludeTags;
137 std::set<std::string> metabomRestrictTags;
138 std::set<std::string> restrictedInstallnames;
139 std::map<std::string, Architecture> architectures;
140
141 bool operator==(const Configuration& O) const;
142 bool operator!=(const Configuration& other) const;
143 const Architecture& architecture(const std::string& architecture) const;
144 void forEachArchitecture(std::function<void(const std::string& archName)> lambda) const;
145 };
146
147 const std::map<std::string, Project>& projects();
148 const Configuration& configuration(const std::string& configuration) const;
149 void forEachConfiguration(std::function<void(const std::string& configName)> lambda) const;
150
151 void addProjectSource(const std::string& project, const std::string& source, bool first = false);
152
153 const std::string projectPath(const std::string& projectName);
154 const bool empty(void);
155 const std::string dylibOrderFile() const;
156 void setDylibOrderFile(const std::string& dylibOrderFile);
157
158 const std::string dirtyDataOrderFile() const;
159 void setDirtyDataOrderFile(const std::string& dirtyDataOrderFile);
160
161 const std::string metabomFile() const;
162 void setMetabomFile(const std::string& metabomFile);
163
164 const Platform platform() const;
165 void setPlatform(const Platform platform);
166
167 const std::string& build() const;
168 void setBuild(const std::string& build);
169 const uint32_t version() const;
170 void setVersion(const uint32_t manifestVersion);
171 bool normalized;
172
173 Manifest(Diagnostics& D, const std::string& path);
174 Manifest(Diagnostics& D, const std::string& path, const std::set<std::string>& overlays);
175
176 BuildQueueEntry makeQueueEntry(const std::string& outputPath, const std::set<std::string>& configs, const std::string& arch, bool optimizeStubs, const std::string& prefix, bool verbose);
177
178 void write(const std::string& path);
179 void writeJSON(const std::string& path);
180 void canonicalize(void);
181 void calculateClosure();
182 MachOParser parserForUUID(const UUID& uuid) const;
183 const std::string buildPathForUUID(const UUID& uuid);
184 const std::string runtimePathForUUID(const UUID& uuid);
185 DyldSharedCache::MappedMachO machoForPathAndArch(const std::string& path, const std::string& arch) const;
186 void remove(const std::string& config, const std::string& arch);
187 const std::string removeLargestLeafDylib(const std::set<std::string>& configurations, const std::string& architecture);
188 void runConcurrently(dispatch_queue_t queue, dispatch_semaphore_t concurrencyLimitingSemaphore, std::function<void(const std::string configuration, const std::string architecture)> lambda);
189 bool filterForConfig(const std::string& configName);
190
191 private:
192 NSDictionary* _manifestDict;
193 Diagnostics& _diags;
194 std::map<UUID, UUIDInfo> _uuidMap;
195 std::map<std::pair<std::string, std::string>, UUID> _installNameMap;
196 static dispatch_queue_t _identifierQueue;
197 uint32_t _manifestVersion;
198 std::string _build;
199 std::string _dylibOrderFile;
200 std::string _dirtyDataOrderFile;
201 std::string _metabomFile;
202 Platform _platform;
203 std::map<std::string, Project> _projects;
204 std::map<std::string, Configuration> _configurations;
205 std::map<std::string, std::set<std::string>> _metabomTagMap;
206 std::map<std::string, std::set<std::string>> _metabomExcludeTagMap;
207 std::map<std::string, std::set<std::string>> _metabomRestrictedTagMap;
208
209 std::vector<DyldSharedCache::MappedMachO> dylibsForCache(const std::string& configuration, const std::string& architecture);
210 std::vector<DyldSharedCache::MappedMachO> otherDylibsAndBundles(const std::string& configuration, const std::string& architecture);
211 std::vector<DyldSharedCache::MappedMachO> mainExecutables(const std::string& configuration, const std::string& architecture);
212
213 const UUIDInfo& infoForUUID(const UUID& uuid) const;
214 const UUIDInfo infoForInstallNameAndarch(const std::string& installName, const std::string arch) const;
215 void insert(std::vector<DyldSharedCache::MappedMachO>& mappedMachOs, const CacheImageInfo& imageInfo);
216 bool loadParser(const void* p, size_t size, uint64_t sliceOffset, const std::string& runtimePath, const std::string& buildPath, const std::set<std::string>& architectures);
217 bool loadParsers(const std::string& pathToMachO, const std::string& runtimePath, const std::set<std::string>& architectures);
218 void removeDylib(MachOParser parser, const std::string& reason, const std::string& configuration, const std::string& architecture,
219 std::unordered_set<UUID>& processedIdentifiers);
220 void dedupeDispositions();
221 void calculateClosure(const std::string& configuration, const std::string& architecture);
222 void canonicalizeDylib(const std::string& installname);
223 template <typename P>
224 void canonicalizeDylib(const std::string& installname, const uint8_t* p);
225 void addImplicitAliases(void);
226 };
227 }
228
229 #endif /* Manifest_h */