diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b7e2583aad3..65ceb691906 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: printf '[profile.release]\nlto = "fat"\n' >> build/build_sysroot/sysroot_src/library/Cargo.toml EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }} - - name: Run y.sh cargo build + - name: LTO test run: | EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||: @@ -92,6 +92,21 @@ jobs: exit 1 fi + - name: Cross-language LTO test + run: | + pushd tests/cross_lang_lto + gcc -c -flto add.c -masm=intel -fPIC -O3 + ar rcs libadd.a add.o + popd + + EMBED_LTO_BITCODE=1 CHANNEL="release" CG_RUSTFLAGS="-L native=. -Clinker-plugin-lto -Clinker=gcc" ./y.sh cargo build --release --manifest-path tests/cross_lang_lto/Cargo.toml + call_found=$(objdump -dj .text tests/cross_lang_lto/target/release/cross_lang_lto | grep -c "call .*my_add" ) ||: + if [ $call_found -gt 0 ]; then + echo "ERROR: call my_add found in asm" + echo "Test is done with cross-language LTO enabled, hence inlining should occur across object files" + exit 1 + fi + # Summary job for the merge queue. # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! success_release: diff --git a/tests/cross_lang_lto/Cargo.lock b/tests/cross_lang_lto/Cargo.lock new file mode 100644 index 00000000000..a0c9d2df383 --- /dev/null +++ b/tests/cross_lang_lto/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "cross_lang_lto" +version = "0.1.0" diff --git a/tests/cross_lang_lto/Cargo.toml b/tests/cross_lang_lto/Cargo.toml new file mode 100644 index 00000000000..777e6548df2 --- /dev/null +++ b/tests/cross_lang_lto/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cross_lang_lto" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/tests/cross_lang_lto/add.c b/tests/cross_lang_lto/add.c new file mode 100644 index 00000000000..cc59f113bc1 --- /dev/null +++ b/tests/cross_lang_lto/add.c @@ -0,0 +1,5 @@ +#include + +uint32_t my_add(uint32_t a, uint32_t b) { + return a + b; +} diff --git a/tests/cross_lang_lto/src/main.rs b/tests/cross_lang_lto/src/main.rs new file mode 100644 index 00000000000..a7180b33396 --- /dev/null +++ b/tests/cross_lang_lto/src/main.rs @@ -0,0 +1,18 @@ +/* + * Compile the C code with: + * gcc -c -flto add.c -ffat-lto-objects + * ar rcs libadd.a add.o + * + * Compile the Rust code with: + * EMBED_LTO_BITCODE=1 CG_RUSTFLAGS="-L native=. -Clinker-plugin-lto -Clinker=gcc" y cargo run --release + */ + +#[link(name="add")] +unsafe extern "C" { + fn my_add(a: u32, b: u32) -> u32; +} + +fn main() { + let res = unsafe { my_add(30, 12) }; + println!("{}", res); +}