-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Cross-language inlining with LTO #45865
Copy link
Copy link
Closed
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Metadata
Metadata
Assignees
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I link against a C library with a very small function, and I would like its code to be inlined in the Rust function that calls it. I had hoped that it would be possible by setting
lto = trueinCargo.toml, but there is still a call in the final executable. This comment confirms that at the moment there is no LTO between Rust and C.I remember seeing an issue comment here that explained how to do it manually by emitting LLVM IR with
rustcandclangand linking it together withllvm-link, thenopt, but I cannot seem to find it any more.The call overhead can be substantial. For my current use case that calls a C function in an inner loop, it causes the running time to be 9 times as long as the equivalent program where the function is inlined. (It relies on a number of unstable features to be able to express the function in Rust.)
So for “efficient C bindings”, LTO that can inline across C and Rust objects would be nice to have.