### Install pyelftools for Testing Environment Setup Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Installs the pyelftools library, a prerequisite for setting up the RISC-V testing environment. Installation commands vary by distribution (Ubuntu, Fedora, CentOS/RHEL, Arch Linux) or can be done via pip. ```bash sudo apt-get install python3-pyelftools ``` ```bash sudo yum install python3-pyelftools ``` ```bash sudo pacman -Syyu python-pyelftools python-sphinx python-sphinx_rtd_theme ninja ``` ```bash # Assuming pip is installed pip3 install --user pyelftools ``` -------------------------------- ### Multilib Configuration for RISC-V Toolchain Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Enables the creation of toolchains that support multiple architecture and ABI combinations simultaneously. Examples demonstrate building a multilib toolchain, listing supported configurations, and compiling for specific variants. ```bash # Build multilib toolchain supporting both RV32 and RV64 ./configure --prefix=/opt/riscv --enable-multilib make linux # List supported multilib configurations riscv64-unknown-linux-gnu-gcc --print-multi-lib # Build with custom multilib generator ./configure --prefix=/opt/riscv \ --with-multilib-generator="rv32i-ilp32--;rv32imafd-ilp32--" make # Compile for specific architecture variant with multilib riscv64-unknown-elf-gcc -march=rv32imac -mabi=ilp32 -o app32 app.c riscv64-unknown-elf-gcc -march=rv64gc -mabi=lp64d -o app64 app.c ``` -------------------------------- ### Build Newlib Bare-Metal Toolchain Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Configures and builds a cross-compiler toolchain for bare-metal RISC-V systems using the Newlib C library. This includes options for specifying the architecture and ABI, and examples of compiling and inspecting bare-metal programs. ```bash # Build basic RV64GC bare-metal toolchain ./configure --prefix=/opt/riscv make # Build with specific architecture and ABI ./configure --prefix=/opt/riscv --with-arch=rv32ima --with-abi=ilp32 make # After installation, compile a bare-metal program export PATH=/opt/riscv/bin:$PATH riscv64-unknown-elf-gcc -o hello hello.c riscv64-unknown-elf-objdump -d hello ``` -------------------------------- ### Advanced Multilib Testing Configuration Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Adds support for additional architecture/ABI combinations for testing purposes without altering the standard multilib installation. Examples show how to include vector extensions and use custom flag combinations. ```bash # Test additional configurations with vector extensions ./configure --prefix=/opt/riscv --enable-multilib \ --with-extra-multilib-test="rv64gcv-lp64d;rv64gcv_zba-lp64d" make linux make report-linux SIM=qemu # Test with simultaneous flags (AND operation using ':') ./configure --prefix=/opt/riscv \ --with-extra-multilib-test="rv64gcv-lp64d:--param=riscv-autovec-lmul=dynamic:--param=riscv-autovec-preference=fixed-vlmax" # Test with alternative flags (OR operation using ',') ./configure --prefix=/opt/riscv \ --with-extra-multilib-test="rv64gcv-lp64d:--param=riscv-autovec-lmul=dynamic,--param=riscv-autovec-lmul=m2" ``` -------------------------------- ### Build Linux Toolchain with glibc/musl Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Configures and builds a cross-compiler toolchain for RISC-V Linux systems, supporting both glibc and musl libc. Examples show how to build for 32-bit and 64-bit architectures and ABIs, and how to compile and run Linux applications. ```bash # Build RV64GC Linux toolchain with glibc ./configure --prefix=/opt/riscv make linux # Build 32-bit RV32GC Linux toolchain ./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d make linux # Build with musl libc instead of glibc ./configure --prefix=/opt/riscv --with-arch=rv64gc --with-abi=lp64d make musl # Compile and run Linux application export PATH=/opt/riscv/bin:$PATH riscv64-unknown-linux-gnu-gcc -o app app.c qemu-riscv64 -L /opt/riscv/sysroot ./app ``` -------------------------------- ### LLVM/Clang Integration for RISC-V Toolchain Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Builds the RISC-V toolchain with support for LLVM and Clang, enabling compilation of C and C++ applications using these frontends. Examples show building the Linux toolchain with LLVM and compiling code with clang and clang++. ```bash # Build Linux toolchain with LLVM support ./configure --prefix=/opt/riscv --enable-llvm --enable-linux --with-arch=rv64gc --with-abi=lp64d make -j$(nproc) all build-sim SIM=qemu # Compile C application with clang export PATH=/opt/riscv/bin:$PATH clang -march=rv64imafdc -o hello hello.c qemu-riscv64 -L /opt/riscv/sysroot ./hello # Compile C++ application with clang++ clang++ -march=rv64imafdc -stdlib=libc++ -o hello_cpp hello.cpp qemu-riscv64 -L /opt/riscv/sysroot ./hello_cpp ``` -------------------------------- ### ISA Specification Version Selection Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Controls the default RISC-V Instruction Set Architecture (ISA) specification version used by the toolchain. Examples demonstrate setting specific versions and verifying the selected ISA spec in compiled code. ```bash # Use ISA spec version 20191213 (default) ./configure --prefix=/opt/riscv --with-isa-spec=20191213 make # Use older ISA spec version ./configure --prefix=/opt/riscv --with-isa-spec=2.2 make # Verify ISA spec in compiled code riscv64-unknown-elf-gcc -march=rv64gc -misa-spec=20191213 -o test test.c readelf -A test ``` -------------------------------- ### Configure RISC-V Toolchain with QEMU System Targets Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Enables QEMU system emulation targets (softmmu) in addition to default user-mode emulation. Requires `make build-sim SIM=qemu` to build the simulator. Useful for full system emulation. ```bash ./configure --enable-qemu-system --prefix=/opt/riscv make build-sim SIM=qemu ``` -------------------------------- ### Configure and Test GCC with Linux Toolchain using QEMU Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Configures the toolchain for Linux and runs the Linux regression tests using the QEMU simulator. This is a common configuration for testing user-space applications. ```bash ./configure --prefix=$RISCV make linux make report-linux SIM=qemu ``` -------------------------------- ### Configure and Test GCC with Newlib Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Configures the toolchain for newlib and runs the newlib regression tests using the GDB simulator. Requires specifying the architecture (`--with-arch`). ```bash ./configure --prefix=$RISCV --disable-linux --with-arch=rv64ima # or --with-arch=rv32ima make newlib make report-newlib SIM=gdb ``` -------------------------------- ### Build RISC-V Toolchain with LLVM and QEMU Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Configures and builds the RISC-V GNU toolchain with LLVM support, disabling Linux, and enabling specific architecture and ABI. It then compiles a C++ hello world program and runs it using QEMU. ```bash # Build newlib toolchain with LLVM ./configure --prefix=/opt/riscv --enable-llvm --disable-linux --with-arch=rv64gc --with-abi=lp64d make -j$(nproc) all build-sim SIM=qemu clang++ -march=rv64imafdc -static -o hello_static hello.cpp qemu-riscv64 -L /opt/riscv/sysroot ./hello_static ``` -------------------------------- ### Configure and Test GCC with Spike Simulator Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Configures the toolchain to use the Spike simulator. This is typically for bare-metal/elf toolchains and supports `rv64*` architectures. ```bash ./configure --prefix=$RISCV --with-sim=spike make linux make report ``` -------------------------------- ### Run RISC-V GCC Test Suite with Simulators Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Details how to execute the GCC regression test suite using different simulators (GDB, QEMU, Spike) for both bare-metal and Linux toolchains. Includes commands for generating test reports. ```bash # Test bare-metal toolchain with GDB simulator ./configure --prefix=/opt/riscv --disable-linux --with-arch=rv64ima make newlib make report-newlib SIM=gdb # Test Linux toolchain with QEMU ./configure --prefix=/opt/riscv make linux make report-linux SIM=qemu # Test with Spike simulator ./configure --prefix=/opt/riscv --with-sim=spike make linux make report # Run parallel tests to speed up execution make -j$(nproc) report-linux SIM=qemu ``` -------------------------------- ### Run All Toolchain Tests (GCC, Binutils, glibc) Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Executes the default `report` target, which runs all GCC regression tests. Alternatively, specific targets `check-gcc`, `check-binutils`, and `check-glibc-linux` can be used to run tests for individual components. ```bash make report # Runs all GCC regression tests make check-gcc # Runs GCC tests make check-binutils # Runs Binutils tests make check-glibc-linux # Runs glibc tests ``` -------------------------------- ### Configure RISC-V Toolchain with Custom Source Trees Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Shows how to build the RISC-V toolchain using external source trees for GCC, binutils, newlib, or Linux headers instead of the bundled submodules. ```bash # Use custom GCC source tree ./configure --prefix=/opt/riscv --with-gcc-src=$HOME/gcc-dev make # Use multiple custom sources ./configure --prefix=/opt/riscv \ --with-gcc-src=$HOME/gcc-dev \ --with-binutils-src=$HOME/binutils-dev \ --with-newlib-src=$HOME/newlib-dev make # Use custom Linux headers ./configure --prefix=/opt/riscv \ --with-linux-headers-src=$HOME/linux/include make linux ``` -------------------------------- ### Analyze RISC-V Architecture Strings with Python Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Uses a Python script (`march_to_cpu_opt.py`) to parse RISC-V architecture strings, determine vector length, and generate QEMU CPU configuration. It can also parse architecture from ELF files and generate Spike ISA/vector configurations. ```python #!/usr/bin/env python3 from march_to_cpu_opt import parse_march, get_vlen, CPU_OPTIONS # Parse architecture string from command line import sys sys.path.insert(0, './scripts') from march_to_cpu_opt import * # Parse march string extensions = parse_march("rv64gcv") print(f"Extensions: {extensions}") # Get vector length vlen = get_vlen(extensions) print(f"VLEN: {vlen}") # Generate QEMU CPU configuration CPU_OPTIONS["xlen"] = 64 CPU_OPTIONS["vlen"] = vlen CPU_OPTIONS["extensions"] = list(extensions.keys()) qemu_cpu = print_qemu_cpu() print(f"QEMU CPU: {qemu_cpu}") ``` -------------------------------- ### Parse RISC-V Architecture from ELF Files (Bash) Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Utilizes the `march-to-cpu-opt` script to extract RISC-V architecture information from ELF files, including XLEN, QEMU CPU configuration, Spike ISA string, and Spike vector architecture. Also includes commands for running self-tests. ```bash # Parse architecture from ELF file ./scripts/march-to-cpu-opt --elf-file-path=./hello --print-xlen # Output: 64 # Get QEMU CPU configuration string ./scripts/march-to-cpu-opt --elf-file-path=./hello --print-qemu-cpu # Output: rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0 # Get Spike ISA string ./scripts/march-to-cpu-opt --elf-file-path=./hello --print-spike-isa # Output: rv64imafdcv # Get Spike vector architecture ./scripts/march-to-cpu-opt --elf-file-path=./hello --print-spike-varch # Output: vlen:128,elen:64 # Run self-tests ./scripts/march-to-cpu-opt -selftest ``` -------------------------------- ### Configure RISC-V Toolchain Code Model Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Demonstrates how to configure the RISC-V toolchain to use different code models (medany, medlow) for libc and libgcc. It also shows how to verify the selected code model using objdump. ```bash # Build with medany code model (default is medlow) ./configure --prefix=/opt/riscv --with-cmodel=medany make # Use medlow code model explicitly ./configure --prefix=/opt/riscv --with-cmodel=medlow make # Verify code model in compiled library riscv64-unknown-elf-objdump -d /opt/riscv/riscv64-unknown-elf/lib/libc.a | grep -A5 "auipc" ``` -------------------------------- ### Configure RISC-V Toolchain Language Selection Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Explains how to control which programming languages (C, C++, Fortran) are enabled in the GCC toolchain build, allowing for a smaller footprint if certain languages are not required. Includes default language sets for different environments. ```bash # Build with C and C++ only (smaller footprint) ./configure --prefix=/opt/riscv --with-languages=c,c++ make # Build with C, C++, and Fortran ./configure --prefix=/opt/riscv --with-languages=c,c++,fortran make linux ``` -------------------------------- ### Filter RISC-V GCC Test Suite Results Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Demonstrates how to use the `testsuite-filter` script to compare test results against allowlists, identifying new unexpected failures for GCC, binutils, and newlib. ```bash # Filter GCC test results ./scripts/testsuite-filter gcc newlib \ ./test/allowlist \ ./build-gcc-newlib-stage2/gcc/testsuite/gcc/gcc.sum # Filter with multiple sum files ./scripts/testsuite-filter gcc glibc \ ./test/allowlist \ ./build/gcc/testsuite/gcc/gcc.sum,./build/gcc/testsuite/g++/g++.sum # Filter binutils test results ./scripts/testsuite-filter binutils newlib \ ./test/allowlist \ ./build-binutils/binutils/binutils.sum,./build-binutils/ld/ld.sum ``` -------------------------------- ### Selective RISC-V GCC Test Execution Source: https://context7.com/riscv-collab/riscv-gnu-toolchain/llms.txt Provides methods for running specific subsets of the GCC test suite to expedite development cycles. This includes running RISC-V specific tests, tests matching patterns, component-specific tests, and tests with custom architecture/ABI configurations. ```bash # Run only RISC-V specific tests RUNTESTFLAGS="riscv.exp" make report # Run specific test patterns RUNTESTFLAGS="riscv.exp=zb*.c sm*.c" make report # Run tests for specific components make check-gcc make check-binutils make check-glibc-linux # Run with specific architecture/ABI configuration make report-linux SIM=qemu \ RUNTESTFLAGS="--target_board=riscv-sim/-march=rv64gcv/-mabi=lp64d" ``` -------------------------------- ### Restrict GCC Regression Tests by File Pattern Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Further refines GCC regression tests by specifying file patterns within the RISC-V specific tests. Useful for targeting specific test cases. ```bash RUNTESTFLAGS="riscv.exp=zb*.c\ sm*.c" make report ``` -------------------------------- ### Restrict GCC Regression Tests to RISC-V Specific Tests Source: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md Uses the `RUNTESTFLAGS` environment variable to limit GCC regression tests to only those relevant to RISC-V. This significantly reduces test execution time. ```bash RUNTESTFLAGS="riscv.exp" make report ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.