Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,10 +1763,6 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {

// Returns true if linker is located within sysroot
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
// Assume `-C linker=rust-lld` as self-contained mode
if linker == Path::new("rust-lld") {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Below only the sysroot from which we get the standard library is checked, not the fallback sysroot that rustc itself is contained in. rust-lld is likely to be contained only in the latter if the former is overriden.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fairly sure from my tests the sysroot would point at ~/.rustup/toolchains/<toolchain>.

If I read

fn default_from_rustc_driver_dll() -> Result<PathBuf, String> {
right, it would indeed stirp all the subdirectories.

Copy link
Member

@bjorn3 bjorn3 Dec 3, 2025

Choose a reason for hiding this comment

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

The code below only strips sess.opts.sysroot.path(), which only returns the value explicitly passed to --sysroot if passed, only returning the fallback sysroot when it isn't passed.

/// Return explicit sysroot if it was passed with `--sysroot`, or default sysroot otherwise.
pub fn path(&self) -> &Path {
self.explicit.as_deref().unwrap_or(&self.default)
}
You need sess.opts.sysroot.all_paths() to check both.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, but is --sysroot ever passed to rustc when building natively (host == target)?

Copy link
Member

Choose a reason for hiding this comment

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

There are legitimate reasons to pass it when building natively. For example miri does for it's copy of the standard library that contains MIR for all functions (though it doesn't need a linker). cargo build -Zbuild-std doesn't use --sysroot currently, but I think it should pass --sysroot /dev/null or something like that to prevent accidentally picking up libraries from the sysroot. The only thing that leads to is lang item conflicts. --sysroot /dev/null would give nicer error messages.

Copy link
Member

Choose a reason for hiding this comment

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

--sysroot /dev/null would break all cases of implicit self-contained detection, not just rust-lld. I mean, there is no obvious issue caused by this PR, not that there is no general issue with implicit self-contained detection.

Copy link
Member

Choose a reason for hiding this comment

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

Right. The self-contained components are themself only looked up in --sysroot. Didn't think of that.

let linker_with_extension = if cfg!(windows) && linker.extension().is_none() {
linker.with_extension("exe")
} else {
Expand Down
Loading