2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
8 .. index:: RISC-V Options
15 These command-line options are defined for RISC-V targets:
17 .. option:: -mbranch-cost={n}
19 Set the cost of branches to roughly :samp:`{n}` instructions.
21 .. option:: -mplt, -mno-plt
23 When generating PIC code, do or don't allow the use of PLTs. Ignored for
24 non-PIC. The default is :option:`-mplt`.
26 .. option:: -mabi={ABI-string}
28 Specify integer and floating-point calling convention. :samp:`{ABI-string}`
29 contains two parts: the size of integer types and the registers used for
30 floating-point types. For example :samp:`-march=rv64ifd -mabi=lp64d` means that
31 :samp:`long` and pointers are 64-bit (implicitly defining :samp:`int` to be
32 32-bit), and that floating-point values up to 64 bits wide are passed in F
33 registers. Contrast this with :samp:`-march=rv64ifd -mabi=lp64f`, which still
34 allows the compiler to generate code that uses the F and D extensions but only
35 allows floating-point values up to 32 bits long to be passed in registers; or
36 :samp:`-march=rv64ifd -mabi=lp64`, in which no floating-point arguments will be
39 The default for this argument is system dependent, users who want a specific
40 calling convention should specify one explicitly. The valid calling
41 conventions are: :samp:`ilp32`, :samp:`ilp32f`, :samp:`ilp32d`, :samp:`lp64`,
42 :samp:`lp64f`, and :samp:`lp64d`. Some calling conventions are impossible to
43 implement on some ISAs: for example, :samp:`-march=rv32if -mabi=ilp32d` is
44 invalid because the ABI requires 64-bit values be passed in F registers, but F
45 registers are only 32 bits wide. There is also the :samp:`ilp32e` ABI that can
46 only be used with the :samp:`rv32e` architecture. This ABI is not well
47 specified at present, and is subject to change.
49 .. option:: -mfdiv, -mno-fdiv
51 Do or don't use hardware floating-point divide and square root instructions.
52 This requires the F or D extensions for floating-point registers. The default
53 is to use them if the specified architecture has these instructions.
55 .. option:: -mdiv, -mno-div
57 Do or don't use hardware instructions for integer division. This requires the
58 M extension. The default is to use them if the specified architecture has
61 .. option:: -misa-spec={ISA-spec-string}
63 Specify the version of the RISC-V Unprivileged (formerly User-Level)
64 ISA specification to produce code conforming to. The possibilities
65 for :samp:`{ISA-spec-string}` are:
68 Produce code conforming to version 2.2.
71 Produce code conforming to version 20190608.
74 Produce code conforming to version 20191213.
76 The default is :option:`-misa-spec=20191213` unless GCC has been configured
77 with :option:`--with-isa-spec=` specifying a different default version.
79 .. option:: -march={ISA-string}
81 Generate code for given RISC-V ISA (e.g. :samp:`rv64im`). ISA strings must be
82 lower-case. Examples include :samp:`rv64i`, :samp:`rv32g`, :samp:`rv32e`, and
85 When :option:`-march=` is not specified, use the setting from :option:`-mcpu`.
87 If both :option:`-march` and :option:`-mcpu=` are not specified, the default for
88 this argument is system dependent, users who want a specific architecture
89 extensions should specify one explicitly.
91 .. option:: -mcpu={processor-string}
93 Use architecture of and optimize the output for the given processor, specified
94 by particular CPU name.
95 Permissible values for this option are: :samp:`sifive-e20`, :samp:`sifive-e21`,
96 :samp:`sifive-e24`, :samp:`sifive-e31`, :samp:`sifive-e34`, :samp:`sifive-e76`,
97 :samp:`sifive-s21`, :samp:`sifive-s51`, :samp:`sifive-s54`, :samp:`sifive-s76`,
98 :samp:`sifive-u54`, and :samp:`sifive-u74`.
100 .. option:: -mtune={processor-string}
102 Optimize the output for the given processor, specified by microarchitecture or
103 particular CPU name. Permissible values for this option are: :samp:`rocket`,
104 :samp:`sifive-3-series`, :samp:`sifive-5-series`, :samp:`sifive-7-series`,
105 :samp:`thead-c906`, :samp:`size`, and all valid options for :option:`-mcpu=`.
107 When :option:`-mtune=` is not specified, use the setting from :option:`-mcpu`,
108 the default is :samp:`rocket` if both are not specified.
110 The :samp:`size` choice is not intended for use by end-users. This is used
111 when :option:`-Os` is specified. It overrides the instruction cost info
112 provided by :option:`-mtune=`, but does not override the pipeline info. This
113 helps reduce code size while still giving good performance.
115 .. option:: -mpreferred-stack-boundary={num}
117 Attempt to keep the stack boundary aligned to a 2 raised to :samp:`{num}`
118 byte boundary. If :option:`-mpreferred-stack-boundary` is not specified,
119 the default is 4 (16 bytes or 128-bits).
123 If you use this switch, then you must build all modules with
124 the same value, including any libraries. This includes the system libraries
127 .. option:: -msmall-data-limit={n}
129 Put global and static data smaller than :samp:`{n}` bytes into a special section
132 .. option:: -msave-restore, -mno-save-restore
134 Do or don't use smaller but slower prologue and epilogue code that uses
135 library function calls. The default is to use fast inline prologues and
138 .. option:: -mshorten-memrefs, -mno-shorten-memrefs
140 Do or do not attempt to make more use of compressed load/store instructions by
141 replacing a load/store of 'base register + large offset' with a new load/store
142 of 'new base + small offset'. If the new base gets stored in a compressed
143 register, then the new load/store can be compressed. Currently targets 32-bit
144 integer load/stores only.
146 .. option:: -mstrict-align, -mno-strict-align
148 Do not or do generate unaligned memory accesses. The default is set depending
149 on whether the processor we are optimizing for supports fast unaligned access
152 .. option:: -mcmodel=medlow
154 Generate code for the medium-low code model. The program and its statically
155 defined symbols must lie within a single 2 GiB address range and must lie
156 between absolute addresses -2 GiB and +2 GiB. Programs can be
157 statically or dynamically linked. This is the default code model.
159 .. option:: -mcmodel=medany
161 Generate code for the medium-any code model. The program and its statically
162 defined symbols must be within any single 2 GiB address range. Programs can be
163 statically or dynamically linked.
165 .. option:: -mexplicit-relocs, -mno-exlicit-relocs
167 Use or do not use assembler relocation operators when dealing with symbolic
168 addresses. The alternative is to use assembler macros instead, which may
171 .. option:: -mrelax, -mno-relax
173 Take advantage of linker relaxations to reduce the number of instructions
174 required to materialize symbol addresses. The default is to take advantage of
177 .. option:: -mriscv-attribute, -mno-riscv-attribute
179 Emit (do not emit) RISC-V attribute to record extra information into ELF
180 objects. This feature requires at least binutils 2.32.
182 .. option:: -mcsr-check, -mno-csr-check
184 Enables or disables the CSR checking.
186 .. option:: -malign-data={type}
188 Control how GCC aligns variables and constants of array, structure, or union
189 types. Supported values for :samp:`{type}` are :samp:`xlen` which uses x register
190 width as the alignment value, and :samp:`natural` which uses natural alignment.
191 :samp:`xlen` is the default.
193 .. option:: -mbig-endian
195 Generate big-endian code. This is the default when GCC is configured for a
196 :samp:`riscv64be-*-*` or :samp:`riscv32be-*-*` target.
198 .. option:: -mlittle-endian
200 Generate little-endian code. This is the default when GCC is configured for a
201 :samp:`riscv64-*-*` or :samp:`riscv32-*-*` but not a :samp:`riscv64be-*-*` or
202 :samp:`riscv32be-*-*` target.
204 .. option:: -mstack-protector-guard={guard}
206 Generate stack protection code using canary at :samp:`{guard}`. Supported
207 locations are :samp:`global` for a global canary or :samp:`tls` for per-thread
208 canary in the TLS block.
210 With the latter choice the options
211 :option:`-mstack-protector-guard-reg=reg` and
212 :option:`-mstack-protector-guard-offset=offset` furthermore specify
213 which register to use as base register for reading the canary,
214 and from what offset from that base register. There is no default
215 register or offset as this is entirely for use within the Linux