Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTO flags are silently ignored if one the crate-type of the root package is not compatible with LTO #14612

Open
stormshield-kg opened this issue Sep 29, 2024 · 2 comments
Labels
A-lto Area: link-time optimization C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@stormshield-kg
Copy link

stormshield-kg commented Sep 29, 2024

Problem

Using the Cargo.toml below, LTO is not used for the staticlib target when building multiple library targets with cargo build --release.

To enable LTO, the lib target must be removed, or we must use cargo rustc --crate-type=staticlib for building separately.

Steps

  1. Cargo.toml:
[package]
name = "a"

[profile.release]
lto = true

[lib]
crate-type = ["lib", "staticlib"]
  1. Command

cargo build --release

Possible Solution(s)

Show a warning that LTO is disabled for the LTO-compatible targets, and suggest using cargo rustc --crate-type=X.

Version

cargo 1.81.0 (2dbb1af80 2024-08-20)
release: 1.81.0
commit-hash: 2dbb1af80a2914475ba76827a312e29cedfa6b2f
commit-date: 2024-08-20
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 20.4.0 (focal) [64-bit]
@stormshield-kg stormshield-kg added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Sep 29, 2024
@epage
Copy link
Contributor

epage commented Sep 30, 2024

We have this comment in the code though it lacks an explanation

// LTO can only be performed if *all* of the crate types support it.
// For example, a cdylib/rlib combination won't allow LTO.
let all_lto_types = crate_types.iter().all(CrateType::can_lto);

@epage
Copy link
Contributor

epage commented Sep 30, 2024

That code seemed to be added in #8349

@epage epage added the A-lto Area: link-time optimization label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lto Area: link-time optimization C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants