Skip to content

Commit

Permalink
rewrite no-builtins-lto to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 17, 2024
1 parent cabc982 commit df6d873
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ run-make/native-link-modifier-verbatim-rustc/Makefile
run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile
run-make/no-builtins-attribute/Makefile
run-make/no-builtins-lto/Makefile
run-make/no-duplicate-libs/Makefile
run-make/obey-crate-type-flag/Makefile
run-make/optimization-remarks-dir-pgo/Makefile
Expand Down
5 changes: 4 additions & 1 deletion tests/run-make/lto-avoid-object-duplication/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore-tidy-tab
// Staticlibs don't include Rust object files from upstream crates if the same
// code was already pulled into the lib via LTO. However, the bug described in
// https://github.com/rust-lang/rust/issues/64153 lead to this exclusion not
Expand All @@ -10,6 +11,8 @@
//@ ignore-windows
// Reason: `llvm-objdump`'s output looks different on windows than on other platforms.
// Only checking on Unix platforms should suffice.
//FIXME(Oneirical): This could be adapted to work on Windows by checking how
// that output differs.

use run_make_support::{llvm_objdump, regex, rust_lib_name, rustc, static_lib_name};

Expand All @@ -28,7 +31,7 @@ fn main() {
.codegen_units(1)
.run();
let syms = llvm_objdump().arg("-t").input(static_lib_name("downstream")).run().stdout_utf8();
let re = regex::Regex::new(r#"(?m)\s*g\s*F\s.*issue64153_test_function"#).unwrap();
let re = regex::Regex::new(r#"\s*g\s*F\s.*issue64153_test_function"#).unwrap();
// Count the global instances of `issue64153_test_function`. There'll be 2
// if the `upstream` object file got erroneously included twice.
// The line we are testing for with the regex looks something like:
Expand Down
9 changes: 0 additions & 9 deletions tests/run-make/no-builtins-lto/Makefile

This file was deleted.

20 changes: 20 additions & 0 deletions tests/run-make/no-builtins-lto/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// The rlib produced by a no_builtins crate should be explicitely linked
// during compilation, and as a result be present in the linker arguments.
// See the comments inside this file for more details.
// See https://github.com/rust-lang/rust/pull/35637

use run_make_support::{rust_lib_name, rustc};

fn main() {
// Compile a `#![no_builtins]` rlib crate
rustc().input("no_builtins.rs").run();
// Build an executable that depends on that crate using LTO. The no_builtins crate doesn't
// participate in LTO, so its rlib must be explicitly
// linked into the final binary. Verify this by grepping the linker arguments.
rustc()
.input("main.rs")
.arg("-Clto")
.print("link-args")
.run()
.assert_stdout_contains(rust_lib_name("no_builtins"));
}

0 comments on commit df6d873

Please sign in to comment.