Sign inSign up

deagwon97/riscv-gnu-toolchain

By deagwon97

•Updated over 3 years ago

riscv-gnu-toolchain in arm64, amd64(x86)

Image
2

502

deagwon97/riscv-gnu-toolchain repository overview

⁠riscv-gnu-toolchain

This is "riscv gnu toolchain" container image. It has tags corresponding to both the arm64(apple silicon) and amd64(intel, amd) architectures.

You could cross-compile your C code to RISC-V binary. Use the appropriate tag depending on the device you are using.

⁠How to use

⁠1. docker run
>> docker run -it deagwon97/riscv-gnu-toolchain:amd64 # for intel, amd
or
>> docker run -it deagwon97/riscv-gnu-toolchain:arm64 # for apple silicon 
⁠2. create example code
# root@776c53f76757:~# cat << EOF > main.c
> long A[10] = { -1, -2, -3, 1, 2, 3, 4, 5, 6, 7 };
> long sum = 0;
> int i;
>
> int main (void) {
>    for (i=0; i<10; i++) {
>       if (A[i]>0)
>          sum += A[i];
>    }
>    return 0;
> }
>
> EOF
# root@776c53f76757:~# ls
main.c
⁠3. compile main.c by riscv64-unknown-elf-gcc
# root@776c53f76757:~# riscv64-unknown-elf-gcc main.c -o main.out
# root@776c53f76757:~# ls
main.c  main.out     
⁠4. disassemble main.out by riscv64-unknown-elf-objdump
root@776c53f76757:~# riscv64-unknown-elf-objdump --disassemble=main --visualize-jumps --disassembler-color=extended -M numeric,no-aliases main.out

main.out:     file format elf64-littleriscv


Disassembly of section .text:

00000000000101e0 <main>:
   101e0:                 ff010113              addi    x2,x2,-16
   101e4:                 00813423              sd      x8,8(x2)
   101e8:                 01010413              addi    x8,x2,16
   101ec:                 fa01ac23              sw      x0,-72(x3) # 11e30 <i>
   101f0:          /----- 0540006f              jal     x0,10244 <main+0x64>
   101f4:       /--|----> fb81a783              lw      x15,-72(x3) # 11e30 <i>
   101f8:       |  |      00011737              lui     x14,0x11
   101fc:       |  |      67870713              addi    x14,x14,1656 # 11678 <A>
   10200:       |  |      00379793              slli    x15,x15,0x3
   10204:       |  |      00f707b3              add     x15,x14,x15
   
...

⁠How to create

This container image was built based on ubuntu:20.04 docker image and https://github.com/riscv-collab/riscv-gnu-toolchain⁠ repository.

# Tested on Ubuntu 20.04.5
# set DEBIAN_FRONTEND=noninteractive to forbid blocking on package installation
​
sudo apt-get update
sudo apt-get -y dist-upgrade
​
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install \
binutils build-essential libtool texinfo \
gzip zip unzip patchutils curl git \
make cmake ninja-build automake bison flex gperf \
grep sed gawk python3 bc \
zlib1g-dev libexpat1-dev libmpc-dev \
libglib2.0-dev libfdt-dev libpixman-1-dev 
​
export RISCV_TOOLCHAIN=/opt/riscv
​
# gcc, binutils, newlib build
git clone https://github.com/riscv/riscv-gnu-toolchain
pushd riscv-gnu-toolchain
./configure --prefix=$RISCV_TOOLCHAIN -with-arch=rv64g --disable-multilib
make -j$(nproc)
popd
​
# Environment Variable check & setting
if command -v riscv64-unknown-elf-gcc &>/dev/null; then 
	echo "Adding RISC-V Toolchain folder to PATH"
	echo "export PATH=\$RISCV_TOOLCHAIN/bin:\$PATH" >> ~/.bashrc
fi
export PATH=$RISCV_TOOLCHAIN/bin:$PATH
​

⁠reference

Tag summary

Content type

Image

Digest

sha256:2c51e4c5a…

Size

705.6 MB

Last updated

over 3 years ago

docker pull deagwon97/riscv-gnu-toolchain:arm64