-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
I believe that cross language LTO does not work correctly when calling C++ code from Rust via intermediate C functions.
Consider this example, here a C++ function foo::do_something
(defined in cc/foo_cc.h
) is wrapped in a C function foo_do_something
(declared in c/foo_c.h
) which is then called from Rust via its FFI (in rust/foo_main.rs
).
For reference, when linking the static library libfoo_c.a
that exposes foo_do_something
to a binary created from another C file (c/foo_main.c
), a call to foo_do_something
is correctly reduced to a call to foo::do_something
in the resulting machine code. However, this is not the case for the binary created by rustc
, here the main function first jumps to foo_do_something
which then does nothing but to jump to foo::do_something
.
I've tested this with rustc 1.53.0
and clang 12.0.0
Activity
michaelwoerister commentedon Jul 5, 2021
Thanks for the bug report, @Time0o! It would be helpful if you could provide the LLVM IR files for all files involved. The Rust compiler can generate those via
--emit llvm-ir
.HKalbasi commentedon May 23, 2025
Might be related to llvm/llvm-project#141038