Skip to content

Commit 8ba16fd

Browse files
committed
Add test for cross-language LTO
1 parent 1f6e396 commit 8ba16fd

File tree

5 files changed

+65
-10
lines changed

5 files changed

+65
-10
lines changed

.github/workflows/release.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,39 @@ jobs:
7575
- name: Add more failing tests because of undefined symbol errors (FIXME)
7676
run: cat tests/failing-lto-tests.txt >> tests/failing-ui-tests.txt
7777

78-
- name: Run tests
79-
run: |
78+
#- name: Run tests
79+
#run: |
8080
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
8181
# FIXME(antoyo): this should probably not be needed since we embed the LTO bitcode.
82-
printf '[profile.release]\nlto = "fat"\n' >> build/build_sysroot/sysroot_src/library/Cargo.toml
83-
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}
84-
85-
- name: Run y.sh cargo build
82+
#printf '[profile.release]\nlto = "fat"\n' >> build/build_sysroot/sysroot_src/library/Cargo.toml
83+
#EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}
84+
85+
#- name: LTO test
86+
#run: |
87+
#EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
88+
#call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||:
89+
#if [ $call_found -gt 0 ]; then
90+
#echo "ERROR: call my_func found in asm"
91+
#echo "Test is done with LTO enabled, hence inlining should occur across crates"
92+
#exit 1
93+
#fi
94+
95+
- name: Cross-language LTO test
8696
run: |
87-
EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
88-
call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||:
97+
pushd tests/cross_lang_lto
98+
gcc -c -flto add.c -masm=intel -fPIC
99+
ar rcs libadd.a add.o
100+
popd
101+
102+
./y.sh build --sysroot --release # TODO: Remove this line.
103+
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
104+
call_found=$(objdump -dj .text tests/cross_lang_lto/target/release/cross_lang_lto | grep -c "call .*my_add" ) ||:
105+
gcc -v
106+
/usr/bin/gcc -v
107+
objdump -dj .text tests/cross_lang_lto/target/release/cross_lang_lto | grep "call .*my_add"
89108
if [ $call_found -gt 0 ]; then
90-
echo "ERROR: call my_func found in asm"
91-
echo "Test is done with LTO enabled, hence inlining should occur across crates"
109+
echo "ERROR: call my_add found in asm"
110+
echo "Test is done with cross-language LTO enabled, hence inlining should occur across object files"
92111
exit 1
93112
fi
94113

tests/cross_lang_lto/Cargo.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 4
4+
5+
[[package]]
6+
name = "cross_lang_lto"
7+
version = "0.1.0"

tests/cross_lang_lto/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "cross_lang_lto"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]

tests/cross_lang_lto/add.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdint.h>
2+
3+
uint32_t my_add(uint32_t a, uint32_t b) {
4+
return a + b;
5+
}

tests/cross_lang_lto/src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Compile the C code with:
3+
* gcc -c -flto add.c -ffat-lto-objects
4+
* ar rcs libadd.a add.o
5+
*
6+
* Compile the Rust code with:
7+
* EMBED_LTO_BITCODE=1 CG_RUSTFLAGS="-L native=. -Clinker-plugin-lto -Clinker=gcc" y cargo run --release
8+
*/
9+
10+
#[link(name="add")]
11+
unsafe extern "C" {
12+
fn wrong_my_add(a: u32, b: u32) -> u32;
13+
}
14+
15+
fn main() {
16+
let res = unsafe { wrong_my_add(30, 12) };
17+
println!("{}", res);
18+
}

0 commit comments

Comments
 (0)