You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/doc/rustc/src/codegen-options/index.md
+46-3Lines changed: 46 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -192,6 +192,8 @@ to save information after compiling a crate to be reused when recompiling the
192
192
crate, improving re-compile times. This takes a path to a directory where
193
193
incremental files will be stored.
194
194
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
+
195
197
## inline-threshold
196
198
197
199
This option is deprecated and does nothing.
@@ -213,6 +215,8 @@ This flag lets you append a single extra argument to the linker invocation.
213
215
214
216
"Append" is significant; you can pass this flag multiple times to add multiple arguments.
215
217
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
+
216
220
## link-args
217
221
218
222
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
248
252
be inferred based on the target. See also the [linker-flavor](#linker-flavor)
249
253
flag for another way to specify the linker.
250
254
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
+
251
259
## linker-flavor
252
260
253
261
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.
301
309
302
310
Pass `--help` to see a list of options.
303
311
312
+
<divclass="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
+
304
318
## lto
305
319
306
320
This flag controls whether LLVM uses [link time
@@ -315,6 +329,7 @@ linking time. It takes one of the following values:
This is similar to "fat", but takes substantially less time to run while
317
331
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.
318
333
319
334
If `-C lto` is not specified, then the compiler will attempt to perform "thin
320
335
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.
343
358
This flag tells the pass manager to use an empty list of passes, instead of the
344
359
usual pre-populated list of passes.
345
360
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
+
346
363
## no-redzone
347
364
348
365
This flag allows you to disable [the
@@ -379,7 +396,7 @@ This flag controls the optimization level.
379
396
*`2`: some optimizations.
380
397
*`3`: all optimizations.
381
398
*`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`
383
400
384
401
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=3`.
385
402
@@ -407,6 +424,8 @@ This option lets you control what happens when the code panics.
407
424
408
425
If not specified, the default depends on the target.
409
426
427
+
If any crate in the crate graph uses `abort`, the final binary (`bin`, `dylib`, `cdylib`, `staticlib`) must also use `abort`.
428
+
410
429
## passes
411
430
412
431
This flag can be used to add extra [LLVM
@@ -416,6 +435,12 @@ The list must be separated by spaces.
416
435
417
436
See also the [`no-prepopulate-passes`](#no-prepopulate-passes) flag.
418
437
438
+
<divclass="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
+
419
444
## prefer-dynamic
420
445
421
446
By default, `rustc` prefers to statically link dependencies. This option will
@@ -523,12 +548,28 @@ The list of passes should be separated by spaces.
523
548
524
549
## rpath
525
550
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:
528
553
529
554
*`y`, `yes`, `on`, `true` or no value: enable rpath.
530
555
*`n`, `no`, `off` or `false`: disable rpath (the default).
531
556
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
+
532
573
## save-temps
533
574
534
575
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:
545
586
*`y`, `yes`, `on`, `true` or no value: use soft floats.
546
587
*`n`, `no`, `off` or `false`: use hardware floats (the default).
547
588
589
+
This flag only works on `*eabihf` targets and **is unsound and deprecated**.
590
+
548
591
## split-debuginfo
549
592
550
593
This option controls the emission of "split debuginfo" for debug information
0 commit comments