Skip to content

RISC V binutils

Kirill Korolev edited this page Dec 2, 2019 · 8 revisions

How to get binutils source files

RISC-V binutils must be build manually, so first you'll need to get sources.

The source files are stored in GitHub repository in the riscv project. Use git to get a local clone of the repository:

git clone --recursive https://github.com/riscv/riscv-gnu-toolchain.git

How to build binutils

This cheat-sheet is based on GitHub README. See it if you have any problem or need more information.

# Install prerequisites 
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

# Create a folder where the binutils will be installed (can be any)
mkdir /opt/cross

# Create a folder for a build process (can be any):
cd /tmp
mkdir build-binutils && cd build-binutils

# Configure build (configures for RV64GC by default):
/path/to/binutils/configure --prefix=/opt/cross

# Make sources (can dump a lot of info):  
make
  
# Install (can dump a lot of info, usually requires sudo):  
sudo make install

# Update PATH variable to have binaries available:
export PATH=$PATH;/opt/cross/bin

Note that in addition to assembler this RISC-V GNU toolchain also includes C and C++ cross-compiler, so you can build C/C++ code for RISC-V on regular x86 machines.

Clone this wiki locally