rust-lang / libc

Raw bindings to platform APIs for Rust
https://docs.rs/libc
Apache License 2.0
2.06k stars 1.03k forks source link

`dl_iterate_phdr()` and ELF friends only defined on Linux and Fuchsia. #1066

Open vext01 opened 6 years ago

vext01 commented 6 years ago

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

alexcrichton commented 6 years ago

Feel free to send PRs for other platforms!

maxbla commented 3 years ago

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

waddlesplash commented 1 year ago

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.)