Skip to content

Add missing getauxval for Linux uClibc targets #3738

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

Merged
merged 1 commit into from
Jun 16, 2024

Conversation

operutka
Copy link
Contributor

@operutka operutka commented Jun 5, 2024

This should fix the following error when building Rust std on Linux uClibc targets.

error[E0425]: cannot find function `getauxval` in crate `libc`
   --> /home/operutka/.rustup/toolchains/nightly-2024-06-05-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/stack_overflow.rs:237:47
    |
237 |         let dynamic_sigstksz = unsafe { libc::getauxval(AT_MINSIGSTKSZ) };
    |                                               ^^^^^^^^^ not found in `libc`

@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2024

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@JohnTitor JohnTitor added this pull request to the merge queue Jun 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 8, 2024
@operutka
Copy link
Contributor Author

@JohnTitor the pull request has been removed from the merge queue due to some unrelated problems in the CI pipeline. Is there anything I can do to fix this?

@JohnTitor
Copy link
Member

Sorry! It has been fixed now.

@JohnTitor JohnTitor enabled auto-merge June 16, 2024 11:08
@JohnTitor JohnTitor added this pull request to the merge queue Jun 16, 2024
Merged via the queue into rust-lang:libc-0.2 with commit db6ef14 Jun 16, 2024
57 checks passed
@tgross35 tgross35 added the main-needs-cherry-pick This PR was merged against libc-0.2 but does not yet exist in main. label Aug 13, 2024
This was referenced Aug 15, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Aug 29, 2024
(apply <rust-lang#3738> to `main`)
(cherry picked from commit 3940851)
@tgross35 tgross35 added main-applied This PR was merged against libc-0.2 and main has since been updated to include it and removed main-needs-cherry-pick This PR was merged against libc-0.2 but does not yet exist in main. labels Aug 29, 2024
@skrap
Copy link
Contributor

skrap commented Oct 17, 2024

Hmm, I wonder what we should do for uclibc targets which do not include getauxval? It's optional in some (all?) versions of uclibc, and for those of us working with unchangeable uclibc configurations, this means that we can't build rust without patching libc to include an implementation of getauxval.

Of course, that's not the fault of this PR; I only raise it here because the audience might have some thoughts.

One possibility: I could try to set up a cfg switch, similar to the which_freebsd() function from build.rs, which might be able to detect an older uclibc without a getauxval implementation and provide its own.

OTOH I know we don't really want implementation in this crate. Not sure where an alternative spot would be, though.

@operutka
Copy link
Contributor Author

@skrap I've also had to deal with this. The problem is that Rust std can't be built without getauxval, so removing (or feature-gating) it here doesn't really help. Right now I use a feature flag in my app that can enable an empty getauxval implementation. Something like:

#[cfg(feature = "fake-getauxval")]
#[no_mangle]
extern "C" fn getauxval(_: c_ulong) -> c_ulong {
    0
}

But, as you suggested, detecting it in build.rs and supplying an empty implementation if it isn't provided by the C library would be probably a better option.

I think the question is if Rust std should really depend on this function or if it can detect that the function isn't available. The libc crate could then export it only if it's actually available and Rust std wouldn't require it unless it's available. But that's probably a question for people more deeply involved in the libc and Rust std projects then I am :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
main-applied This PR was merged against libc-0.2 and main has since been updated to include it S-waiting-on-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants