This is an archive of the discontinued LLVM Phabricator instance.

[Support] Fix getMainExecutable on FreeBSD when called via an absolute path
ClosedPublic

Authored by jrtc27 on May 28 2021, 4:29 PM.

Details

Summary

On FreeBSD, absolute paths are passed unmodified in AT_EXECPATH, but
relative paths are resolved to absolute paths, and any symlinks will be
followed in the process. This means that the resource dir calculation
will be wrong if Clang is invoked as an absolute path to a symlink, and
this currently causes clang/test/Driver/rocm-detect.hip to fail on
FreeBSD. Thus, make sure to call realpath on the result, just like is
done on macOS.

Whilst here, clean up the old fallback auxargs loop to use the actual
type for auxargs rather than using lots of hacky casts that rely on
addresses and pointers being the same (which is not the case on CHERI,
and thus Arm's prototype Morello, although for little-endian systems it
happens to work still as the word-sized integer will be padded to a full
pointer). This also makes the code easier to follow, and removes the
confusing double-increment of p.

Diff Detail

Event Timeline

jrtc27 created this revision.May 28 2021, 4:29 PM
jrtc27 requested review of this revision.May 28 2021, 4:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 28 2021, 4:29 PM

I guess the CHERI argument is a bit silly, because (a) you'll take a bounds fault trying to walk off the end of environ (b) CheriBSD is newer than 1300057 so this will just call elf_aux_info, but it's still nicer to use the right types.

dim accepted this revision.May 29 2021, 12:39 AM

Yes, this looks good to me. Thanks for this fix!

This revision is now accepted and ready to land.May 29 2021, 12:39 AM
arichardson accepted this revision.May 29 2021, 12:52 AM
This revision was landed with ongoing or failed builds.May 29 2021, 7:01 AM
This revision was automatically updated to reflect the committed changes.