@@ -227,19 +227,31 @@ static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
227
227
228
228
DylibFile *macho::loadDylib (MemoryBufferRef mbref, DylibFile *umbrella,
229
229
bool isBundleLoader, bool explicitlyLinked) {
230
- // Frameworks can be found from different symlink paths, so resolve
231
- // symlinks before looking up in the dylib cache.
232
- SmallString<128 > realPath;
233
- std::error_code err = fs::real_path (mbref.getBufferIdentifier (), realPath);
234
- CachedHashStringRef path (!err ? uniqueSaver ().save (StringRef (realPath))
235
- : mbref.getBufferIdentifier ());
230
+ CachedHashStringRef path (mbref.getBufferIdentifier ());
236
231
DylibFile *&file = loadedDylibs[path];
237
232
if (file) {
238
233
if (explicitlyLinked)
239
234
file->setExplicitlyLinked ();
240
235
return file;
241
236
}
242
237
238
+ // Frameworks can be found from different symlink paths, so resolve
239
+ // symlinks and look up in the dylib cache.
240
+ DylibFile *&realfile = file;
241
+ SmallString<128 > realPath;
242
+ std::error_code err = fs::real_path (mbref.getBufferIdentifier (), realPath);
243
+ if (!err) {
244
+ CachedHashStringRef resolvedPath (uniqueSaver ().save (StringRef (realPath)));
245
+ realfile = loadedDylibs[resolvedPath];
246
+ if (realfile) {
247
+ if (explicitlyLinked)
248
+ realfile->setExplicitlyLinked ();
249
+
250
+ file = realfile;
251
+ return realfile;
252
+ }
253
+ }
254
+
243
255
DylibFile *newFile;
244
256
file_magic magic = identify_magic (mbref.getBuffer ());
245
257
if (magic == file_magic::tapi_file) {
@@ -251,6 +263,7 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
251
263
}
252
264
file =
253
265
make<DylibFile>(**result, umbrella, isBundleLoader, explicitlyLinked);
266
+ realfile = file;
254
267
255
268
// parseReexports() can recursively call loadDylib(). That's fine since
256
269
// we wrote the DylibFile we just loaded to the loadDylib cache via the
@@ -266,6 +279,7 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
266
279
magic == file_magic::macho_executable ||
267
280
magic == file_magic::macho_bundle);
268
281
file = make<DylibFile>(mbref, umbrella, isBundleLoader, explicitlyLinked);
282
+ realfile = file;
269
283
270
284
// parseLoadCommands() can also recursively call loadDylib(). See comment
271
285
// in previous block for why this means we must copy `file` here.
0 commit comments