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

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

Closed
DavidR91 opened this issue Aug 14, 2021 · 2 comments
Closed
Labels
C-bug Category: bug

Comments

@DavidR91
Copy link

DavidR91 commented Aug 14, 2021

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

@JohnTitor
Copy link
Member

Thanks for filing it! But I'm going to close as wontfix, see #2346 (comment).

@qwandor
Copy link
Contributor

qwandor commented Apr 27, 2022

Could it at least derive Default?

jalaziz added a commit to jalaziz/agave that referenced this issue Nov 29, 2024
msghdr cannot be directly instantiated on musl due to private padding
fields (see rust-lang/libc#2344). The recommended solution is to use
`mem::zeroed` to initialize the struct then set the fields as needed.

While we could use the same solution for both glibc and musl, we use a
conditional compilation directive to avoid using unsafe code when it's
not required.
joncinque pushed a commit to anza-xyz/agave that referenced this issue Dec 3, 2024
* [streamer] Fix musl build

msghdr cannot be directly instantiated on musl due to private padding
fields (see rust-lang/libc#2344). The recommended solution is to use
`mem::zeroed` to initialize the struct then set the fields as needed.

While we could use the same solution for both glibc and musl, we use a
conditional compilation directive to avoid using unsafe code when it's
not required.

* fix lint warnings
Ma233 pushed a commit to dephy-io/agave that referenced this issue Jan 25, 2025
* [streamer] Fix musl build

msghdr cannot be directly instantiated on musl due to private padding
fields (see rust-lang/libc#2344). The recommended solution is to use
`mem::zeroed` to initialize the struct then set the fields as needed.

While we could use the same solution for both glibc and musl, we use a
conditional compilation directive to avoid using unsafe code when it's
not required.

* fix lint warnings
Ma233 pushed a commit to dephy-io/agave that referenced this issue Jan 25, 2025
* [streamer] Fix musl build

msghdr cannot be directly instantiated on musl due to private padding
fields (see rust-lang/libc#2344). The recommended solution is to use
`mem::zeroed` to initialize the struct then set the fields as needed.

While we could use the same solution for both glibc and musl, we use a
conditional compilation directive to avoid using unsafe code when it's
not required.

* fix lint warnings
jasl pushed a commit to jasl/agave that referenced this issue Jan 26, 2025
* [streamer] Fix musl build

msghdr cannot be directly instantiated on musl due to private padding
fields (see rust-lang/libc#2344). The recommended solution is to use
`mem::zeroed` to initialize the struct then set the fields as needed.

While we could use the same solution for both glibc and musl, we use a
conditional compilation directive to avoid using unsafe code when it's
not required.

* fix lint warnings
mergify bot pushed a commit to anza-xyz/agave that referenced this issue Jan 27, 2025
* [streamer] Fix musl build

msghdr cannot be directly instantiated on musl due to private padding
fields (see rust-lang/libc#2344). The recommended solution is to use
`mem::zeroed` to initialize the struct then set the fields as needed.

While we could use the same solution for both glibc and musl, we use a
conditional compilation directive to avoid using unsafe code when it's
not required.

* fix lint warnings

(cherry picked from commit 8c1d4f6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants