-
Notifications
You must be signed in to change notification settings - Fork 0
Development documentation for scripts for ARC‐V GNU toolchain
Yuriy Kolerov edited this page Dec 12, 2025
·
6 revisions
riscv64-snps-elf-buildlib is a Python script which helps a user to build Picolibc, libgcc and libstdc++ for a custom target configuration.
- First,
buildlibtries to findriscv64-snps-elf-gccinPATHor in a local directory. It fails if GCC could not be found. - Create the main
buildlibdirectory and build directories for Picolibc and GCC. Create symbolic links for Picolibc and GCC sources. - Configure, build and install Picolibc and then GCC. All libraries are installed to the
buildlibdirectory. - Delete symbolic links to sources and build directories for Picolibc and GCC (if
--no-cleanis not passed).
Build a sample configuration:
$ ./riscv64-snps-elf-buildlib build \
--buildlib-dir-path buildlib \
--gcc-sources-dir-path <path-to-gcc> \
--picolibc-sources-dir-path <path-to-picolibc> \
--march rv32imac \
--mabi ilp32 \
--mtune arc-v-rmx-500-series \
--mcmodel medlow \
--nproc 4 \
--cflags "-O3 -g0"
Here is a buildlib directory structure:
tree -d -L 3 buildlib
buildlib
├── lib
│ └── gcc
│ └── riscv64-snps-elf
├── riscv64-snps-elf
│ ├── include
│ │ ├── arpa
│ │ ├── bits
│ │ ├── c++
│ │ ├── machine
│ │ ├── rpc
│ │ ├── ssp
│ │ └── sys
│ ├── lib
│ └── sys-include
│ ├── arpa
│ ├── bits
│ ├── machine
│ ├── rpc
│ ├── ssp
│ └── sys
└── share
└── gcc-15.2.0
└── python
To build and link an application with a custom library, you need to pass extra arguments:
-
-specs=./buildlib/buildlib.specs- include a.specsfile which turns off default multilib rules. -
-isystem ./buildlib/riscv64-snps-elf/sys-include -isystem ./buildlib/riscv64-snps-elf/include- use included from a custom Picolibc. -
-B./buildlib/lib/gcc -B./buildlib/riscv64-snps-elf/lib- use custom libraries by default instead of original.
Consider this example:
int main()
{
printf("Hello, World!\n");
return 0;
}How to link an application with custom libraries (also, we pass -Wl,-t to ensure that custom libraries are linked with our application):
$ riscv64-snps-elf-gcc \
-march=rv32imac \
-mabi=ilp32 \
-mtune=arc-v-rmx-100-series \
-mcmodel=medlow \
-isystem ./buildlib/riscv64-snps-elf/sys-include \
-isystem ./buildlib/riscv64-snps-elf/include \
-B./buildlib/lib/gcc \
-B./buildlib/riscv64-snps-elf/lib \
-specs=picolibc.specs \
-specs=buildlib.specs \
--oslib=semihost \
--crt0=semihost \
hello.c -o hello.elf \
-Wl,-t
./buildlib/riscv64-snps-elf/lib/crt0-semihost.o
/tmp/ccUptbxg.o
./buildlib/lib/gcc/riscv64-snps-elf/15.2.0/libgcc.a
./buildlib/lib/gcc/riscv64-snps-elf/15.2.0/libgcc.a
./buildlib/riscv64-snps-elf/lib/libc.a
./buildlib/riscv64-snps-elf/lib/libsemihost.a
./buildlib/lib/gcc/riscv64-snps-elf/15.2.0/libgcc.a
./buildlib/riscv64-snps-elf/lib/libc.a
./buildlib/riscv64-snps-elf/lib/libsemihost.a
./buildlib/lib/gcc/riscv64-snps-elf/15.2.0/libgcc.a
Now we can run the example:
$ nsimdrv -p nsim_isa_family=rv32 -p nsim_isa_ext=-all.i.m.a.c.zicsr -p nsim_semihosting=1 -p enable_exceptions=0 hello.elf
Hello, World!