Skip to content

Build failure when using LTO with static linking #129888

@burtonageo

Description

@burtonageo
Contributor

I have been experimenting with building crates as cdylibs/staticlibs out of tree as a workaround for emulating cargo artefacts
on stable rust. I have created a repository with an example of this here. To minimally reproduce the error, run:

git clone --depth 1 https://github.com/burtonageo/rational_test_app
cd rational_test_app
cargo build --release

When building with static linking and LTO, I get the following error:

error: failed to get bitcode from object file for LTO (could not find requested section)

I have configured the release profile to use lto. When building with dynamic linking and LTO, or static linking
without LTO, the build succeeds. This can be reproduced with either lto = "thin" or lto = true. To reproduce
the error, run cargo build --release. To disable static linking, use the --no-default-features flag.

Meta

rustc --version --verbose:

cargo 1.80.1 (376290515 2024-07-16)
release: 1.80.1
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.7.1 (sys:0.4.72+curl-8.6.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.6.1 [64-bit]

This issue is also seen on nightly:

rustc +nightly --version --verbose:

cargo 1.82.0-nightly (8f40fc59f 2024-08-21)
release: 1.82.0-nightly
commit-hash: 8f40fc59fb0c8df91c97405785197f3c630304ea
commit-date: 2024-08-21
host: aarch64-apple-darwin
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.7.1 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.6.1 [64-bit]

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 2, 2024
added
O-macosOperating system: macOS
A-LTOArea: Link-time optimization (LTO)
A-linkageArea: linking into static, shared libraries and binaries
on Sep 2, 2024
madsmtm

madsmtm commented on Sep 5, 2024

@madsmtm
Contributor

This does not seem to be specific to macOS, I got the same result using, for example, --target=x86_64-unknown-redox.

@rustbot label -O-macos

changed the title [-]Build failure when using LTO with static linking on MacOS[/-] [+]Build failure when using LTO with static linking[/+] on Sep 5, 2024
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Oct 10, 2024
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 12, 2024
zamazan4ik

zamazan4ik commented on Nov 30, 2024

@zamazan4ik
Contributor

Met the same problem for ppc64le target in Maturin: PyO3/maturin#2337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LTOArea: Link-time optimization (LTO)A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @burtonageo@zamazan4ik@madsmtm@saethlin@jieyouxu

        Issue actions

          Build failure when using LTO with static linking · Issue #129888 · rust-lang/rust