Page MenuHomePhabricator

[hurd] Make getMainExecutable get the real binary path

Authored by sthibaul on Oct 23 2018, 12:45 AM.



On GNU/Hurd, llvm-config is returning bogus value, such as:

$ llvm-config-6.0 --includedir

while it should be:
$ llvm-config-6.0 --includedir

This is because getMainExecutable does not get the actual installation path. On GNU/Hurd, /proc/self/exe is indeed a symlink to the path that was used to start the program, and not the eventual binary file. Llvm's getMainExecutable thus needs to run realpath over it to get the actual place where llvm was installed (/usr/lib/llvm-6.0/bin/llvm-config), and not /usr/bin/llvm-config-6.0. This will not change the result on Linux, where /proc/self/exe already points to the eventual file.

Diff Detail


Event Timeline

sthibaul created this revision.Oct 23 2018, 12:45 AM
sthibaul added a comment.EditedOct 23 2018, 12:48 AM

Note: I added the realpath call for all OSes hitting this part of the code, in case the behavior would be the same on some other OSes. We could instead just call realpath(exe_path, NULL); only in the __GNU__ case (i.e. GNU/Hurd) instead if it is preferred.

sthibaul added reviewers: rnk, JDevlieghere.
rnk accepted this revision.Oct 23 2018, 9:11 AM


I think doing this everywhere is fine.

188 ↗(On Diff #170577)

Can you add a comment explaining that Hurd needs this realpath call as you have in the commit message? Otherwise some well-meaning person will try to simplify the code and break Hurd.

This revision is now accepted and ready to land.Oct 23 2018, 9:11 AM

(I can not commit this myself)

sthibaul updated this revision to Diff 170674.Oct 23 2018, 9:18 AM
This revision was automatically updated to reflect the committed changes.