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

Do not copy libstd dynamic library to sysroot #131188

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ fn main() {
// When statically linking `std` into `rustc_driver`, remove `-C prefer-dynamic`
if env::var("RUSTC_LINK_STD_INTO_RUSTC_DRIVER").unwrap() == "1"
&& crate_name == Some("rustc_driver")
&& stage != "0"
{
if let Some(pos) = args.iter().enumerate().position(|(i, a)| {
a == "-C" && args.get(i + 1).map(|a| a == "prefer-dynamic").unwrap_or(false)
Expand Down
18 changes: 17 additions & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,8 +1923,24 @@ impl Step for Assemble {
let src_libdir = builder.sysroot_libdir(build_compiler, host);
for f in builder.read_dir(&src_libdir) {
let filename = f.file_name().into_string().unwrap();
if (is_dylib(&filename) || is_debug_info(&filename)) && !proc_macros.contains(&filename)

let is_proc_macro = proc_macros.contains(&filename);
let is_dylib_or_debug = is_dylib(&filename) || is_debug_info(&filename);

// If we link statically to stdlib, do not copy the libstd dynamic library file
// FIXME: Also do this for Windows once incremental post-optimization stage0 tests
// work without std.dll (see https://github.com/rust-lang/rust/pull/131188).
let can_be_rustc_dynamic_dep = if builder
.link_std_into_rustc_driver(target_compiler.host)
&& !target_compiler.host.is_windows()
{
let is_std = filename.starts_with("std-") || filename.starts_with("libstd-");
!is_std
} else {
true
};

if is_dylib_or_debug && can_be_rustc_dynamic_dep && !is_proc_macro {
builder.copy_link(&f.path(), &rustc_libdir.join(&filename));
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/command/command-current-dir.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
//@ no-prefer-dynamic We move the binary around, so do not depend dynamically on libstd
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this changed needed? Was it linking to the compiler's std copy before? If so, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test was buggy. It compiled a Rust binary that dynamically linked to libstd.so. Then it moved the binary around, which should have broken it. However, the binary somehow linked to the compiler's std copy instead (!), so it worked by accident.

Copy link
Member

@lqd lqd Oct 3, 2024

Choose a reason for hiding this comment

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

Since UI tests are built with -Cprefer-dynamic did they all (modulo no-prefer-dynamic) dynamically link to the compiler's std?

Copy link
Contributor Author

@Kobzol Kobzol Oct 4, 2024

Choose a reason for hiding this comment

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

I don't think so, no other tests broke. It was probably just caused by the fact that this binary was moved around, lost its link to the target library and then somehow got dynamically linked to the compiler one instead.

EDIT: or, in theory, all tests could have linked to the compiler's std before, and now they link to target instead, that's a second explanation. But that would mean that all cross-compiled tests would be failing before, right?

//@ ignore-wasm32 no processes
//@ ignore-sgx no processes
//@ ignore-fuchsia Needs directory creation privilege
Expand Down
Loading