This is an archive of the discontinued LLVM Phabricator instance.

[llvm-rc] Resolve the executable path if not present in Argv[0]
ClosedPublic

Authored by mstorsjo on Aug 6 2023, 2:25 PM.

Details

Summary

The llvm-rc tool tries to locate a suitable Clang executable to
use for preprocessing. For this purpose, it first checks within
the same directory as the llvm-rc tool, checking with a couple
different names, followed by checking all of $PATH for another
couple names.

On Windows, the InitLLVM() function always sets up Argv[0] with the
full path to the executable, while on Unix, Argv[0] is kept as is.

Therefore, call getMainExecutable to try to resolve the directory of
the executable before looking for colocated Clang executables.

This makes 282744a9ce18120dc0a6eceb02693b36980d9498 actually have
the desired effect.

Diff Detail

Event Timeline

mstorsjo created this revision.Aug 6 2023, 2:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2023, 2:25 PM
mstorsjo requested review of this revision.Aug 6 2023, 2:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2023, 2:25 PM
thieta accepted this revision.Aug 7 2023, 12:22 AM

LGTM, I would change P to nullptr, unless there is a good reason to check the symbol there.

llvm/tools/llvm-rc/llvm-rc.cpp
128

You can just pass nullptr to getMainExecutable instead of a symbol, unless there is a good reason here (I don't think so?).

This revision is now accepted and ready to land.Aug 7 2023, 12:22 AM

Thanks for the review!

llvm/tools/llvm-rc/llvm-rc.cpp
128

As far as I know, the address argument can be used for resolving the main executable as a late fallback implementation - see https://github.com/llvm/llvm-project/blob/llvmorg-17.0.0-rc1/llvm/lib/Support/Unix/Path.inc#L323. If we pass nullptr there, the getMainExecutable function won't work in that particular codepath.

This revision was landed with ongoing or failed builds.Aug 8 2023, 1:20 PM
This revision was automatically updated to reflect the committed changes.