Skip to content

Fix path reolution in sandboxed build environments - #5338

Open
ephemeralriggs wants to merge 1 commit into
rust-lang:mainfrom
ephemeralriggs:pathresolution
Open

Fix path reolution in sandboxed build environments#5338
ephemeralriggs wants to merge 1 commit into
rust-lang:mainfrom
ephemeralriggs:pathresolution

Conversation

@ephemeralriggs

Copy link
Copy Markdown

Description

This fixes an invalid relative module path resolution in src/new/glibc/sysdeps/nptl/mod.rs that causes build failures in sandboxed/hermetic build environments (e.g. Bazel, Nix, and isolated containers).
When rustc runs inside these sandboxes, calling open() on sysdeps/nptl/bits/../../x86/nptl/bits/struct_mutex.rs may fail with ENOENT because the bits directory may not exist.

Checklist

  • [N/A] Relevant tests in libc-test/semver have been updated
  • [N/A] Commit messages permalink to headers for added or changed API
  • [N/A] Placeholder or unstable values like *LAST or *MAX have the standard
    doc comment
  • [YES] Tested locally (cargo test -p libc-test --target mytarget); also tested on Fuchsia CI builders
    @rustbot label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Jul 29, 2026
This fixes an invalid relative module path resolution in
src/new/glibc/sysdeps/nptl/mod.rs that causes build failures in
sandboxed/hermetic build environments (e.g. Bazel, Nix, and isolated
containers).
When rustc runs inside these sandboxes, calling open() on
sysdeps/nptl/bits/../../x86/nptl/bits/struct_mutex.rs may fail with
ENOENT because the bits directory may not exist.

Signed-off-by: Thomas Zander <thomasalpinus@google.com>

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind clarifying where the problem comes from? Since path resolution comes from rustc I wouldn't expect it to be different for different build systems.

View changes since this review

Comment on lines 9 to 34
#[cfg_attr(
any(
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "mips",
target_arch = "mips32r6",
),
path = "../../mips/nptl/bits/struct_mutex.rs"
any(target_arch = "mips", target_arch = "mips32r6",),
path = "../mips/nptl/bits/struct_mutex.rs"
)]
#[cfg_attr(
any(target_arch = "powerpc", target_arch = "powerpc64"),
path = "../../powerpc/nptl/bits/struct_mutex.rs"
path = "../powerpc/nptl/bits/struct_mutex.rs"
)]
#[cfg_attr(target_arch = "s390x", path = "../../s390/nptl/bits/struct_mutex.rs")]
#[cfg_attr(target_arch = "s390x", path = "../s390/nptl/bits/struct_mutex.rs")]
#[cfg_attr(
any(target_arch = "x86", target_arch = "x86_64"),
path = "../../x86/nptl/bits/struct_mutex.rs"
path = "../x86/nptl/bits/struct_mutex.rs"
)]
#[cfg_attr(
not(any(
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "s390x",
target_arch = "x86",
target_arch = "x86_64",
)),
path = "bits/struct_mutex.rs"
)]
pub(crate) mod struct_mutex;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use cfg_if (repeating mod struct_mutex in each) so we get the fallback without needing to duplicate the arch list?

@tgross35

Copy link
Copy Markdown
Contributor

Actually, is the issue that the bits directory is getting deleted because struct_mutex.rs isn't used? If that's the case, I think I'd rather add an empty.rs file to get it to stick around (it should get used more in the near future).

Separately I wonder if rustc could/should attempt to normalize_lexically if the path doesn't exist. Or if the build systems should be keeping the directory structure somehow.

@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@rustbot author, awaiting feedback

@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants