This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Fix trailing slash in oso_prefix
ClosedPublic

Authored by keith on Nov 9 2021, 9:38 PM.

Details

Summary

Previously if you passed -oso_prefix path/to/foo/ with a trailing
slash at the end, using real_path would remove that slash, but that
slash is necessary to make sure OSO prefix paths end up as valid
relative paths instead of starting with /.

Diff Detail

Event Timeline

keith created this revision.Nov 9 2021, 9:38 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
keith requested review of this revision.Nov 9 2021, 9:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2021, 9:38 PM
keith added inline comments.Nov 9 2021, 9:39 PM
lld/MachO/Driver.cpp
1164

Maybe the second half of the conditional here isn't necessary?

oontvoo accepted this revision.Nov 10 2021, 7:12 AM

LG Thanks!

lld/MachO/Driver.cpp
1164

I guess it's not needed if we can count on real_path to NOT change its behaviour.
But the tests below should catch it.

This revision is now accepted and ready to land.Nov 10 2021, 7:12 AM
int3 added inline comments.Nov 10 2021, 8:42 AM
lld/MachO/Driver.cpp
1164

Given that realpath is a POSIX API with very wide use, I think it is extremely unlikely to ever change its behavior...

I guess this means we can remove the check on line 1160 too

keith updated this revision to Diff 386402.Nov 10 2021, 7:10 PM
keith marked 2 inline comments as done.

Remove unnecessary conditions

thevinster accepted this revision.Nov 10 2021, 7:57 PM
thevinster added a subscriber: thevinster.

Nice find!

lld/MachO/Driver.cpp
1160–1163

We can simplify this with a || in the first if? Could we also document the behavior of real_path here (that it removes the trailing slash)?

int3 accepted this revision.Nov 11 2021, 12:20 PM

lgtm

lld/MachO/Driver.cpp
1160–1163

+1

keith updated this revision to Diff 386628.Nov 11 2021, 12:42 PM
keith marked an inline comment as done.

Combine conditions

This revision was automatically updated to reflect the committed changes.