LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

riscv64-unknown-elf-gcc

Cross-compile C code for RISC-V targets

TLDR

Compile for RISC-V
$ riscv64-unknown-elf-gcc -o [output] [source.c]
copy
Compile with specific architecture
$ riscv64-unknown-elf-gcc -march=rv64imac -o [output] [source.c]
copy
Compile for bare metal
$ riscv64-unknown-elf-gcc -nostdlib -o [output] [source.c]
copy
Produce assembly
$ riscv64-unknown-elf-gcc -S [source.c]
copy

SYNOPSIS

riscv64-unknown-elf-gcc [options] files...

DESCRIPTION

riscv64-unknown-elf-gcc is the GCC cross-compiler for RISC-V 64-bit bare-metal targets. It compiles C/C++ code for RISC-V processors without an operating system.

PARAMETERS

-march=arch

Target architecture (e.g. rv64imac, rv64gc, rv32imac).
-mabi=abi
Integer and floating-point calling convention (e.g. lp64, lp64d, lp64f, ilp32).
-nostdlib
Do not link standard library or startup files.
-T script
Use the specified linker script.
-mcmodel=model
Code model: medlow (default) or medany.
-msave-restore
Use smaller but slower prologue/epilogue routines to reduce code size.
-msmall-data-limit=n
Put global and static data smaller than n bytes in a special section.
--specs=file
Use the specified specs file (e.g. nano.specs for newlib-nano).
-Olevel
Optimization level (0, 1, 2, 3, s, g).

EXAMPLES

$ # Basic compilation
riscv64-unknown-elf-gcc -o hello hello.c

# With specific ISA extensions
riscv64-unknown-elf-gcc -march=rv64gc -mabi=lp64d -o prog prog.c

# Bare metal with linker script
riscv64-unknown-elf-gcc -nostdlib -T link.ld -o firmware firmware.c

# Generate object file
riscv64-unknown-elf-gcc -c -o main.o main.c

# With newlib
riscv64-unknown-elf-gcc --specs=nano.specs -o app app.c
copy

ARCHITECTURES

$ rv64imac   - Integer, Multiply, Atomic, Compressed
rv64gc     - General purpose (IMAFDC) - equivalent to rv64imafdC
rv64imafdc - Same as rv64gc (explicit form)
rv32imac   - 32-bit: Integer, Multiply, Atomic, Compressed
rv32gc     - 32-bit general purpose
copy

CAVEATS

Cross-compiler for embedded. Requires RISC-V toolchain installation. Different from riscv64-linux-gnu-gcc.

HISTORY

RISC-V GCC toolchain was developed as part of the RISC-V open ISA project from UC Berkeley.

SEE ALSO

Copied to clipboard
Kai