Skip to content

Commit d83495c

Browse files
committed
Improve documentation for codegen options
This adds more information to many different codegen options. It should not add any new guarantees, just document existing behavior.
1 parent e88e854 commit d83495c

File tree

1 file changed

+46
-3
lines changed
  • src/doc/rustc/src/codegen-options

1 file changed

+46
-3
lines changed

src/doc/rustc/src/codegen-options/index.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ to save information after compiling a crate to be reused when recompiling the
192192
crate, improving re-compile times. This takes a path to a directory where
193193
incremental files will be stored.
194194

195+
Using incremental compilation inhibits certain optimizations (for example by increasing the amount of codegen units) and is therefore not recommend for release builds.
196+
195197
## inline-threshold
196198

197199
This option is deprecated and does nothing.
@@ -213,6 +215,8 @@ This flag lets you append a single extra argument to the linker invocation.
213215

214216
"Append" is significant; you can pass this flag multiple times to add multiple arguments.
215217

218+
On Unix-like targets that use `cc` as the linker driver, use `-Clink-arg=-Wl,$ARG` to pass an argument to the actual linker.
219+
216220
## link-args
217221

218222
This flag lets you append multiple extra arguments to the linker invocation. The
@@ -248,6 +252,10 @@ path to the linker executable. If this flag is not specified, the linker will
248252
be inferred based on the target. See also the [linker-flavor](#linker-flavor)
249253
flag for another way to specify the linker.
250254

255+
Note that on Unix-like targets (for example, `*-unknown-linux-gnu` or `*-unknown-freebsd`)
256+
the C compiler (for example `cc` or `clang`) is used as the "linker" here, serving as a linker driver.
257+
It will invoke the actual linker with all the necessary flags to be able to link against the system libraries like libc.
258+
251259
## linker-flavor
252260

253261
This flag controls the linker flavor used by `rustc`. If a linker is given with
@@ -301,6 +309,12 @@ The list must be separated by spaces.
301309

302310
Pass `--help` to see a list of options.
303311

312+
<div class="warning">
313+
314+
Because this flag directly talks to LLVM, it is not subject to the usual stability guarantees of rustc's CLI interface.
315+
316+
</div>
317+
304318
## lto
305319

306320
This flag controls whether LLVM uses [link time
@@ -315,6 +329,7 @@ linking time. It takes one of the following values:
315329
LTO](http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html).
316330
This is similar to "fat", but takes substantially less time to run while
317331
still achieving performance gains similar to "fat".
332+
For larger projects like the Rust compiler, ThinLTO can even result in better performance than fat LTO.
318333

319334
If `-C lto` is not specified, then the compiler will attempt to perform "thin
320335
local LTO" which performs "thin" LTO on the local crate only across its
@@ -343,6 +358,8 @@ between two different versions of the same crate being linked.
343358
This flag tells the pass manager to use an empty list of passes, instead of the
344359
usual pre-populated list of passes.
345360

361+
When combined with `-O --emit llvm-ir`, it can be used to see the optimized LLVM IR emitted by rustc before any optimizations are applied by LLVM.
362+
346363
## no-redzone
347364

348365
This flag allows you to disable [the
@@ -379,7 +396,7 @@ This flag controls the optimization level.
379396
* `2`: some optimizations.
380397
* `3`: all optimizations.
381398
* `s`: optimize for binary size.
382-
* `z`: optimize for binary size, but also turn off loop vectorization.
399+
* `z`: optimize for binary size, but more aggressively. Often results in larger binaries than `s`
383400

384401
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=3`.
385402

@@ -407,6 +424,8 @@ This option lets you control what happens when the code panics.
407424

408425
If not specified, the default depends on the target.
409426

427+
If any crate in the crate graph uses `abort`, the final binary (`bin`, `dylib`, `cdylib`, `staticlib`) must also use `abort`.
428+
410429
## passes
411430

412431
This flag can be used to add extra [LLVM
@@ -416,6 +435,12 @@ The list must be separated by spaces.
416435

417436
See also the [`no-prepopulate-passes`](#no-prepopulate-passes) flag.
418437

438+
<div class="warning">
439+
440+
Because this flag directly talks to LLVM, it not subject to the usual stability guarantees of rustc's CLI interface.
441+
442+
</div>
443+
419444
## prefer-dynamic
420445

421446
By default, `rustc` prefers to statically link dependencies. This option will
@@ -523,12 +548,28 @@ The list of passes should be separated by spaces.
523548

524549
## rpath
525550

526-
This flag controls whether [`rpath`](https://en.wikipedia.org/wiki/Rpath) is
527-
enabled. It takes one of the following values:
551+
This flag controls whether rustc sets an [`rpath`](https://en.wikipedia.org/wiki/Rpath) for the binary.
552+
It takes one of the following values:
528553

529554
* `y`, `yes`, `on`, `true` or no value: enable rpath.
530555
* `n`, `no`, `off` or `false`: disable rpath (the default).
531556

557+
If enabled, rustc will add output-relative (using `@load_path` on Apple and `$ORIGIN` on ELF respectively) rpaths to all `dylib` dependencies.
558+
559+
For example, for the following directory structure, with `libdep.so` being a `dylib` crate compiled with `-Cprefer-dynamic`:
560+
561+
```
562+
dep
563+
|- libdep.so
564+
a.rs
565+
```
566+
567+
`rustc a.rs --extern dep=dep/libdep.so -Crpath` will, on x86-64 Linux, result in approximately the following `DT_RUNPATH`: `$ORIGIN/dep:$ORIGIN/$RELATIVE_PATH_TO_SYSROOT/lib/rustlib/x86_64-unknown-linux-gnu/lib` (where `RELATIVE_PATH_TO_SYSROOT` depends on the build directory location).
568+
569+
This is primarily useful for local development, to ensure that all the `dylib` dependencies can be found appropriately.
570+
571+
To set the rpath to a different value (which can be useful for distribution), `-Clink-arg` with a platform-specific linker argument can be used to set the rpath directly.
572+
532573
## save-temps
533574

534575
This flag controls whether temporary files generated during compilation are
@@ -545,6 +586,8 @@ point instructions in software. It takes one of the following values:
545586
* `y`, `yes`, `on`, `true` or no value: use soft floats.
546587
* `n`, `no`, `off` or `false`: use hardware floats (the default).
547588

589+
This flag only works on `*eabihf` targets and **is unsound and deprecated**.
590+
548591
## split-debuginfo
549592

550593
This option controls the emission of "split debuginfo" for debug information

0 commit comments

Comments
 (0)