libc
libc copied to clipboard
`dl_iterate_phdr()` and ELF friends only defined on Linux and Fuchsia.
Hi,
I'm writing a library around the dl_iterate_phdr API, and want it to be portable.
I've noticed that dl_iterate_phdr, its types, and constants, are defined only on Linux and Fuchsia for now:
$ ag PT_NULL
src/fuchsia/mod.rs
2431:pub const PT_NULL: u32 = 0;
src/unix/notbsd/linux/mod.rs
1225:pub const PT_NULL: u32 = 0;
$ ag dl_iterate_phdr
src/fuchsia/mod.rs
3976: pub fn dl_iterate_phdr(
src/unix/notbsd/linux/mod.rs
2045: pub fn dl_iterate_phdr(
$ ag Elf64_Half
src/fuchsia/mod.rs
50:pub type Elf64_Half = u16;
930: pub dlpi_phnum: Elf64_Half,
src/unix/notbsd/linux/mod.rs
31:pub type Elf64_Half = u16;
472: pub dlpi_phnum: Elf64_Half,
AFAIK, all of this stuff if present on the BSDs. The ELF stuff is a standard ABI (although different for 32/64-bit arches) that could be shared across all platforms, but some of the types for dl_iterate_phdr differ per-platform. For example, on OpenBSD dl_phdr_info contains more fields than on Linux.
For now users can work around this by using bindgen, but in the long run I think it would be best for libc to implement these interfaces across all platforms.
Thanks
Feel free to send PRs for other platforms!
It seems like #1953 added dl_iterate_phdir to all the BSDs. Haiku doesn't have it despite using ELF and neither does illumos. newlib still needs it
- [x] Freebsd
- [x] openbsd
- [x] netbsd
- [x] dragonflybsd
- [ ] newlib
Haiku now has dl_iterate_phdr, but you must link against -lbsd for it. (It also does not have all the struct members that the BSDs do.)