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`.
8 This option is deprecated and does nothing.
12 This option lets you choose which code model to use.
14 To find the valid options for this flag, run `rustc --print code-models`.
18 This flag controls how many code generation units the crate is split into. It
19 takes an integer greater than 0.
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.
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.
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:
35 * `y`, `yes`, `on`, or no value: enable debug-assertions.
36 * `n`, `no`, or `off`: disable debug-assertions.
38 If not specified, debug assertions are automatically enabled only if the
39 [opt-level](#opt-level) is 0.
43 This flag controls the generation of debug information. It takes one of the
46 * `0`: no debug info at all (the default).
47 * `1`: line tables only.
48 * `2`: full debug info.
50 Note: The [`-g` flag][option-g-debug] is an alias for `-C debuginfo=2`.
52 ## default-linker-libraries
54 This flag controls whether or not the linker includes its default libraries.
55 It takes one of the following values:
57 * `y`, `yes`, `on`, or no value: include default libraries (the default).
58 * `n`, `no`, or `off`: exclude default libraries.
60 For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to
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.
69 ## force-frame-pointers
71 This flag forces the use of frame pointers. It takes one of the following
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.
78 The default behaviour, if frame pointers are not force-enabled, depends on the
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.
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.
94 The default depends on the [opt-level](#opt-level):
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 |
107 This flag lets you append a single extra argument to the linker invocation.
109 "Append" is significant; you can pass this flag multiple times to add multiple arguments.
113 This flag lets you append multiple extra arguments to the linker invocation. The
114 options should be separated by spaces.
118 This flag controls whether the linker will keep dead code. It takes one of
119 the following values:
121 * `y`, `yes`, `on`, or no value: keep dead code.
122 * `n`, `no`, or `off`: remove dead code (the default).
124 An example of when this flag might be useful is when trying to construct code coverage
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.
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:
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.
147 [`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker) for Nvidia
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`.
158 [lld-flavor]: https://lld.llvm.org/Driver.html
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:
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.
172 This flag can be used to pass a list of arguments directly to LLVM.
174 The list must be separated by spaces.
176 Pass `--help` to see a list of options.
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:
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".
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:
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.
206 See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO.
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.
215 ## no-prepopulate-passes
217 This flag tells the pass manager to use an empty list of passes, instead of the
218 usual pre-populated list of passes.
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:
226 * `y`, `yes`, `on`, or no value: disable the red zone.
227 * `n`, `no`, or `off`: enable the red zone.
229 The default behaviour, if the flag is not specified, depends on the target.
233 This option is deprecated and does nothing.
235 ## no-vectorize-loops
237 This flag disables [loop
238 vectorization](https://llvm.org/docs/Vectorizers.html#the-loop-vectorizer).
242 This flag disables vectorization using
244 parallelism](https://llvm.org/docs/Vectorizers.html#the-slp-vectorizer).
248 This flag controls the optimization level.
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.
258 Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`.
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:
269 * `y`, `yes`, `on`, or no value: enable overflow checks.
270 * `n`, `no`, or `off`: disable overflow checks.
272 If not specified, overflow checks are enabled if
273 [debug-assertions](#debug-assertions) are enabled, disabled otherwise.
277 This option lets you control what happens when the code panics.
279 * `abort`: terminate the process upon panic
280 * `unwind`: unwind the stack upon panic
282 If not specified, the default depends on the target.
286 This flag can be used to add extra [LLVM
287 passes](http://llvm.org/docs/Passes.html) to the compilation.
289 The list must be separated by spaces.
291 See also the [`no-prepopulate-passes`](#no-prepopulate-passes) flag.
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:
302 * `y`, `yes`, `on`, or no value: use dynamic linking.
303 * `n`, `no`, or `off`: use static linking (the default).
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.
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.
322 This option lets you choose which
323 [relocation](https://en.wikipedia.org/wiki/Relocation_\(computing\)) model to
326 To find the valid options for this flag, run `rustc --print relocation-models`.
330 This flag lets you print remarks for optimization passes.
332 The list of passes should be separated by spaces.
334 `all` will remark on every pass.
338 This flag controls whether [`rpath`](https://en.wikipedia.org/wiki/Rpath) is
339 enabled. It takes one of the following values:
341 * `y`, `yes`, `on`, or no value: enable rpath.
342 * `n`, `no`, or `off`: disable rpath (the default).
346 This flag controls whether temporary files generated during compilation are
347 deleted once compilation finishes. It takes one of the following values:
349 * `y`, `yes`, `on`, or no value: save temporary files.
350 * `n`, `no`, or `off`: delete temporary files (the default).
354 This option controls whether `rustc` generates code that emulates floating
355 point instructions in software. It takes one of the following values:
357 * `y`, `yes`, `on`, or no value: use soft floats.
358 * `n`, `no`, or `off`: use hardware floats (the default).
362 This instructs `rustc` to generate code specifically for a particular processor.
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.
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.
374 To see the valid options and an example of use, run `rustc --print
377 Using this flag is unsafe and might result in [undefined runtime
378 behavior](../targets/known-issues.md).
380 See also the [`target_feature`
381 attribute](../../reference/attributes/codegen.md#the-target_feature-attribute)
382 for controlling features per-function.
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).
387 Each target and [`target-cpu`](#target-cpu) has a default set of enabled
392 This flag controls whether or not the compiler puts compressed LLVM bitcode
393 into generated rlibs. It takes one of the following values:
395 * `y`, `yes`, `on`, or no value: put bitcode in rlibs (the default).
396 * `n`, `no`, or `off`: omit bitcode from rlibs.
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.
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
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.
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