@@ -227,31 +227,19 @@ static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
227
227
228
228
DylibFile *macho::loadDylib (MemoryBufferRef mbref, DylibFile *umbrella,
229
229
bool isBundleLoader, bool explicitlyLinked) {
230
- CachedHashStringRef path (mbref.getBufferIdentifier ());
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 ());
231
236
DylibFile *&file = loadedDylibs[path];
232
237
if (file) {
233
238
if (explicitlyLinked)
234
239
file->setExplicitlyLinked ();
235
240
return file;
236
241
}
237
242
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
-
255
243
DylibFile *newFile;
256
244
file_magic magic = identify_magic (mbref.getBuffer ());
257
245
if (magic == file_magic::tapi_file) {
@@ -263,7 +251,6 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
263
251
}
264
252
file =
265
253
make<DylibFile>(**result, umbrella, isBundleLoader, explicitlyLinked);
266
- realfile = file;
267
254
268
255
// parseReexports() can recursively call loadDylib(). That's fine since
269
256
// we wrote the DylibFile we just loaded to the loadDylib cache via the
@@ -279,7 +266,6 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
279
266
magic == file_magic::macho_executable ||
280
267
magic == file_magic::macho_bundle);
281
268
file = make<DylibFile>(mbref, umbrella, isBundleLoader, explicitlyLinked);
282
- realfile = file;
283
269
284
270
// parseLoadCommands() can also recursively call loadDylib(). See comment
285
271
// in previous block for why this means we must copy `file` here.
0 commit comments