Skip to content

Rust does not perform cross language LTO for C functions forwarding to C++ #86745

Open
@Time0o

Description

@Time0o

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LTOArea: Link-time optimization (LTO)C-bugCategory: This is a bug.S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions