|
| 1 | +//@ needs-rust-lld |
| 2 | +use run_make_support::{llvm_filecheck, llvm_objdump, path, rfs, run, rustc, source_root}; |
| 3 | + |
| 4 | +// Test a thumb target calling arm functions. Doing so requires switching from thumb mode to arm |
| 5 | +// mode, calling the arm code, then switching back to thumb mode. Depending on the thumb version, |
| 6 | +// this happens using a special calling instruction, or by calling a generated thunk that performs |
| 7 | +// the mode switching. |
| 8 | +// |
| 9 | +// In particular this tests that naked functions behave like normal functions. Before LLVM 22, a |
| 10 | +// bug in LLVM caused thumb mode to be used unconditonally when symbols were .hidden, miscompiling |
| 11 | +// calls to arm functions. |
| 12 | +// |
| 13 | +// - https://github.com/llvm/llvm-project/pull/181156 |
| 14 | +// - https://github.com/rust-lang/rust/issues/151946 |
| 15 | + |
| 16 | +macro_rules! helper { |
| 17 | + ($prefix:literal, $test:literal) => { |
| 18 | + rustc() |
| 19 | + .input(source_root().join("tests/auxiliary/minicore.rs")) |
| 20 | + .crate_name("minicore") |
| 21 | + .crate_type("rlib") |
| 22 | + .target(concat!($prefix, "-none-eabi")) |
| 23 | + .output("libminicore.rlib") |
| 24 | + .run(); |
| 25 | + let minicore = path("libminicore.rlib"); |
| 26 | + |
| 27 | + rustc() |
| 28 | + .input(concat!($test, ".rs")) |
| 29 | + .panic("abort") |
| 30 | + .link_arg("-Tlink.ld") |
| 31 | + .arg("--extern") |
| 32 | + .arg(format!("minicore={}", minicore.display())) |
| 33 | + .target(concat!($prefix, "-none-eabi")) |
| 34 | + .output(concat!($prefix, "-", $test)) |
| 35 | + .run(); |
| 36 | + |
| 37 | + let dump = |
| 38 | + llvm_objdump().disassemble().demangle().input(path(concat!($prefix, "-", $test))).run(); |
| 39 | + |
| 40 | + llvm_filecheck() |
| 41 | + .patterns(concat!($test, ".rs")) |
| 42 | + .check_prefix($prefix) |
| 43 | + .stdin_buf(dump.stdout()) |
| 44 | + .run(); |
| 45 | + }; |
| 46 | +} |
| 47 | + |
| 48 | +fn main() { |
| 49 | + // Thumb calling thumb. |
| 50 | + helper!("thumbv5te", "t32"); |
| 51 | + helper!("thumbv4t", "t32"); |
| 52 | + |
| 53 | + // Thumb calling arm. |
| 54 | + helper!("thumbv5te", "a32"); |
| 55 | + helper!("thumbv4t", "a32"); |
| 56 | +} |
0 commit comments