Skip to content

Commit c0dd69e

Browse files
committed
[lld] resolve dylib paths before caching
When loading frameworks it is possible to have load commands for the same framework through symlinks and the real path. To avoid loading these multiple times find the real path before checking the dylib cache.
1 parent 258e143 commit c0dd69e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lld/MachO/DriverUtils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Support/Path.h"
2727
#include "llvm/TextAPI/InterfaceFile.h"
2828
#include "llvm/TextAPI/TextAPIReader.h"
29+
#include <system_error>
2930

3031
using namespace llvm;
3132
using namespace llvm::MachO;
@@ -229,7 +230,13 @@ static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
229230

230231
DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
231232
bool isBundleLoader, bool explicitlyLinked) {
232-
CachedHashStringRef path(mbref.getBufferIdentifier());
233+
// Frameworks can be found from different symlink paths, so resolve
234+
// symlinks before looking up in the dylib cache.
235+
SmallString<128> realPath;
236+
std::error_code err = fs::real_path(mbref.getBufferIdentifier(), realPath);
237+
CachedHashStringRef path(err.value() == 0
238+
? uniqueSaver().save(StringRef(realPath))
239+
: mbref.getBufferIdentifier());
233240
DylibFile *&file = loadedDylibs[path];
234241
if (file) {
235242
if (explicitlyLinked)

0 commit comments

Comments
 (0)