]> git.lizzy.rs Git - rust.git/blob - src/doc/rustc/src/codegen-options/index.md
a503679f19bf74e039cbecb0b82ee6dd1b95bb87
[rust.git] / src / doc / rustc / src / codegen-options / index.md
1 # Codegen options
2
3 All of these options are passed to `rustc` via the `-C` flag, short for "codegen." You can see
4 a version of this list for your exact compiler by running `rustc -C help`.
5
6 ## ar
7
8 This option is deprecated and does nothing.
9
10 ## code-model
11
12 This option lets you choose which code model to use.
13
14 To find the valid options for this flag, run `rustc --print code-models`.
15
16 ## codegen-units
17
18 This flag controls how many code generation units the crate is split into. It
19 takes an integer greater than 0.
20
21 When a crate is split into multiple codegen units, LLVM is able to process
22 them in parallel. Increasing parallelism may speed up compile times, but may
23 also produce slower code. Setting this to 1 may improve the performance of
24 generated code, but may be slower to compile.
25
26 The default value, if not specified, is 16 for non-incremental builds. For
27 incremental builds the default is 256 which allows caching to be more granular.
28
29 ## debug-assertions
30
31 This flag lets you turn `cfg(debug_assertions)` [conditional
32 compilation](../../reference/conditional-compilation.md#debug_assertions) on
33 or off. It takes one of the following values:
34
35 * `y`, `yes`, `on`, or no value: enable debug-assertions.
36 * `n`, `no`, or `off`: disable debug-assertions.
37
38 If not specified, debug assertions are automatically enabled only if the
39 [opt-level](#opt-level) is 0.
40
41 ## debuginfo
42
43 This flag controls the generation of debug information. It takes one of the
44 following values:
45
46 * `0`: no debug info at all (the default).
47 * `1`: line tables only.
48 * `2`: full debug info.
49
50 Note: The [`-g` flag][option-g-debug] is an alias for `-C debuginfo=2`.
51
52 ## default-linker-libraries
53
54 This flag controls whether or not the linker includes its default libraries.
55 It takes one of the following values:
56
57 * `y`, `yes`, `on`, or no value: include default libraries (the default).
58 * `n`, `no`, or `off`: exclude default libraries.
59
60 For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to
61 the linker.
62
63 ## extra-filename
64
65 This option allows you to put extra data in each output filename. It takes a
66 string to add as a suffix to the filename. See the [`--emit`
67 flag][option-emit] for more information.
68
69 ## force-frame-pointers
70
71 This flag forces the use of frame pointers. It takes one of the following
72 values:
73
74 * `y`, `yes`, `on`, or no value: force-enable frame pointers.
75 * `n`, `no`, or `off`: do not force-enable frame pointers. This does
76   not necessarily mean frame pointers will be removed.
77
78 The default behaviour, if frame pointers are not force-enabled, depends on the
79 target.
80
81 ## incremental
82
83 This flag allows you to enable incremental compilation, which allows `rustc`
84 to save information after compiling a crate to be reused when recompiling the
85 crate, improving re-compile times. This takes a path to a directory where
86 incremental files will be stored.
87
88 ## inline-threshold
89
90 This option lets you set the default threshold for inlining a function. It
91 takes an unsigned integer as a value. Inlining is based on a cost model, where
92 a higher threshold will allow more inlining.
93
94 The default depends on the [opt-level](#opt-level):
95
96 | opt-level | Threshold |
97 |-----------|-----------|
98 | 0         | N/A, only inlines always-inline functions |
99 | 1         | N/A, only inlines always-inline functions and LLVM lifetime intrinsics |
100 | 2         | 225 |
101 | 3         | 275 |
102 | s         | 75 |
103 | z         | 25 |
104
105 ## link-arg
106
107 This flag lets you append a single extra argument to the linker invocation.
108
109 "Append" is significant; you can pass this flag multiple times to add multiple arguments.
110
111 ## link-args
112
113 This flag lets you append multiple extra arguments to the linker invocation. The
114 options should be separated by spaces.
115
116 ## link-dead-code
117
118 This flag controls whether the linker will keep dead code. It takes one of
119 the following values:
120
121 * `y`, `yes`, `on`, or no value: keep dead code.
122 * `n`, `no`, or `off`: remove dead code (the default).
123
124 An example of when this flag might be useful is when trying to construct code coverage
125 metrics.
126
127 ## linker
128
129 This flag controls which linker `rustc` invokes to link your code. It takes a
130 path to the linker executable. If this flag is not specified, the linker will
131 be inferred based on the target. See also the [linker-flavor](#linker-flavor)
132 flag for another way to specify the linker.
133
134 ## linker-flavor
135
136 This flag controls the linker flavor used by `rustc`. If a linker is given with
137 the [`-C linker` flag](#linker), then the linker flavor is inferred from the
138 value provided. If no linker is given then the linker flavor is used to
139 determine the linker to use. Every `rustc` target defaults to some linker
140 flavor. Valid options are:
141
142 * `em`: use [Emscripten `emcc`](https://emscripten.org/docs/tools_reference/emcc.html).
143 * `gcc`: use the `cc` executable, which is typically gcc or clang on many systems.
144 * `ld`: use the `ld` executable.
145 * `msvc`: use the `link.exe` executable from Microsoft Visual Studio MSVC.
146 * `ptx-linker`: use
147   [`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker) for Nvidia
148   NVPTX GPGPU support.
149 * `wasm-ld`: use the [`wasm-ld`](https://lld.llvm.org/WebAssembly.html)
150   executable, a port of LLVM `lld` for WebAssembly.
151 * `ld64.lld`: use the LLVM `lld` executable with the [`-flavor darwin`
152   flag][lld-flavor] for Apple's `ld`.
153 * `ld.lld`: use the LLVM `lld` executable with the [`-flavor gnu`
154   flag][lld-flavor] for GNU binutils' `ld`.
155 * `lld-link`: use the LLVM `lld` executable with the [`-flavor link`
156   flag][lld-flavor] for Microsoft's `link.exe`.
157
158 [lld-flavor]: https://lld.llvm.org/Driver.html
159
160 ## linker-plugin-lto
161
162 This flag defers LTO optimizations to the linker. See
163 [linker-plugin-LTO](../linker-plugin-lto.md) for more details. It takes one of
164 the following values:
165
166 * `y`, `yes`, `on`, or no value: enable linker plugin LTO.
167 * `n`, `no`, or `off`: disable linker plugin LTO (the default).
168 * A path to the linker plugin.
169
170 ## llvm-args
171
172 This flag can be used to pass a list of arguments directly to LLVM.
173
174 The list must be separated by spaces.
175
176 Pass `--help` to see a list of options.
177
178 ## lto
179
180 This flag controls whether LLVM uses [link time
181 optimizations](https://llvm.org/docs/LinkTimeOptimization.html) to produce
182 better optimized code, using whole-program analysis, at the cost of longer
183 linking time. It takes one of the following values:
184
185 * `y`, `yes`, `on`, `fat`, or no value: perform "fat" LTO which attempts to
186   perform optimizations across all crates within the dependency graph.
187 * `n`, `no`, `off`: disables LTO.
188 * `thin`: perform ["thin"
189   LTO](http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html).
190   This is similar to "fat", but takes substantially less time to run while
191   still achieving performance gains similar to "fat".
192
193 If `-C lto` is not specified, then the compiler will attempt to perform "thin
194 local LTO" which performs "thin" LTO on the local crate only across its
195 [codegen units](#codegen-units). When `-C lto` is not specified, LTO is
196 disabled if codegen units is 1 or optimizations are disabled ([`-C
197 opt-level=0`](#opt-level)). That is:
198
199 * When `-C lto` is not specified:
200   * `codegen-units=1`: disable LTO.
201   * `opt-level=0`: disable LTO.
202 * When `-C lto=true`:
203   * `lto=true`: 16 codegen units, perform fat LTO across crates.
204   * `codegen-units=1` + `lto=true`: 1 codegen unit, fat LTO across crates.
205
206 See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO.
207
208 ## metadata
209
210 This option allows you to control the metadata used for symbol mangling. This
211 takes a space-separated list of strings. Mangled symbols will incorporate a
212 hash of the metadata. This may be used, for example, to differentiate symbols
213 between two different versions of the same crate being linked.
214
215 ## no-prepopulate-passes
216
217 This flag tells the pass manager to use an empty list of passes, instead of the
218 usual pre-populated list of passes.
219
220 ## no-redzone
221
222 This flag allows you to disable [the
223 red zone](https://en.wikipedia.org/wiki/Red_zone_\(computing\)). It takes one
224 of the following values:
225
226 * `y`, `yes`, `on`, or no value: disable the red zone.
227 * `n`, `no`, or `off`: enable the red zone.
228
229 The default behaviour, if the flag is not specified, depends on the target.
230
231 ## no-stack-check
232
233 This option is deprecated and does nothing.
234
235 ## no-vectorize-loops
236
237 This flag disables [loop
238 vectorization](https://llvm.org/docs/Vectorizers.html#the-loop-vectorizer).
239
240 ## no-vectorize-slp
241
242 This flag disables vectorization using
243 [superword-level
244 parallelism](https://llvm.org/docs/Vectorizers.html#the-slp-vectorizer).
245
246 ## opt-level
247
248 This flag controls the optimization level.
249
250 * `0`: no optimizations, also turns on
251   [`cfg(debug_assertions)`](#debug-assertions) (the default).
252 * `1`: basic optimizations.
253 * `2`: some optimizations.
254 * `3`: all optimizations.
255 * `s`: optimize for binary size.
256 * `z`: optimize for binary size, but also turn off loop vectorization.
257
258 Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`.
259
260 The default is `0`.
261
262 ## overflow-checks
263
264 This flag allows you to control the behavior of [runtime integer
265 overflow](../../reference/expressions/operator-expr.md#overflow). When
266 overflow-checks are enabled, a panic will occur on overflow. This flag takes
267 one of the following values:
268
269 * `y`, `yes`, `on`, or no value: enable overflow checks.
270 * `n`, `no`, or `off`: disable overflow checks.
271
272 If not specified, overflow checks are enabled if
273 [debug-assertions](#debug-assertions) are enabled, disabled otherwise.
274
275 ## panic
276
277 This option lets you control what happens when the code panics.
278
279 * `abort`: terminate the process upon panic
280 * `unwind`: unwind the stack upon panic
281
282 If not specified, the default depends on the target.
283
284 ## passes
285
286 This flag can be used to add extra [LLVM
287 passes](http://llvm.org/docs/Passes.html) to the compilation.
288
289 The list must be separated by spaces.
290
291 See also the [`no-prepopulate-passes`](#no-prepopulate-passes) flag.
292
293 ## prefer-dynamic
294
295 By default, `rustc` prefers to statically link dependencies. This option will
296 indicate that dynamic linking should be used if possible if both a static and
297 dynamic versions of a library are available. There is an internal algorithm
298 for determining whether or not it is possible to statically or dynamically
299 link with a dependency. For example, `cdylib` crate types may only use static
300 linkage. This flag takes one of the following values:
301
302 * `y`, `yes`, `on`, or no value: use dynamic linking.
303 * `n`, `no`, or `off`: use static linking (the default).
304
305 ## profile-generate
306
307 This flag allows for creating instrumented binaries that will collect
308 profiling data for use with profile-guided optimization (PGO). The flag takes
309 an optional argument which is the path to a directory into which the
310 instrumented binary will emit the collected data. See the chapter on
311 [profile-guided optimization] for more information.
312
313 ## profile-use
314
315 This flag specifies the profiling data file to be used for profile-guided
316 optimization (PGO). The flag takes a mandatory argument which is the path
317 to a valid `.profdata` file. See the chapter on
318 [profile-guided optimization] for more information.
319
320 ## relocation-model
321
322 This option lets you choose which
323 [relocation](https://en.wikipedia.org/wiki/Relocation_\(computing\)) model to
324 use.
325
326 To find the valid options for this flag, run `rustc --print relocation-models`.
327
328 ## remark
329
330 This flag lets you print remarks for optimization passes.
331
332 The list of passes should be separated by spaces.
333
334 `all` will remark on every pass.
335
336 ## rpath
337
338 This flag controls whether [`rpath`](https://en.wikipedia.org/wiki/Rpath) is
339 enabled. It takes one of the following values:
340
341 * `y`, `yes`, `on`, or no value: enable rpath.
342 * `n`, `no`, or `off`: disable rpath (the default).
343
344 ## save-temps
345
346 This flag controls whether temporary files generated during compilation are
347 deleted once compilation finishes. It takes one of the following values:
348
349 * `y`, `yes`, `on`, or no value: save temporary files.
350 * `n`, `no`, or `off`: delete temporary files (the default).
351
352 ## soft-float
353
354 This option controls whether `rustc` generates code that emulates floating
355 point instructions in software. It takes one of the following values:
356
357 * `y`, `yes`, `on`, or no value: use soft floats.
358 * `n`, `no`, or `off`: use hardware floats (the default).
359
360 ## target-cpu
361
362 This instructs `rustc` to generate code specifically for a particular processor.
363
364 You can run `rustc --print target-cpus` to see the valid options to pass
365 here. Additionally, `native` can be passed to use the processor of the host
366 machine. Each target has a default base CPU.
367
368 ## target-feature
369
370 Individual targets will support different features; this flag lets you control
371 enabling or disabling a feature. Each feature should be prefixed with a `+` to
372 enable it or `-` to disable it. Separate multiple features with commas.
373
374 To see the valid options and an example of use, run `rustc --print
375 target-features`.
376
377 Using this flag is unsafe and might result in [undefined runtime
378 behavior](../targets/known-issues.md).
379
380 See also the [`target_feature`
381 attribute](../../reference/attributes/codegen.md#the-target_feature-attribute)
382 for controlling features per-function.
383
384 This also supports the feature `+crt-static` and `-crt-static` to control
385 [static C runtime linkage](../../reference/linkage.html#static-and-dynamic-c-runtimes).
386
387 Each target and [`target-cpu`](#target-cpu) has a default set of enabled
388 features.
389
390 ## bitcode-in-rlib
391
392 This flag controls whether or not the compiler puts compressed LLVM bitcode
393 into generated rlibs. It takes one of the following values:
394
395 * `y`, `yes`, `on`, or no value: put bitcode in rlibs (the default).
396 * `n`, `no`, or `off`: omit bitcode from rlibs.
397
398 LLVM bitcode is only needed when link-time optimization (LTO) is being
399 performed, but it is enabled by default for backwards compatibility reasons.
400
401 The use of `-C bitcode-in-rlib=no` can significantly improve compile times and
402 reduce generated file sizes. For these reasons, Cargo uses `-C
403 bitcode-in-rlib=no` whenever possible. Likewise, if you are building directly
404 with `rustc` we recommend using `-C bitcode-in-rlib=no` whenever you are not
405 using LTO.
406
407 If combined with `-C lto`, `-C bitcode-in-rlib=no` will cause `rustc` to abort
408 at start-up, because the combination is invalid.
409
410 [option-emit]: ../command-line-arguments.md#option-emit
411 [option-o-optimize]: ../command-line-arguments.md#option-o-optimize
412 [profile-guided optimization]: ../profile-guided-optimization.md
413 [option-g-debug]: ../command-line-arguments.md#option-g-debug