rust-lang / rust-lang/libc

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

Open
#1,066 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-API-request
Dominant language
Rust
Stars
2.6k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
69

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the existing ELF and dl_iterate_phdr definitions in src/fuchsia/mod.rs and src/unix/notbsd/linux/mod.rs with the corresponding BSD platform APIs. Trace the platform modules and account for differences such as OpenBSD's additional dl_phdr_info fields; done means the interfaces are exposed across the applicable BSD targets with platform-correct definitions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.