Skip to content

#![no_builtins] should prevent a crate from participating in LTO #35540

Closed
@Amanieu

Description

@Amanieu

This attribute is needed to prevent LLVM from optimizing a memcpy implementation into a recursive call. However this attribute is not preserved in LTO builds: the attribute only works if it is set at the top-level crate.

Since crates containing implementations of built-in functions aren't meant to be called directly, they don't benefit from LTO and should be linked as a separate object.

One workaround (using rlibc as an example) is to first compile a rlibc_inner crate as a staticlib with #![no_builtins], and then compile the rlibc crate as a rlib which links to rlibc_inner.a.

cc #31544 @alexcrichton @japaric

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions