libc icon indicating copy to clipboard operation
libc copied to clipboard

Fix the definition of sigevent

Open asomers opened this issue 3 years ago • 64 comments

It was originally defined back before rust could represent C unions. So instead of defining the union field correctly, it simply defined that union's most useful field. Define it correctly now.

Include a backwards-compatibility mechanism: Rename sigevent's old definition and hide it. Implement Deref and DerefMut from sigevent to the old definition, so consumers will still be able to use the old field name.

asomers avatar Jun 01 '22 03:06 asomers

r? @Amanieu

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive avatar Jun 01 '22 03:06 rust-highfive

@Amanieu what can we do about backwards-compat? It should only be a problem for crates that uses the fairly obscure sigev_notify_thread_id field. That includes Nix, which I can fix. Can we use crater in "grep mode" just to find affected crates?

asomers avatar Jun 01 '22 03:06 asomers

Can we use crater in "grep mode" just to find affected crates?

AFAIK no, the cheapest way is cargo check.

JohnTitor avatar Jun 02 '22 03:06 JohnTitor

@Amanieu Semi-related, is there any discussion/progress about libc crate versioning while I wasn't here? I'd like to resolve the root cause of such an issue someday...

JohnTitor avatar Jun 02 '22 03:06 JohnTitor

No, there's not been any discussion on this. We could bring it up at the next libs team meeting, but I'm not really sure what needs to be done here.

Amanieu avatar Jun 02 '22 15:06 Amanieu

Then here's what I suggest:

  • Run Crater in check mode on all of libc's direct dependencies.
  • If Nix is the only affected crate, then we can make the change, and publish a near synchronous patch release of Nix uses the newer libc crate.
  • If there are a lots of crates that would be affected, then we change the PR to create a sigevent2 structure and deprecate the original. At some future date we rename sigevent2 to sigevent and make sigevent2 a deprecated type alias.

Does that sound reasonable? Is craterbot already activated for this repo?

asomers avatar Jun 02 '22 15:06 asomers

Crater is really designed to test builds of the Rust compiler & standard library, not external crates like libc. I'm sure it would be possible to adapt it, but I'm not familiar with crater and wouldn't know where to start.

As an alternative, it's possible to download the source code for all crates published on crates.io: https://twitter.com/m_ou_se/status/1433085053056262144

This would allow grepping for any uses of sigev_notify_thread_id to see if any crates other than nix would break from this change.

Amanieu avatar Jun 02 '22 16:06 Amanieu

I used a command inspired by that Twitter post to download and search every crate version. What I found was:

  • Nix
  • A few Nix forks, all since abandoned
  • The autd-timer and autd3-timer crates, both abandoned and deleted from their upstream repo with the comments "start over" and "start over v2"
  • The async-timer crate, which used this symbol up until v0.2.7, but then stopped. And FWIW it never used that symbol correctly.
  • A bunch of false positives

asomers avatar Jun 02 '22 20:06 asomers

@Amanieu do you approve of the plan to fix libc and deal with the breakage by immediately publishing patch releases of Nix?

asomers avatar Jun 11 '22 00:06 asomers

I'm concerned about the amount of breakage: there's a lot of crates that aren't using the latest major version of Nix. Do you think we could implement a backward-compatibility hack using Deref/DerefMut so that .sigev_notify_thread_id continues to work?

Amanieu avatar Jun 11 '22 00:06 Amanieu

We would definitely patch more than just the current major version. I think I should be able to do the top five or six. But what about this DerefMut proposal. How would that work?

asomers avatar Jun 11 '22 01:06 asomers

If we implement DerefMut for sigevent such that it dereferences to an anonymous union with a sigev_notify_thread_id, existing users of sigev_notify_thread_id should still continue working. We also don't need to worry about accessing uninitialized data since reading out of a union is still unsafe.

Amanieu avatar Jun 11 '22 01:06 Amanieu

That's a good idea, and it looks like it works! I'll amend the PR.

asomers avatar Jun 11 '22 01:06 asomers

@Amanieu the remaining CI failure is due to a limitation in the style checker. It doesn't understand that the type declaration is part of an impl block. I'm not sure how to fix that. Do you have any ideas?

asomers avatar Jun 11 '22 17:06 asomers

Not sure about how to deal with the style checker, @JohnTitor any ideas?

Amanieu avatar Jun 12 '22 00:06 Amanieu

Not sure about how to deal with the style checker, @JohnTitor any ideas?

Fixed in #2824

JohnTitor avatar Jun 12 '22 06:06 JohnTitor

Rebased and squashed.

asomers avatar Jun 14 '22 01:06 asomers

@bors r+

Amanieu avatar Jun 16 '22 14:06 Amanieu

:pushpin: Commit ec3ef178bedc9d501283647269bdd2cf6b37f71e has been approved by Amanieu

bors avatar Jun 16 '22 14:06 bors

:hourglass: Testing commit ec3ef178bedc9d501283647269bdd2cf6b37f71e with merge f4be5776f9229cf39935634d0817a2f2df740379...

bors avatar Jun 16 '22 14:06 bors

:broken_heart: Test failed - checks-actions

bors avatar Jun 16 '22 14:06 bors

@bors r+

Amanieu avatar Jun 16 '22 20:06 Amanieu

:pushpin: Commit b543967199223ad91bf7c37a6ddb274ef938ed64 has been approved by Amanieu

bors avatar Jun 16 '22 20:06 bors

:hourglass: Testing commit b543967199223ad91bf7c37a6ddb274ef938ed64 with merge cab2ffed062c72446cf8eceed51cdf298a76eb64...

bors avatar Jun 16 '22 20:06 bors

:broken_heart: Test failed - checks-actions

bors avatar Jun 16 '22 20:06 bors

@bors r+

Amanieu avatar Jun 16 '22 22:06 Amanieu

:pushpin: Commit d7420e6bf7be507bf0076025fbb9d9b432100992 has been approved by Amanieu

bors avatar Jun 16 '22 22:06 bors

:hourglass: Testing commit d7420e6bf7be507bf0076025fbb9d9b432100992 with merge 6aead05faf27e0a86f64322ed0bccc82e395feed...

bors avatar Jun 16 '22 22:06 bors

:broken_heart: Test failed - checks-actions

bors avatar Jun 16 '22 22:06 bors

@bors r+

Amanieu avatar Jun 16 '22 22:06 Amanieu