Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vext01 opened this issue Aug 20, 2018 · 3 comments
Open

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

vext01 opened this issue Aug 20, 2018 · 3 comments
Labels
C-API-request Category: API request
Milestone

Comments

@vext01
Copy link

vext01 commented Aug 20, 2018

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
Copy link
Member

Feel free to send PRs for other platforms!

@gnzlbg gnzlbg added the C-API-request Category: API request label Nov 22, 2018
bors bot added a commit to softdevteam/phdrs that referenced this issue Aug 24, 2020
5: Use the libc and elf crates instead of bindgen. r=ptersilie a=vext01

This make phdrs simpler and more lightweight.

For now this would only work on Linux, but it'd be easy to get working elsewhere with small patches to libc (see [this issue](rust-lang/libc#1066)).

Makes phdrs build so much faster.

Co-authored-by: Edd Barrett <vext01@gmail.com>
bors added a commit that referenced this issue Oct 27, 2020
Add dl_iterate_phdr to some BSD OSs

Add dl_iterate_phdr for freebsd, openbsd and netbsd: #1066
cc rust-lang/backtrace-rs#325
bors added a commit that referenced this issue Oct 27, 2020
Add dl_iterate_phdr to some BSD OSs

Add dl_iterate_phdr for freebsd, openbsd and netbsd: #1066
cc rust-lang/backtrace-rs#325
JohnTitor added a commit to JohnTitor/libc that referenced this issue Oct 27, 2020
Add dl_iterate_phdr to some BSD OSs

Add dl_iterate_phdr for freebsd, openbsd and netbsd: rust-lang#1066
cc rust-lang/backtrace-rs#325
bors added a commit that referenced this issue Oct 27, 2020
Add dl_iterate_phdr to some BSD OSs

Add dl_iterate_phdr for freebsd, openbsd and netbsd: #1066
cc rust-lang/backtrace-rs#325
@maxbla
Copy link
Contributor

maxbla commented Feb 24, 2021

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

  • Freebsd
  • openbsd
  • netbsd
  • dragonflybsd
  • newlib

@waddlesplash
Copy link

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

@tgross35 tgross35 added this to the 1.0 milestone Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-API-request Category: API request
Projects
None yet
Development

No branches or pull requests

6 participants