Skip to content

Commit d1fff4a

Browse files
committed
Auto merge of #66109 - pietroalbini:rollup-2npidna, r=pietroalbini
Rollup of 10 pull requests Successful merges: - #65136 (Update codegen option documentation.) - #65574 (docs: improve disclaimer regarding LinkedList) - #65720 (Add FFI bindings for LLVM's Module::getInstructionCount()) - #65905 ([doc] fixes for unix/vxworks `OpenOptionsExt::mode`) - #65962 (Fix logic in example.) - #66019 (Improved std::iter::Chain documentation) - #66038 (doc(str): show example of chars().count() under len()) - #66042 (Suggest correct code when encountering an incorrect trait bound referencing the current trait) - #66073 (Do not needlessly write-lock) - #66096 (Add a failing UI test for multiple loops of all kinds in a `const`) Failed merges: r? @ghost
2 parents 2e4da3c + 1ffa93e commit d1fff4a

File tree

19 files changed

+468
-94
lines changed

19 files changed

+468
-94
lines changed

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

+186-37
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ This option is deprecated and does nothing.
99

1010
## linker
1111

12-
This flag lets you control which linker `rustc` invokes to link your code.
12+
This flag lets you control which linker `rustc` invokes to link your code. It
13+
takes a path to the linker executable. If this flag is not specified, the
14+
linker will be inferred based on the target. See also the
15+
[linker-flavor](#linker-flavor) flag for another way to specify the linker.
1316

14-
## link-arg=val
17+
## link-arg
1518

1619
This flag lets you append a single extra argument to the linker invocation.
1720

@@ -25,9 +28,27 @@ options should be separated by spaces.
2528
## linker-flavor
2629

2730
This flag lets you control the linker flavor used by `rustc`. If a linker is given with the
28-
`-C linker` flag described above then the linker flavor is inferred from the value provided. If no
31+
[`-C linker` flag](#linker), then the linker flavor is inferred from the value provided. If no
2932
linker is given then the linker flavor is used to determine the linker to use. Every `rustc` target
30-
defaults to some linker flavor.
33+
defaults to some linker flavor. Valid options are:
34+
35+
* `em`: Uses [Emscripten `emcc`](https://emscripten.org/docs/tools_reference/emcc.html).
36+
* `gcc`: Uses the `cc` executable, which is typically gcc or clang on many systems.
37+
* `ld`: Uses the `ld` executable.
38+
* `msvc`: Uses the `link.exe` executable from Microsoft Visual Studio MSVC.
39+
* `ptx-linker`: Uses
40+
[`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker) for Nvidia
41+
NVPTX GPGPU support.
42+
* `wasm-ld`: Uses the [`wasm-ld`](https://lld.llvm.org/WebAssembly.html)
43+
executable, a port of LLVM `lld` for WebAssembly.
44+
* `ld64.lld`: Uses the LLVM `lld` executable with the [`-flavor darwin`
45+
flag][lld-flavor] for Apple's `ld`.
46+
* `ld.lld`: Uses the LLVM `lld` executable with the [`-flavor gnu`
47+
flag][lld-flavor] for GNU binutils' `ld`.
48+
* `lld-link`: Uses the LLVM `lld` executable with the [`-flavor link`
49+
flag][lld-flavor] for Microsoft's `link.exe`.
50+
51+
[lld-flavor]: https://lld.llvm.org/Driver.html
3152

3253
## link-dead-code
3354

@@ -39,42 +60,92 @@ metrics.
3960
## lto
4061

4162
This flag instructs LLVM to use [link time
42-
optimizations](https://llvm.org/docs/LinkTimeOptimization.html).
63+
optimizations](https://llvm.org/docs/LinkTimeOptimization.html) to produce
64+
better optimized code, using whole-program analysis, at the cost of longer
65+
linking time.
4366

44-
It takes one of two values, `thin` and `fat`. 'thin' LTO [is a new feature of
45-
LLVM](http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html),
46-
'fat' referring to the classic version of LTO.
67+
This flag may take one of the following values:
68+
69+
* `y`, `yes`, `on`, `fat`, or no value: Performs "fat" LTO which attempts to
70+
perform optimizations across all crates within the dependency graph.
71+
* `n`, `no`, `off`: Disables LTO.
72+
* `thin`: Performs ["thin"
73+
LTO](http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html).
74+
This is similar to "fat", but takes substantially less time to run while
75+
still achieving performance gains similar to "fat".
76+
77+
If `-C lto` is not specified, then the compiler will attempt to perform "thin
78+
local LTO" which performs "thin" LTO on the local crate only across its
79+
[codegen units](#codegen-units). When `-C lto` is not specified, LTO is
80+
disabled if codegen units is 1 or optimizations are disabled ([`-C
81+
opt-level=0`](#opt-level)). That is:
82+
83+
* When `-C lto` is not specified:
84+
* `codegen-units=1`: Disables LTO.
85+
* `opt-level=0`: Disables LTO.
86+
* When `-C lto=true`:
87+
* `lto=true`: 16 codegen units, performs fat LTO across crates.
88+
* `codegen-units=1` + `lto=true`: 1 codegen unit, fat LTO across crates.
89+
90+
See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO.
91+
92+
## linker-plugin-lto
93+
94+
Defers LTO optimizations to the linker. See
95+
[linkger-plugin-LTO](../linker-plugin-lto.md) for more details. Takes one of
96+
the following values:
97+
98+
* `y`, `yes`, `on`, or no value: Enabled.
99+
* `n`, `no`, or `off`: Disabled (default).
100+
* A path to the linker plugin.
47101

48102
## target-cpu
49103

50104
This instructs `rustc` to generate code specifically for a particular processor.
51105

52106
You can run `rustc --print target-cpus` to see the valid options to pass
53107
here. Additionally, `native` can be passed to use the processor of the host
54-
machine.
108+
machine. Each target has a default base CPU.
55109

56110
## target-feature
57111

58112
Individual targets will support different features; this flag lets you control
59-
enabling or disabling a feature.
113+
enabling or disabling a feature. Each feature should be prefixed with a `+` to
114+
enable it or `-` to disable it. Separate multiple features with commas.
60115

61116
To see the valid options and an example of use, run `rustc --print
62117
target-features`.
63118

64-
Using this flag is unsafe and might result in [undefined runtime behavior](../targets/known-issues.md).
119+
Using this flag is unsafe and might result in [undefined runtime
120+
behavior](../targets/known-issues.md).
121+
122+
See also the [`target_feature`
123+
attribute](../../reference/attributes/codegen.md#the-target_feature-attribute)
124+
for controlling features per-function.
125+
126+
This also supports the feature `+crt-static` and `-crt-static` to control
127+
[static C runtime linkage](../../reference/linkage.html#static-and-dynamic-c-runtimes).
128+
129+
Each target and [`target-cpu`](#target-cpu) has a default set of enabled
130+
features.
65131

66132
## passes
67133

68-
This flag can be used to add extra LLVM passes to the compilation.
134+
This flag can be used to add extra [LLVM
135+
passes](http://llvm.org/docs/Passes.html) to the compilation.
69136

70137
The list must be separated by spaces.
71138

139+
See also the [`no-prepopulate-passes`](#no-prepopulate-passes) flag.
140+
72141
## llvm-args
73142

74143
This flag can be used to pass a list of arguments directly to LLVM.
75144

76145
The list must be separated by spaces.
77146

147+
Pass `--help` to see a list of options.
148+
78149
## save-temps
79150

80151
`rustc` will generate temporary files during compilation; normally it will
@@ -83,16 +154,21 @@ preserved instead of removed.
83154

84155
## rpath
85156

86-
This option allows you to set the value of
157+
This option allows you to enable
87158
[`rpath`](https://en.wikipedia.org/wiki/Rpath).
88159

89160
## overflow-checks
90161

91-
This flag allows you to control the behavior of integer overflow. This flag
92-
can be passed many options:
162+
This flag allows you to control the behavior of [runtime integer
163+
overflow](../../reference/expressions/operator-expr.md#overflow). When
164+
overflow-checks are enabled, a panic will occur on overflow. This flag takes
165+
one of the following values:
93166

94-
* To turn overflow checks on: `y`, `yes`, or `on`.
95-
* To turn overflow checks off: `n`, `no`, or `off`.
167+
* `y`, `yes`, `on`, or no value: Enable overflow checks.
168+
* `n`, `no`, or `off`: Disable overflow checks.
169+
170+
If not specified, overflow checks are enabled if
171+
[debug-assertions](#debug-assertions) are enabled, disabled otherwise.
96172

97173
## no-prepopulate-passes
98174

@@ -125,49 +201,65 @@ make it use dynamic linking instead.
125201

126202
## no-integrated-as
127203

128-
LLVM comes with an internal assembler; this option will let you use an
129-
external assembler instead.
204+
`rustc` normally uses the LLVM internal assembler to create object code. This
205+
flag will disable the internal assembler and emit assembly code to be
206+
translated using an external assembler, currently the linker such as `cc`.
130207

131208
## no-redzone
132209

133210
This flag allows you to disable [the
134211
red zone](https://en.wikipedia.org/wiki/Red_zone_\(computing\)). This flag can
135-
be passed many options:
212+
be passed one of the following options:
213+
214+
* `y`, `yes`, `on`, or no value: Disables the red zone.
215+
* `n`, `no`, or `off`: Enables the red zone.
136216

137-
* To enable the red zone: `y`, `yes`, or `on`.
138-
* To disable it: `n`, `no`, or `off`.
217+
The default if not specified depends on the target.
139218

140219
## relocation-model
141220

142-
This option lets you choose which relocation model to use.
221+
This option lets you choose which
222+
[relocation](https://en.wikipedia.org/wiki/Relocation_\(computing\)) model to
223+
use.
143224

144225
To find the valid options for this flag, run `rustc --print relocation-models`.
145226

146-
## code-model=val
227+
## code-model
147228

148229
This option lets you choose which code model to use.
149230

150231
To find the valid options for this flag, run `rustc --print code-models`.
151232

152233
## metadata
153234

154-
This option allows you to control the metadata used for symbol mangling.
235+
This option allows you to control the metadata used for symbol mangling. This
236+
takes a space-separated list of strings. Mangled symbols will incorporate a
237+
hash of the metadata. This may be used, for example, to differentiate symbols
238+
between two different versions of the same crate being linked.
155239

156240
## extra-filename
157241

158-
This option allows you to put extra data in each output filename.
242+
This option allows you to put extra data in each output filename. It takes a
243+
string to add as a suffix to the filename. See the [`--emit`
244+
flag][option-emit] for more information.
159245

160246
## codegen-units
161247

162-
This flag lets you control how many threads are used when doing
163-
code generation.
248+
This flag controls how many code generation units the crate is split into. It
249+
takes an integer greater than 0.
164250

165-
Increasing parallelism may speed up compile times, but may also
166-
produce slower code.
251+
When a crate is split into multiple codegen units, LLVM is able to process
252+
them in parallel. Increasing parallelism may speed up compile times, but may
253+
also produce slower code. Setting this to 1 may improve the performance of
254+
generated code, but may be slower to compile.
255+
256+
The default, if not specified, is 16. This flag is ignored if
257+
[incremental](#incremental) is enabled, in which case an internal heuristic is
258+
used to split the crate.
167259

168260
## remark
169261

170-
This flag lets you print remarks for these optimization passes.
262+
This flag lets you print remarks for optimization passes.
171263

172264
The list of passes should be separated by spaces.
173265

@@ -181,30 +273,55 @@ This option is deprecated and does nothing.
181273

182274
This flag lets you control debug information:
183275

184-
* `0`: no debug info at all
276+
* `0`: no debug info at all (default)
185277
* `1`: line tables only
186278
* `2`: full debug info
187279

280+
Note: The [`-g` flag][option-g-debug] is an alias for `-C debuginfo=2`.
281+
188282
## opt-level
189283

190284
This flag lets you control the optimization level.
191285

192-
* `0`: no optimizations, also turn on `cfg(debug_assertions)`.
286+
* `0`: no optimizations, also turns on [`cfg(debug_assertions)`](#debug-assertions).
193287
* `1`: basic optimizations
194288
* `2`: some optimizations
195289
* `3`: all optimizations
196290
* `s`: optimize for binary size
197291
* `z`: optimize for binary size, but also turn off loop vectorization.
198292

293+
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`.
294+
295+
The default is `0`.
296+
199297
## debug-assertions
200298

201-
This flag lets you turn `cfg(debug_assertions)` on or off.
299+
This flag lets you turn `cfg(debug_assertions)` [conditional
300+
compilation](../../reference/conditional-compilation.md#debug_assertions) on
301+
or off. It takes one of the following values:
302+
303+
* `y`, `yes`, `on`, or no value: Enable debug-assertions.
304+
* `n`, `no`, or `off`: Disable debug-assertions.
305+
306+
If not specified, debug assertions are automatically enabled only if the
307+
[opt-level](#opt-level) is 0.
202308

203309
## inline-threshold
204310

205-
This option lets you set the threshold for inlining a function.
311+
This option lets you set the default threshold for inlining a function. It
312+
takes an unsigned integer as a value. Inlining is based on a cost model, where
313+
a higher threshold will allow more inlining.
206314

207-
The default is 225.
315+
The default depends on the [opt-level](#opt-level):
316+
317+
| opt-level | Threshold |
318+
|-----------|-----------|
319+
| 0 | N/A, only inlines always-inline functions |
320+
| 1 | N/A, only inlines always-inline functions and LLVM lifetime intrinsics |
321+
| 2 | 225 |
322+
| 3 | 275 |
323+
| s | 75 |
324+
| z | 25 |
208325

209326
## panic
210327

@@ -213,9 +330,14 @@ This option lets you control what happens when the code panics.
213330
* `abort`: terminate the process upon panic
214331
* `unwind`: unwind the stack upon panic
215332

333+
If not specified, the default depends on the target.
334+
216335
## incremental
217336

218-
This flag allows you to enable incremental compilation.
337+
This flag allows you to enable incremental compilation, which allows `rustc`
338+
to save information after compiling a crate to be reused when recompiling the
339+
crate, improving re-compile times. This takes a path to a directory where
340+
incremental files will be stored.
219341

220342
## profile-generate
221343

@@ -232,4 +354,31 @@ optimization (PGO). The flag takes a mandatory argument which is the path
232354
to a valid `.profdata` file. See the chapter on
233355
[profile-guided optimization] for more information.
234356

357+
## force-frame-pointers
358+
359+
This flag forces the use of frame pointers. It takes one of the following
360+
values:
361+
362+
* `y`, `yes`, `on`, or no value: Frame pointers are forced to be enabled.
363+
* `n`, `no`, or `off`: Frame pointers are not forced to be enabled. This does
364+
not necessarily mean frame pointers will be removed.
365+
366+
The default if not specified depends on the target.
367+
368+
## default-linker-libraries
369+
370+
This flag controls whether or not the linker includes its default libraries.
371+
It takes one of the following values:
372+
373+
* `y`, `yes`, `on`, or no value: Default libraries are included.
374+
* `n`, `no`, or `off`: Default libraries are **not** included.
375+
376+
For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to
377+
the linker.
378+
379+
The default is `yes` if not specified.
380+
381+
[option-emit]: ../command-line-arguments.md#option-emit
382+
[option-o-optimize]: ../command-line-arguments.md#option-o-optimize
235383
[profile-guided optimization]: ../profile-guided-optimization.md
384+
[option-g-debug]: ../command-line-arguments.md#option-g-debug

0 commit comments

Comments
 (0)