|
| 1 | +//@ ignore-windows Windows does not actually strip |
| 2 | + |
| 3 | +// Test that -Cstrip correctly strips/preserves debuginfo and symbols. |
| 4 | + |
| 5 | +use run_make_support::{bin_name, is_darwin, llvm_dwarfdump, llvm_nm, rustc}; |
| 6 | + |
| 7 | +fn main() { |
| 8 | + // We use DW_ (the start of any DWARF name) to check that some debuginfo is present. |
| 9 | + let dwarf_indicator = "DW_"; |
| 10 | + |
| 11 | + let test_symbol = "hey_i_get_compiled"; |
| 12 | + let binary = &bin_name("hello"); |
| 13 | + |
| 14 | + // Avoid checking debuginfo on darwin, because it is not actually affected by strip. |
| 15 | + // Darwin *never* puts debuginfo in the main binary (-Csplit-debuginfo=off just removes it), |
| 16 | + // so we never actually have any debuginfo in there, so we can't check that it's present. |
| 17 | + let do_debuginfo_check = !is_darwin(); |
| 18 | + |
| 19 | + // Additionally, use -Cdebuginfo=2 to make the test independent of the amount of debuginfo |
| 20 | + // for std. |
| 21 | + |
| 22 | + // -Cstrip=none should preserve symbols and debuginfo. |
| 23 | + rustc().arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=none").run(); |
| 24 | + llvm_nm().input(binary).run().assert_stdout_contains(test_symbol); |
| 25 | + if do_debuginfo_check { |
| 26 | + llvm_dwarfdump().input(binary).run().assert_stdout_contains(dwarf_indicator); |
| 27 | + } |
| 28 | + |
| 29 | + // -Cstrip=debuginfo should preserve symbols and strip debuginfo. |
| 30 | + rustc().arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=debuginfo").run(); |
| 31 | + llvm_nm().input(binary).run().assert_stdout_contains(test_symbol); |
| 32 | + if do_debuginfo_check { |
| 33 | + llvm_dwarfdump().input(binary).run().assert_stdout_not_contains(dwarf_indicator); |
| 34 | + } |
| 35 | + |
| 36 | + // -Cstrip=symbols should strip symbols and strip debuginfo. |
| 37 | + rustc().arg("hello.rs").arg("-Cdebuginfo=2").arg("-Cstrip=symbols").run(); |
| 38 | + llvm_nm().input(binary).run().assert_stderr_not_contains(test_symbol); |
| 39 | + if do_debuginfo_check { |
| 40 | + llvm_dwarfdump().input(binary).run().assert_stdout_not_contains(dwarf_indicator); |
| 41 | + } |
| 42 | +} |
0 commit comments