|
| 1 | +// This test makes sure that cross-language inlining can be used in conjunction |
| 2 | +// with profile-guided optimization. The test only tests that the whole workflow |
| 3 | +// can be executed without anything crashing. It does not test whether PGO or |
| 4 | +// xLTO have any specific effect on the generated code. |
| 5 | +// See https://github.com/rust-lang/rust/pull/61036 |
| 6 | + |
| 7 | +//@ needs-force-clang-based-tests |
| 8 | +// NOTE(#126180): This test would only run on `x86_64-gnu-debug`, because that CI job sets |
| 9 | +// RUSTBUILD_FORCE_CLANG_BASED_TESTS and only runs tests which contain "clang" in their |
| 10 | +// name. |
| 11 | + |
| 12 | +//@ needs-profiler-support |
| 13 | +// FIXME(Oneirical): Except that due to the reliance on llvm-profdata, this test |
| 14 | +// never runs, because `x86_64-gnu-debug` does not have the `profiler_builtins` crate. |
| 15 | + |
| 16 | +//FIXME(Oneirical): There was a strange workaround for MSVC on this test |
| 17 | +// which added -C panic=abort to every RUSTC call. It was justified as follows: |
| 18 | + |
| 19 | +// "LLVM doesn't support instrumenting binaries that use SEH: |
| 20 | +// https://bugs.llvm.org/show_bug.cgi?id=41279 |
| 21 | +// Things work fine with -Cpanic=abort though." |
| 22 | + |
| 23 | +// This isn't very pertinent, however, as the test does not get run on any |
| 24 | +// MSVC platforms. |
| 25 | + |
| 26 | +use run_make_support::{ |
| 27 | + clang, env_var, has_extension, has_prefix, llvm_ar, llvm_profdata, rfs, run, rustc, |
| 28 | + shallow_find_files, static_lib_name, |
| 29 | +}; |
| 30 | + |
| 31 | +fn main() { |
| 32 | + rustc() |
| 33 | + .linker_plugin_lto("on") |
| 34 | + .output(static_lib_name("rustlib-xlto")) |
| 35 | + .opt_level("3") |
| 36 | + .codegen_units(1) |
| 37 | + .input("rustlib.rs") |
| 38 | + .arg("-Cprofile-generate=cpp-profdata") |
| 39 | + .run(); |
| 40 | + clang() |
| 41 | + .lto("thin") |
| 42 | + .arg("-fprofile-generate=cpp-profdata") |
| 43 | + .use_ld("lld") |
| 44 | + .arg("-lrustlib-xlto") |
| 45 | + .out_exe("cmain") |
| 46 | + .input("cmain.c") |
| 47 | + .arg("-O3") |
| 48 | + .run(); |
| 49 | + run("cmain"); |
| 50 | + // Postprocess the profiling data so it can be used by the compiler |
| 51 | + let profraw_files = shallow_find_files("cpp-profdata", |path| { |
| 52 | + has_prefix(path, "default") && has_extension(path, "profraw") |
| 53 | + }); |
| 54 | + let profraw_file = profraw_files.get(0).unwrap(); |
| 55 | + llvm_profdata().merge().output("cpp-profdata/merged.profdata").input(profraw_file).run(); |
| 56 | + rustc() |
| 57 | + .linker_plugin_lto("on") |
| 58 | + .profile_use("cpp-profdata/merged.profdata") |
| 59 | + .output(static_lib_name("rustlib-xlto")) |
| 60 | + .opt_level("3") |
| 61 | + .codegen_units(1) |
| 62 | + .input("rustlib.rs") |
| 63 | + .run(); |
| 64 | + clang() |
| 65 | + .lto("thin") |
| 66 | + .arg("-fprofile-use=cpp-profdata/merged.profdata") |
| 67 | + .use_ld("lld") |
| 68 | + .arg("-lrustlib-xlto") |
| 69 | + .out_exe("cmain") |
| 70 | + .input("cmain.c") |
| 71 | + .arg("-O3") |
| 72 | + .run(); |
| 73 | + |
| 74 | + clang() |
| 75 | + .input("clib.c") |
| 76 | + .arg("-fprofile-generate=rs-profdata") |
| 77 | + .lto("thin") |
| 78 | + .arg("-c") |
| 79 | + .out_exe("clib.o") |
| 80 | + .arg("-O3") |
| 81 | + .run(); |
| 82 | + llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run(); |
| 83 | + rustc() |
| 84 | + .linker_plugin_lto("on") |
| 85 | + .opt_level("3") |
| 86 | + .codegen_units(1) |
| 87 | + .arg("-Cprofile-generate=rs-profdata") |
| 88 | + .linker(&env_var("CLANG")) |
| 89 | + .link_arg("-fuse-ld=lld") |
| 90 | + .input("main.rs") |
| 91 | + .output("rsmain") |
| 92 | + .run(); |
| 93 | + run("rsmain"); |
| 94 | + // Postprocess the profiling data so it can be used by the compiler |
| 95 | + let profraw_files = shallow_find_files("rs-profdata", |path| { |
| 96 | + has_prefix(path, "default") && has_extension(path, "profraw") |
| 97 | + }); |
| 98 | + let profraw_file = profraw_files.get(0).unwrap(); |
| 99 | + llvm_profdata().merge().output("rs-profdata/merged.profdata").input(profraw_file).run(); |
| 100 | + clang() |
| 101 | + .input("clib.c") |
| 102 | + .arg("-fprofile-use=rs-profdata/merged.profdata") |
| 103 | + .arg("-c") |
| 104 | + .lto("thin") |
| 105 | + .out_exe("clib.o") |
| 106 | + .arg("-O3") |
| 107 | + .run(); |
| 108 | + rfs::remove_file(static_lib_name("xyz")); |
| 109 | + llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run(); |
| 110 | + rustc() |
| 111 | + .linker_plugin_lto("on") |
| 112 | + .opt_level("3") |
| 113 | + .codegen_units(1) |
| 114 | + .arg("-Cprofile-use=rs-profdata/merged.profdata") |
| 115 | + .linker(&env_var("CLANG")) |
| 116 | + .link_arg("-fuse-ld=lld") |
| 117 | + .input("main.rs") |
| 118 | + .output("rsmain") |
| 119 | + .run(); |
| 120 | +} |
0 commit comments