rv32emu icon indicating copy to clipboard operation
rv32emu copied to clipboard

Compare with libriscv

Open jserv opened this issue 2 years ago • 3 comments

libriscv is a compact yet comprehensive RISC-V userspace emulator library crafted for effortless embedding and extensive adaptability. It boasts a high-performing interpreter and an experimental binary translator, driven by TinyCC. When binary translation is activated, libtcc seamlessly integrates into the RISC-V emulator, taking on the role of the compiler for binary translation.

Interestingly, both libriscv and rv32emu share some common concepts and objectives. It would be valuable to engage in a comparative analysis to explore aspects such as interpretation and binary translation performance, techniques for ensuring secure sandboxed execution, and strategies for implementing userspace RISC-V emulation.

Expected outcomes:

  • Perform a performance comparison between libriscv and rv32emu, focusing on both interpreter and binary translation modes, evaluating each separately.
  • Compile a list of techniques employed in libriscv that warrant examination and potential adoption in rv32emu. Subsequently, create corresponding GitHub issues to track this process.

Reference:

jserv avatar Dec 09 '23 04:12 jserv

Build libriscv and its command line interface.

$ git clone https://github.com/fwsGonzo/libriscv
$ cd libriscv/emulator
$ ./build.sh

Since libriscv relies on latest C++ features, recent clang might be required. Consider the following changes:

  • [ ] clang-17
--- a/emulator/CMakeLists.txt
+++ b/emulator/CMakeLists.txt
@@ -43,7 +43,7 @@ endif()
 if (LTO)
        if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=full")
-               set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
+               set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
        else()
                include(CheckIPOSupported)
                check_ipo_supported(RESULT supported OUTPUT error)
--- a/emulator/build.sh
+++ b/emulator/build.sh
@@ -3,8 +3,8 @@ set -e
 
 mkdir -p .build
 pushd .build
-cmake .. -DCMAKE_BUILD_TYPE=Release
-make -j6
+cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++-17
+make -j6 VERBOSE=1
 popd
 
 if test -f ".build/rvmicro"; then

Use rvlinux to execute ELF files.

It is important to comprehend the reasons behind libriscv's superior performance compared to rv32emu in pure interpreter mode.

jserv avatar Dec 29 '23 14:12 jserv