Skip to content

msghdr for musl cannot be instantiated because of private padding fields #2344

@DavidR91

Description

@DavidR91

If I attempt to build

 let mut header = libc::msghdr {
            msg_name: std::ptr::null_mut(),
            msg_namelen: 0,
            msg_iov: std::ptr::null_mut(),
            msg_iovlen: 0,
            msg_control: std::ptr::null_mut(),
            msg_controllen: 0,
            msg_flags: 0, 
        };

on a generic linux target this works, but with --target x86_64-unknown-linux-musl I receive:

error: cannot construct `msghdr` with struct literal syntax due to inaccessible fields
  --> init/src/main.rs:27:26
   |
27 |         let mut header = libc::msghdr {
   |                          ^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted

This is because of private padding used in the musl version of these types: https://github.com/rust-lang/libc/blob/master/src/unix/linux_like/linux/musl/b64/mod.rs#L92

It is notable that in the types below the padding is made public, making this particular struct inconsistent.

Can be worked around with mem::zeroed but I think these fields should ideally be made public

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions