|
| 1 | +//@ only-x86_64-unknown-linux-gnu |
| 2 | + |
| 3 | +use std::fs; |
| 4 | +use std::path::Path; |
| 5 | + |
| 6 | +use run_make_support::{cwd, has_extension, llvm_ar, llvm_bcanalyzer, rust_lib_name, rustc}; |
| 7 | + |
| 8 | +// A regression test for #146133. |
| 9 | + |
| 10 | +fn main() { |
| 11 | + // Compile a `#![no_builtins]` rlib crate with `-Clinker-plugin-lto`. |
| 12 | + // It is acceptable to generate bitcode for rlib, so there is no need to check something. |
| 13 | + rustc().input("no_builtins.rs").crate_type("rlib").linker_plugin_lto("on").run(); |
| 14 | + |
| 15 | + // Checks that rustc's LTO doesn't emit any bitcode to the linker. |
| 16 | + let stdout = rustc() |
| 17 | + .input("main.rs") |
| 18 | + .extern_("no_builtins", rust_lib_name("no_builtins")) |
| 19 | + .lto("thin") |
| 20 | + .print("link-args") |
| 21 | + .arg("-Csave-temps") |
| 22 | + .arg("-Clinker-features=-lld") |
| 23 | + .run() |
| 24 | + .stdout_utf8(); |
| 25 | + for object in stdout |
| 26 | + .split_whitespace() |
| 27 | + .map(|s| s.trim_matches('"')) |
| 28 | + .filter(|path| has_extension(path, "rlib") || has_extension(path, "o")) |
| 29 | + { |
| 30 | + let object_path = if !fs::exists(object).unwrap() { |
| 31 | + cwd().join(object) |
| 32 | + } else { |
| 33 | + Path::new(object).to_path_buf() |
| 34 | + }; |
| 35 | + if has_extension(object, "rlib") { |
| 36 | + let ar_stdout = llvm_ar().arg("t").arg(&object_path).run().stdout_utf8(); |
| 37 | + llvm_ar().extract().arg(&object_path).run(); |
| 38 | + for object in ar_stdout.split_whitespace().filter(|o| has_extension(o, "o")) { |
| 39 | + let object_path = cwd().join(object); |
| 40 | + not_bitcode(&object_path); |
| 41 | + } |
| 42 | + } else { |
| 43 | + not_bitcode(&object_path); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +fn not_bitcode(object: &Path) { |
| 49 | + llvm_bcanalyzer() |
| 50 | + .input(object) |
| 51 | + .run_fail() |
| 52 | + .assert_stderr_contains("llvm-bcanalyzer: Invalid record at top-level"); |
| 53 | +} |
0 commit comments