LinuxCommandLibrary

riscv64-unknown-elf-gcc

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 (rv64imac, rv64gc).
-mabi=abi
ABI (lp64, lp64d).
-nostdlib
No standard library.
-T script
Linker script.
-mcmodel=model
Code model.
-Olevel
Optimization level.

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 (IMAFD + C)
rv32imac  - 32-bit version
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