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

CMSG_SPACE is no longer a const function #4115

Closed
asomers opened this issue Nov 19, 2024 · 9 comments · Fixed by #4134
Closed

CMSG_SPACE is no longer a const function #4115

asomers opened this issue Nov 19, 2024 · 9 comments · Fixed by #4134
Labels
C-bug Category: bug

Comments

@asomers
Copy link
Contributor

asomers commented Nov 19, 2024

CMSG_SPACE is supposed to be a const function. It was, until PR #4105. Now, nix fails to build with the libc-0.2 branch. It fails for both x86_64-unknown-linux-gnu and x86_64-unknown-freebsd. I bisected the regression to verify that it really was #4105.

Steps to reproduce:

$ git clone [email protected]:nix-rust/nix.git
$ cd nix
$ sed -I "" 's!version = "0.2.164"!git = "https://github.com/rust-lang/libc.git", rev = "ae052d3b6a045d58b7ef3187a94de81695e2591e"!' Cargo.toml
$ cargo check --all-features
    Updating crates.io index
    Updating git repository `https://github.com/rust-lang/libc.git`
     Locking 54 packages to latest compatible versions
      Adding sysctl v0.4.6 (available: v0.6.0)
   Compiling autocfg v1.4.0
   Compiling libc v0.2.164 (https://github.com/rust-lang/libc.git?rev=ae052d3b6a045d58b7ef3187a94de81695e2591e#ae052d3b)
   Compiling cfg_aliases v0.2.1
    Checking cfg-if v1.0.0
    Checking pin-utils v0.1.0
    Checking bitflags v2.6.0
   Compiling nix v0.29.0 (/tmp/nix)
   Compiling memoffset v0.9.1
error[E0015]: cannot call non-const fn `CMSG_SPACE` in constant functions
   --> src/sys/socket/mod.rs:652:14
    |
652 |     unsafe { libc::CMSG_SPACE(mem::size_of::<T>() as libc::c_uint) as usize }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

For more information about this error, try `rustc --explain E0015`.
error: could not compile `nix` (lib) due to 1 previous error
@asomers asomers added the C-bug Category: bug label Nov 19, 2024
@tgross35
Copy link
Contributor

Thanks for catching this, I guess the const-extern-fn feature (that we need for ctest) isn't getting enabled. It should be on by default except for when ctest is looking at things.

tgross35 added a commit to tgross35/rust-libc that referenced this issue Nov 23, 2024
This was dropped in fa554bc on `main` and 674cc1f on `libc-0.2`
("Drop the libc_const_extern_fn conditional"). Unfortunately, this meant
that functions were incorrectly never getting marked `const`.

Instead of the fix here, I attempted to just use `cfg(not(libc_ctest))`
instead of a Cargo feature to enable `const` extern functions; however,
this seemed extremely problematic with `ctest` for some reason [1].
Instead, leave the feature as-is and just make it enabled by default.

Fixes: rust-lang#4115

[1]: rust-lang#4134
tgross35 added a commit to tgross35/rust-libc that referenced this issue Nov 23, 2024
This was dropped in fa554bc on `main` and 674cc1f on `libc-0.2`
("Drop the libc_const_extern_fn conditional"). Unfortunately, this meant
that functions were incorrectly never getting marked `const`, which
showed up with `CMSG_SPACE` [1].

Instead of the fix here, I attempted to just use `cfg(not(libc_ctest))`
instead of a Cargo feature to enable `const` extern functions; however,
this seemed extremely problematic with `ctest` for some reason [2].
Instead, leave the feature as-is and just make it enabled by default.

Fixes: rust-lang#4115 [1]

[2]: rust-lang#4134
tgross35 added a commit to tgross35/rust-libc that referenced this issue Nov 23, 2024
This was dropped in fa554bc on `main` and 674cc1f on `libc-0.2`
("Drop the libc_const_extern_fn conditional"). Unfortunately, this meant
that functions were incorrectly never getting marked `const`, which
showed up with `CMSG_SPACE` [1].

Instead of the fix here, I attempted to just use `cfg(not(libc_ctest))`
instead of a Cargo feature to enable `const` extern functions; however,
this seemed extremely problematic with `ctest` for some reason [2].
Instead, leave the feature as-is and just make it enabled by default.

Fixes: rust-lang#4115 [1]

[2]: rust-lang#4134

(backport <rust-lang#4134>)
(cherry picked from commit 9f23a63)
tgross35 added a commit to tgross35/rust-libc that referenced this issue Nov 25, 2024
This was dropped in fa554bc on `main` and 674cc1f on `libc-0.2`
("Drop the libc_const_extern_fn conditional"). Unfortunately, this meant
that functions were incorrectly never getting marked `const`, which
showed up with `CMSG_SPACE` [1].

Instead of the fix here, I attempted to just use `cfg(not(libc_ctest))`
instead of a Cargo feature to enable `const` extern functions; however,
this seemed extremely problematic with `ctest` for some reason [2].
Instead, leave the feature as-is and just make it enabled by default.

Fixes: rust-lang#4115 [1]

[2]: rust-lang#4134
tgross35 added a commit to tgross35/rust-libc that referenced this issue Nov 25, 2024
This was dropped in fa554bc on `main` and 674cc1f on `libc-0.2`
("Drop the libc_const_extern_fn conditional"). Unfortunately, this meant
that functions were incorrectly never getting marked `const`, which
showed up with `CMSG_SPACE` [1].

Instead of the fix here, I attempted to just use `cfg(not(libc_ctest))`
instead of a Cargo feature to enable `const` extern functions; however,
this seemed extremely problematic with `ctest` for some reason [2].
Instead, leave the feature as-is and just make it enabled by default.

Fixes: rust-lang#4115 [1]

[2]: rust-lang#4134
tgross35 added a commit to tgross35/rust-libc that referenced this issue Nov 25, 2024
This was dropped in fa554bc on `main` and 674cc1f on `libc-0.2`
("Drop the libc_const_extern_fn conditional"). Unfortunately, this meant
that functions were incorrectly never getting marked `const`, which
showed up with `CMSG_SPACE` [1].

Instead of the fix here, I attempted to just use `cfg(not(libc_ctest))`
instead of a Cargo feature to enable `const` extern functions; however,
this seemed extremely problematic with `ctest` for some reason [2].
Instead, leave the feature as-is and just make it enabled by default.

Fixes: rust-lang#4115 [1]

[2]: rust-lang#4134

(backport <rust-lang#4134>)
(cherry picked from commit 19e9e6a)
@tgross35
Copy link
Contributor

Fyi @SteveLauC this should be resolved

@tamird
Copy link
Contributor

tamird commented Nov 26, 2024

The current release (0.2.165) should be yanked. It is breaking downstream builds e.g. https://github.com/aya-rs/aya/actions/runs/12023826759/job/33518337160.

@SteveLauC
Copy link
Contributor

The current release (0.2.165) should be yanked. It is breaking downstream builds e.g. https://github.com/aya-rs/aya/actions/runs/12023826759/job/33518337160.

This issue was fixed in 0.2.165 🤔

@tamird
Copy link
Contributor

tamird commented Nov 26, 2024

The current release (0.2.165) should be yanked. It is breaking downstream builds e.g. https://github.com/aya-rs/aya/actions/runs/12023826759/job/33518337160.

This issue was fixed in 0.2.165 🤔

I don't think so. 79afdce isn't contained in the 0.2.165 tag.

EDIT: 940e7e7 is the backport and it is indeed in 0.2.165. However I am still seeing compilation failure.

@tamird
Copy link
Contributor

tamird commented Nov 26, 2024

Looks like this is still an issue under miri in particular. I can reproduce it in aya:

tamird@Mac aya % cargo +nightly miri test --package aya --all-targets --target x86_64-unknown-linux-gnu --no-default-features --features async_std -- nothing-at-all
   Compiling rustix v0.38.41
error[E0015]: cannot call non-const fn `libc::CMSG_SPACE` in constant functions
   --> /Users/tamird/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustix-0.38.41/src/net/send_recv/msg.rs:120:14
    |
120 |     unsafe { c::CMSG_SPACE(converted_len) as usize }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

For more information about this error, try `rustc --explain E0015`.
error: could not compile `rustix` (lib) due to 1 previous error

@tamird
Copy link
Contributor

tamird commented Nov 26, 2024

The problem is that this feature is on by default, which is not the same as it being on always. rustix uses default-features=false which is the root cause of this breakage.

@tamird
Copy link
Contributor

tamird commented Nov 26, 2024

Filed a new bug: #4149.

@tgross35
Copy link
Contributor

The above was addressed in 0.2.166 https://github.com/rust-lang/libc/releases/tag/0.2.166

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.

4 participants