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