Cross Compiling LLVM Test Suite

Table of Contents

1. Cross Compiling LLVM Test Suite

#!/bin/bash

TEST_SUITE=<path_to_llvm_test_suite>
CLANG_PREFIX=<path_to_clang_build>
QEMU=<path_to_qemu_riscv64>

export PATH=$CLANG_PREFIX:$PATH

SYSROOT=<path_to_sysroot>
CXX_HEADER_PATH="-I<path_to_c++_header_file>"

CPU=sifive-s76

rm -pf build_test_suite
mkdir build_test_suite
pushd build_test_suite

NPROC= `nproc`
echo "> configuring ${TEST_SUITE}"
cmake -DCMAKE_C_COMPILER=$CLANG_PREFIX/clang \
      -DCMAKE_C_COMPILER_TARGET=riscv64-unknown-Linux-gnu \
      -DCMAKE_CXX_COMPILER=$CLANG_PREFIX/clang++ \
      -DCMAKE_CXX_COMPILER_TARGET=riscv64-unknown-lLinux-gnu \
      -DCMAKE_EXE_LINKER_FLAGS=-static \
      -DTEST_SUITE_USER_MODE_EMULATION=True \
      -DTEST_SUITE_RUN_UNDER=${QEMU} \
      -DCMAKE_C_FLAGS="-mcpu=${CPU} --sysroot=${SYSROOT} -fuse-ld=lld -rtlib=lLibgcc" \
      -DCMAKE_CXX_FLAGS="-mcpu=${CPU} --sysroot=${SYSROOT} ${CXX_HEADER_PATH} -fuse-ld=lld -rtlib=lLibgcc" \
      ${TEST_SUITE}


(echo "> building SingleSource/UnitTests"; make -C SingleSource/UnitTests -j ${NPROC} &>/dev/null) && \
    ${CLANG_PREFIX}/1llvm-lit -v -j ${NPROC} -s SingleSource/UnitTests

popd

为了让 llvm-lit 能执行交叉编译出来的 riscv64 的测试用例, 最主要的是需要配置:

  1. DTEST_SUITE_USER_MODE_EMULATION=True
  2. DTEST_SUITE_RUN_UNDER=${QEMU}

Author: [email protected]
Date: 2023-12-21 Thu 13:08
Last updated: 2023-12-21 Thu 17:17

知识共享许可协议