File: rmake.rs

package info (click to toggle)
rustc 1.89.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 906,624 kB
  • sloc: xml: 158,148; python: 34,888; javascript: 19,595; sh: 19,221; ansic: 13,046; cpp: 7,144; asm: 4,376; makefile: 692; lisp: 174; sql: 15
file content (39 lines) | stat: -rw-r--r-- 1,658 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Linkers treat archives differently from object files: all object files participate in linking,
// while archives will only participate in linking if they can satisfy at least one undefined
// reference (version scripts doesn't count). This causes `#[no_mangle]` or `#[used]` items to
// be ignored by the linker, and since they never participate in the linking, using `KEEP` in the
// linker scripts can't keep them either. This causes #47384. After the fix in #95604, this test
// checks that these symbols and sections successfully appear in the output dynamic library.
// See https://github.com/rust-lang/rust/pull/95604
// See https://github.com/rust-lang/rust/issues/47384

//@ ignore-cross-compile
//@ needs-crate-type: cdylib
//@ needs-dynamic-linking
//@ ignore-wasm differences in object file formats causes errors in the llvm_objdump step.
//@ ignore-windows differences in object file formats causes errors in the llvm_objdump step.

use run_make_support::{dynamic_lib_name, llvm_objdump, llvm_readobj, rustc, target};

fn main() {
    rustc().crate_type("lib").input("lib.rs").run();
    let mut main = rustc();
    main.crate_type("cdylib");
    if target().contains("linux") {
        main.link_args("-Tlinker.ld");
    }
    main.input("main.rs").run();

    // Ensure `#[used]` and `KEEP`-ed section is there
    llvm_objdump()
        .arg("--full-contents")
        .arg("--section=.static")
        .input(dynamic_lib_name("main"))
        .run();
    // Ensure `#[no_mangle]` symbol is there
    llvm_readobj()
        .arg("--symbols")
        .input(dynamic_lib_name("main"))
        .run()
        .assert_stdout_contains("bar");
}