rust: teach the stdlib about our ld.so trickery

We deliver cross-platform cross-compilers in a trimmed-down chroot-like
environment that doesn't need to ever be `chroot`ed into. chromite's
`lddtree.py` sets this up, but the gist is that all binaries inside of
this chroot are executed like `${chroot}/lib/ld-linux-blah.so --args
"${actual_executable}" "$@"`.

This invocation strategy makes `/proc/self/exe` point to
`ld-linux-blah.so` instead of the ELF executable we're "actually"
invoking.

`lddtree.py` generates scripts which already set a special env var to
point to the "original" `argv[0]`, but that's a path relative to the
directory in which the current program was _initially_ invoked, so
that's not very useful as a general approach.

The intent of this change is to detect if the current binary is being
executed using this ld.so trickery. If it is, we should have an env
var(*) that tells us where the 'original' binary is, relative to ld.so,
so we consult that to find the original binary.

(*) -- once the corresponding change for that lands:
https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2424046

BUG=chromium:1003841, chromium:1114301
TEST=Ran `rustc` in this environment; sysroot was properly detected

Change-Id: I6f6c01f08ad99064614dc0219a0eed2e4f481042
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/2453076
Reviewed-by: LaMont Jones <lamontjones@chromium.org>
Commit-Queue: Mike Nichols <mikenichols@chromium.org>
Tested-by: Mike Nichols <mikenichols@chromium.org>
2 files changed