Skip to content
Open
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
3 changes: 3 additions & 0 deletions tests/run-make/no-builtins-linker-plugin-lto/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
no_builtins::foo();
}
4 changes: 4 additions & 0 deletions tests/run-make/no-builtins-linker-plugin-lto/no_builtins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![no_builtins]

#[inline(never)]
pub fn foo() {}
53 changes: 53 additions & 0 deletions tests/run-make/no-builtins-linker-plugin-lto/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//@ only-x86_64-unknown-linux-gnu

use std::fs;
use std::path::Path;

use run_make_support::{cwd, has_extension, llvm_ar, llvm_bcanalyzer, rust_lib_name, rustc};

// A regression test for #146133.

fn main() {
// Compile a `#![no_builtins]` rlib crate with `-Clinker-plugin-lto`.
// It is acceptable to generate bitcode for rlib, so there is no need to check something.
rustc().input("no_builtins.rs").crate_type("rlib").linker_plugin_lto("on").run();

// Checks that rustc's LTO doesn't emit any bitcode to the linker.
let stdout = rustc()
.input("main.rs")
.extern_("no_builtins", rust_lib_name("no_builtins"))
.lto("thin")
.print("link-args")
.arg("-Csave-temps")
.arg("-Clinker-features=-lld")
.run()
.stdout_utf8();
for object in stdout
.split_whitespace()
.map(|s| s.trim_matches('"'))
.filter(|path| has_extension(path, "rlib") || has_extension(path, "o"))
{
let object_path = if !fs::exists(object).unwrap() {
cwd().join(object)
} else {
Path::new(object).to_path_buf()
};
if has_extension(object, "rlib") {
let ar_stdout = llvm_ar().arg("t").arg(&object_path).run().stdout_utf8();
llvm_ar().extract().arg(&object_path).run();
for object in ar_stdout.split_whitespace().filter(|o| has_extension(o, "o")) {
let object_path = cwd().join(object);
not_bitcode(&object_path);
}
} else {
not_bitcode(&object_path);
}
}
}

fn not_bitcode(object: &Path) {
llvm_bcanalyzer()
.input(object)
.run_fail()
.assert_stderr_contains("llvm-bcanalyzer: Invalid record at top-level");
}
Loading