Skip to content

Conversation

@tedscode
Copy link

@tedscode tedscode commented Oct 31, 2025

Hey there!

fixes #2222
Like @strophy pointed out, there's an issue where msghdr can't be created directly on musl systems. The problem is that the musl libc has a couple extra private padding fields in the struct that aren't accessible.

Fix

This PR uses std::mem::zeroed() to initialize msghdr by just setting everything to 0. This way quiche builds fine on musl-based distros.
If we take a look at the msghdr struct, it's basically just raw pointers and numbers. By zeroing everything out (including those hidden padding fields), we are able to satisfy the kernel.

The original code manually set many fields to null pointers and 0. With zeroed() doing this automatically, those manual assignments were commented out. (kept for reference)

Safety

Now, std::mem::zeroed() can be dangerous if used on the wrong types - like anything that can't be null or zero because that creates undefined behavior.

But as mentioned before it's fine here since msghdr is just raw pointers and numeric types, which can all safely be 0.

Performance

Ran some benchmarks with criterion.rs to compare how fast safe vs unsafe initialization of msghdr struct are.
Optimizations stayed enabled since the goal was to test under realistic conditions.

The safe constructor (which doesn't work with musl) was indeed slower, but the difference wasn't as big as mentioned here.
On average the unsafe approach is about 1.5-2% faster than the version without zeroed().
Between having redundant assignments vs just using zeroed(), the performance is virtually identical.

@tedscode tedscode requested a review from a team as a code owner October 31, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alpine musl libc build fails with cannot construct msghdr with struct literal syntax due to private fields

1 participant