Skip to content

Commit f3e8c2e

Browse files
committed
Update codegen option documentation.
1 parent 8318ef2 commit f3e8c2e

File tree

2 files changed

+235
-68
lines changed

2 files changed

+235
-68
lines changed

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

+167-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,84 @@ 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 it will attempt to perform "thin local LTO"
78+
which performs "thin" LTO on the local crate only across its [codegen
79+
units](#codegen-units). In this case, LTO is disabled if codegen units is 1 or
80+
optimizations are disabled ([`-C opt-level=0`](#opt-level)).
81+
82+
See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO.
83+
84+
## linker-plugin-lto
85+
86+
Defers LTO optimizations to the linker. See
87+
[linkger-plugin-LTO](../linker-plugin-lto.md) for more details. Takes one of
88+
the following values:
89+
90+
* `y`, `yes`, `on`, or no value: Enabled.
91+
* `n`, `no`, or `off`: Disabled (default).
92+
* A path to the linker plugin.
4793

4894
## target-cpu
4995

5096
This instructs `rustc` to generate code specifically for a particular processor.
5197

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

56102
## target-feature
57103

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

61108
To see the valid options and an example of use, run `rustc --print
62109
target-features`.
63110

64-
Using this flag is unsafe and might result in [undefined runtime behavior](../targets/known-issues.md).
111+
Using this flag is unsafe and might result in [undefined runtime
112+
behavior](../targets/known-issues.md).
113+
114+
See also the [`target_feature`
115+
attribute](../../reference/attributes/codegen.md#the-target_feature-attribute)
116+
for controlling features per-function.
117+
118+
This also supports the feature `+crt-static` and `-crt-static` to control
119+
[static C runtime linkage](../../reference/linkage.html#static-and-dynamic-c-runtimes).
120+
121+
Each target and [`target-cpu`](#target-cpu) has a default set of enabled
122+
features.
65123

66124
## passes
67125

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

70129
The list must be separated by spaces.
71130

131+
See also the [`no-prepopulate-passes`](#no-prepopulate-passes) flag.
132+
72133
## llvm-args
73134

74135
This flag can be used to pass a list of arguments directly to LLVM.
75136

76137
The list must be separated by spaces.
77138

139+
Pass `--help` to see a list of options.
140+
78141
## save-temps
79142

80143
`rustc` will generate temporary files during compilation; normally it will
@@ -83,16 +146,21 @@ preserved instead of removed.
83146

84147
## rpath
85148

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

89152
## overflow-checks
90153

91-
This flag allows you to control the behavior of integer overflow. This flag
92-
can be passed many options:
154+
This flag allows you to control the behavior of [runtime integer
155+
overflow](../../reference/expressions/operator-expr.md#overflow). When
156+
overflow-checks are enabled, a panic will occur on overflow. This flag takes
157+
one of the following values:
158+
159+
* `y`, `yes`, `on`, or no value: Enable overflow checks.
160+
* `n`, `no`, or `off`: Disable overflow checks.
93161

94-
* To turn overflow checks on: `y`, `yes`, or `on`.
95-
* To turn overflow checks off: `n`, `no`, or `off`.
162+
If not specified, overflow checks are enabled if
163+
[debug-assertions](#debug-assertions) are enabled, disabled otherwise.
96164

97165
## no-prepopulate-passes
98166

@@ -125,49 +193,62 @@ make it use dynamic linking instead.
125193

126194
## no-integrated-as
127195

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

131200
## no-redzone
132201

133202
This flag allows you to disable [the
134203
red zone](https://en.wikipedia.org/wiki/Red_zone_\(computing\)). This flag can
135-
be passed many options:
204+
be passed one of the following options:
136205

137-
* To enable the red zone: `y`, `yes`, or `on`.
138-
* To disable it: `n`, `no`, or `off`.
206+
* `y`, `yes`, `on`, or no value: Disables the red zone.
207+
* `n`, `no`, or `off`: Enables the red zone.
208+
209+
The default if not specified depends on the target.
139210

140211
## relocation-model
141212

142-
This option lets you choose which relocation model to use.
213+
This option lets you choose which
214+
[relocation](https://en.wikipedia.org/wiki/Relocation_\(computing\)) model to
215+
use.
143216

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

146-
## code-model=val
219+
## code-model
147220

148221
This option lets you choose which code model to use.
149222

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

152225
## metadata
153226

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

156232
## extra-filename
157233

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

160238
## codegen-units
161239

162-
This flag lets you control how many threads are used when doing
163-
code generation.
240+
This flag lets you control how many threads are used when doing code
241+
generation. It takes an integer greater than 0.
242+
243+
Increasing parallelism may speed up compile times, but may also produce slower
244+
code. Setting this to 1 may improve the performance of generated code, but may
245+
be slower to compile.
164246

165-
Increasing parallelism may speed up compile times, but may also
166-
produce slower code.
247+
The default if not specified is 16.
167248

168249
## remark
169250

170-
This flag lets you print remarks for these optimization passes.
251+
This flag lets you print remarks for optimization passes.
171252

172253
The list of passes should be separated by spaces.
173254

@@ -181,30 +262,47 @@ This option is deprecated and does nothing.
181262

182263
This flag lets you control debug information:
183264

184-
* `0`: no debug info at all
265+
* `0`: no debug info at all (default)
185266
* `1`: line tables only
186267
* `2`: full debug info
187268

269+
Note: The [`-g` flag][option-g-debug] is an alias for `-C debuginfo=2`.
270+
188271
## opt-level
189272

190273
This flag lets you control the optimization level.
191274

192-
* `0`: no optimizations, also turn on `cfg(debug_assertions)`.
275+
* `0`: no optimizations, also turn on [`cfg(debug_assertions)`](#debug-assertions).
193276
* `1`: basic optimizations
194277
* `2`: some optimizations
195278
* `3`: all optimizations
196279
* `s`: optimize for binary size
197280
* `z`: optimize for binary size, but also turn off loop vectorization.
198281

282+
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`.
283+
284+
The default is `0`.
285+
199286
## debug-assertions
200287

201-
This flag lets you turn `cfg(debug_assertions)` on or off.
288+
This flag lets you turn `cfg(debug_assertions)` [conditional
289+
compilation](../../reference/conditional-compilation.md#debug_assertions) on
290+
or off. It takes one of the following values:
291+
292+
* `y`, `yes`, `on`, or no value: Enable debug-assertions.
293+
* `n`, `no`, or `off`: Disable debug-assertions.
294+
295+
If not specified, debug assertions are enabled only if the
296+
[opt-level](#opt-level) is 0.
202297

203298
## inline-threshold
204299

205-
This option lets you set the threshold for inlining a function.
300+
This option lets you set the threshold for inlining a function. It takes a
301+
positive integer as a value. Inlining is based on a cost model, where a higher
302+
threshold will allow more inlining.
206303

207-
The default is 225.
304+
The default depends on the [opt-level](#opt-level). Current values are between
305+
25 to 275.
208306

209307
## panic
210308

@@ -213,9 +311,14 @@ This option lets you control what happens when the code panics.
213311
* `abort`: terminate the process upon panic
214312
* `unwind`: unwind the stack upon panic
215313

314+
If not specified, the default depends on the target.
315+
216316
## incremental
217317

218-
This flag allows you to enable incremental compilation.
318+
This flag allows you to enable incremental compilation, which allows `rustc`
319+
to save information after compiling a crate to be reused when recompiling the
320+
crate, improving re-compile times. This takes a path to a directory where
321+
incremental files will be stored.
219322

220323
## profile-generate
221324

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

338+
## force-frame-pointers
339+
340+
This flag forces the use of frame pointers. It takes one of the following
341+
values:
342+
343+
* `y`, `yes`, `on`, or no value: Frame pointers are forced to be enabled.
344+
* `n`, `no`, or `off`: Frame pointers are not forced to be enabled. This does
345+
not necessarily mean frame pointers will be removed.
346+
347+
The default if not specified depends on the target.
348+
349+
## default-linker-libraries
350+
351+
This flag controls whether or not the linker includes its default libraries.
352+
It takes one of the following values:
353+
354+
* `y`, `yes`, `on`, or no value: Default libraries are included.
355+
* `n`, `no`, or `off`: Default libraries are **not** included.
356+
357+
For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to
358+
the linker.
359+
360+
The default is `yes` if not specified.
361+
362+
[option-emit]: ../command-line-arguments.md#option-emit
363+
[option-o-optimize]: ../command-line-arguments.md#option-o-optimize
235364
[profile-guided optimization]: ../profile-guided-optimization.md
365+
[option-g-debug]: ../command-line-arguments.md#option-g-debug

0 commit comments

Comments
 (0)