Skip to content

kpp/xlanglto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This project shows how to inline a call to C function from Rust.

HOWTO

Build with cargo:

CC=clang-9 RUSTFLAGS="-Clinker-plugin-lto -Clinker=clang-9 -Clink-arg=-fuse-ld=lld-9" cargo build --release
# binary: ./target/release/xlanglto

Or build without cargo:

clang-9 mul.c -flto=thin -c -O2
ar crs libmul.a mul.o
rustc -Clinker-plugin-lto -L. -Copt-level=2 -Clinker=clang-9 -Clink-arg=-fuse-ld=lld-9 src/main.rs -o xlanglto
# binary: ./xlanglto

Result

Cross-language LTO will result in an inline call to C function:

$ objdump -d ./target/release/xlanglto | grep "<multiply>:" -A3
000000000002eda0 <multiply>:
   2eda0:	89 f8                	mov    %edi,%eax
   2eda2:	0f af c6             	imul   %esi,%eax
   2eda5:	c3                   	retq

Dependencies

  • clang-9
  • lld-9
  • rustc 1.42.0

About

Using cross-language LTO in Rust project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published