@@ -227,31 +227,19 @@ static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
227227
228228DylibFile *macho::loadDylib (MemoryBufferRef mbref, DylibFile *umbrella,
229229 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 ());
231236 DylibFile *&file = loadedDylibs[path];
232237 if (file) {
233238 if (explicitlyLinked)
234239 file->setExplicitlyLinked ();
235240 return file;
236241 }
237242
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-
255243 DylibFile *newFile;
256244 file_magic magic = identify_magic (mbref.getBuffer ());
257245 if (magic == file_magic::tapi_file) {
@@ -263,7 +251,6 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
263251 }
264252 file =
265253 make<DylibFile>(**result, umbrella, isBundleLoader, explicitlyLinked);
266- realfile = file;
267254
268255 // parseReexports() can recursively call loadDylib(). That's fine since
269256 // we wrote the DylibFile we just loaded to the loadDylib cache via the
@@ -279,7 +266,6 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
279266 magic == file_magic::macho_executable ||
280267 magic == file_magic::macho_bundle);
281268 file = make<DylibFile>(mbref, umbrella, isBundleLoader, explicitlyLinked);
282- realfile = file;
283269
284270 // parseLoadCommands() can also recursively call loadDylib(). See comment
285271 // in previous block for why this means we must copy `file` here.
0 commit comments