|
| 1 | +// Ensure that crates compiled with different rustc versions cannot |
| 2 | +// be dynamically linked. |
| 3 | + |
| 4 | +//@ ignore-cross-compile |
| 5 | + |
| 6 | +use run_make_support::llvm; |
| 7 | +use run_make_support::{diff, dynamic_lib_name, is_darwin, run, run_fail, rustc}; |
| 8 | + |
| 9 | +fn llvm_readobj() -> llvm::LlvmReadobj { |
| 10 | + let mut cmd = llvm::llvm_readobj(); |
| 11 | + if is_darwin() { |
| 12 | + cmd.symbols(); |
| 13 | + } else { |
| 14 | + cmd.dynamic_table(); |
| 15 | + } |
| 16 | + cmd |
| 17 | +} |
| 18 | + |
| 19 | +fn main() { |
| 20 | + let flags = ["-Cprefer-dynamic", "-Csymbol-mangling-version=v0"]; |
| 21 | + |
| 22 | + // a.rs is compiled to a dylib |
| 23 | + rustc().input("a.rs").crate_type("dylib").args(&flags).run(); |
| 24 | + |
| 25 | + // Store symbols |
| 26 | + let symbols_before = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8(); |
| 27 | + |
| 28 | + // b.rs is compiled to a binary |
| 29 | + rustc() |
| 30 | + .input("b.rs") |
| 31 | + .extern_("a", dynamic_lib_name("a")) |
| 32 | + .crate_type("bin") |
| 33 | + .arg("-Crpath") |
| 34 | + .args(&flags) |
| 35 | + .run(); |
| 36 | + run("b"); |
| 37 | + |
| 38 | + // Now re-compile a.rs with another rustc version |
| 39 | + rustc() |
| 40 | + .env("RUSTC_FORCE_RUSTC_VERSION", "deadfeed") |
| 41 | + .input("a.rs") |
| 42 | + .crate_type("dylib") |
| 43 | + .args(&flags) |
| 44 | + .run(); |
| 45 | + |
| 46 | + // After compiling with a different rustc version, store symbols again. |
| 47 | + let symbols_after = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8(); |
| 48 | + |
| 49 | + // As a sanity check, test if the symbols changed: |
| 50 | + // If the symbols are identical, there's been an error. |
| 51 | + diff() |
| 52 | + .expected_text("symbols_before", symbols_before) |
| 53 | + .actual_text("symbols_after", symbols_after) |
| 54 | + .run_fail(); |
| 55 | + run_fail("b"); |
| 56 | +} |
0 commit comments