Skip to content

Improve documentation for codegen options #141554

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Noratrieb
Copy link
Member

This adds more information to many different codegen options. It should not add any new guarantees, just document existing behavior.

r? bjorn3

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 25, 2025
@@ -379,7 +396,7 @@ This flag controls the optimization level.
* `2`: some optimizations.
* `3`: all optimizations.
* `s`: optimize for binary size.
* `z`: optimize for binary size, but also turn off loop vectorization.
* `z`: optimize for binary size, but more aggressively. Often results in larger binaries than `s`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the description from https://llvm.org/doxygen/classllvm_1_1OptimizationLevel.html#a1e916712888d6a2d3952834c126460e7

The fact that it's often worse is based on experience

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd guess the old information was based on https://stackoverflow.com/questions/15548023/clang-optimization-levels
But that misses all the heuristics that are also affected by this flag, which are much more important (there's no way just not doing vectorization results in significantly bigger binaries)

@Noratrieb Noratrieb force-pushed the document-codegen-opts-better branch from 3290111 to d83495c Compare May 25, 2025 16:49
@rust-log-analyzer

This comment has been minimized.

@Noratrieb Noratrieb force-pushed the document-codegen-opts-better branch from d83495c to 2413eb4 Compare May 25, 2025 17:45
@rust-log-analyzer

This comment has been minimized.

This adds more information to many different codegen options. It should
not add any new guarantees, just document existing behavior.
@Noratrieb Noratrieb force-pushed the document-codegen-opts-better branch from 2413eb4 to 71b39e5 Compare May 25, 2025 18:43
@@ -407,6 +424,8 @@ This option lets you control what happens when the code panics.

If not specified, the default depends on the target.

If any crate in the crate graph uses `abort`, the final binary (`bin`, `dylib`, `cdylib`, `staticlib`) must also use `abort`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if libstd is used as dylib compiled with panic=unwind, the final binary must also use panic=unwind. (In that case libstd.so links against libpanic_unwind.rlib. rustc will emit an error when using panic=abort while linking libpanic_unwind.rlib)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants