rust-lang/rust — pull request #16208 by apoelstra (2014-08-03 01:43:06+00:00)
Title: Add explicit padding to network structures; add `repr_c_implicit_padding` lint to help

The recent pull request
https://github.com/rust-lang/rust/issues/15763
changes the structure return value semantics to use a LLVM Load instruction. This instruction does not copy padding fields when copying structs, which interacts badly with BSD socket code -- which makes a habit of casting pointers to different structures amongst each other, inadvertently storing important data in struct padding. The result is that Tcp connections cannot be made after the referenced PR.

This is not a problem for C code, which generally uses `memcpy` and raw pointers to copy structures around. For Rust, which typically copies structures by value, it is a problem. The solution is to make sure that any part of a structure containing data is an explicit field. We accomplish this by adding a lint, `repr_c_implicit_padding`, and enabling it for `libc`, which emits a warning whenever a structure contains padding. This lets us detect implicit padding and replace it with an explicit field, which will be copied on load/store.

This PR will allow PR 15763 to pass the testsuite.

There should be no user-visible changes by this PR, except the new lint that is available. It is off by default.