This is an archive of the discontinued LLVM Phabricator instance.

[lld/mac] When handling @loader_path, use realpath() of symlinks
ClosedPublic

Authored by thakis on Jun 9 2021, 1:13 PM.

Details

Summary

This is important for Frameworks, which are usually symlinks.

ld64 gets this right for @rpath that's replaced with @loader_path, but not for
bare @loader_path -- ld64's code calls realpath() in that case too, but ignores
the result.

ld64 somehow manages to find libbar1.dylib in the test without the
explicit -rpath in Foo1. I don't understand why or how. But this
change is a step forward and fixes an immediate problem I'm having,
so let's start with this :)

Diff Detail

Event Timeline

thakis created this revision.Jun 9 2021, 1:13 PM
Herald added a reviewer: gkm. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
thakis requested review of this revision.Jun 9 2021, 1:13 PM
int3 added inline comments.Jun 9 2021, 4:28 PM
lld/MachO/InputFiles.cpp
794–796

Would it make sense to call realPath before constructing MemoryBuffers in readFile, so that getName() always returns a canonicalized path? Or would that mess up other things?

798

intentional newline?

lld/test/MachO/link-search-at-loader-path-symlink.s
25
thakis updated this revision to Diff 351009.Jun 9 2021, 5:08 PM

comments

thakis added inline comments.Jun 9 2021, 5:23 PM
lld/MachO/InputFiles.cpp
794–796

I think that'd be good. It'd also make us not load libSystem twice when doing -lSystem -lpthreads. I'm a bit scared of changing that though (for no good reason), so I'd like to land the smaller change (and the test) here first if that's ok. I hereby pledge to send you a follow-up that tries moving this call earlier :)

(ld64 has the realpath call in its code corresponding to the code here -- but parts of ld64 are all over the place so that doesn't necessarily mean much.)

798

No, thanks :)

lld/test/MachO/link-search-at-loader-path-symlink.s
25

Maybe I meant "..." :P

int3 accepted this revision.Jun 9 2021, 5:25 PM
int3 added inline comments.
lld/MachO/InputFiles.cpp
794–796

Fair enough :)

This revision is now accepted and ready to land.Jun 9 2021, 5:25 PM
This revision was landed with ongoing or failed builds.Jun 9 2021, 5:36 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2021, 5:36 PM