Use SONAME to determine interpreter flavor on Linux
Opened this issue · 0 comments
Currently, a std
employs imperfect strategies to differentiate between ld-musl
and ld-linux
interpreters:
- Check the file name for the string
ld-musl
orld-linux
. This strategy is Incorrect when the interpreter file is referred to by ID, we don't have this string. - Execute the interpreter with the
--help
argument and search for the stringmusl
in the resultingstderr
. This is always correct, but incurs a wasteful amount of overhead.
Instead, we can parse the ELF header and search for the SONAME field. In the case of glibc, this field will always be set and include the full ld-linux
name. For musl
, the toolchains we produce will contain ld-musl
interpreters which are just symlinks to libc.so
. This file does not have SONAME set, and therefore cannot be an ld-linux
interpreter. This strategy can be implemented in both std.wrap
and the ld
proxy.
On Fedora, installing musl
via the package manager does produce an actual ELF file with a SONAME containing ld-musl
, instead of a symlink. We could consider producing our musl toolchains in this manner as well, but the bootstrap toolchain we obtain from musl.cc
will still only contain the symlink, so we will need to handle this case as well.