Code Monkey home page Code Monkey logo

rv32jit's Introduction

rv32jit

rv32jit is a modern C++-based RISC-V instruction set simulator with a JIT assembler serving as an x86-64 binary translator.

Features

  • Fast runtime for executing the RV32 ISA
  • Built-in ELF loader
  • Implementation of partial Linux system calls

Build and Verify

Currently, only GNU/Linux is supported for building rv32jit.

rv32jit relies on specific third-party packages for full functionality. Please install the following package in advance.

  • clang version 15+, which can be downloaded from the LLVM Page.
  • libelf-dev

Build the simulator:

$ make

You might receive the message "Please run 'make' again." If you do, simply follow the instruction and run make once more.

Download prebuilt RISC-V ELF files and run:

$ make check

License

rv32jit is available under a permissive MIT-style license. Use of this source code is governed by a MIT license that can be found in the LICENSE file.

rv32jit's People

Contributors

25077667 avatar eagletw avatar higuoxing avatar jserv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rv32jit's Issues

Memory leaking issues

When I turn on the -fsanitize=address flag for clang++, and make check.

The aes.elf stage said:

Running build/aes.elf ...
Test results
AES-128 ECB encryption: PASSED!
AES-128 ECB decryption: PASSED!
AES-128 CBC encryption: PASSED!
AES-128 CBC decryption: PASSED!
AES-128 CFB encryption: PASSED!
AES-128 CFB decryption: PASSED!
AES-128 OFB encryption: PASSED!
AES-128 OFB decryption: PASSED!
AES-128 CTR encryption: PASSED!
AES-128 CTR decryption: PASSED!
AES-128 XTS encryption: PASSED!
AES-128 XTS decryption: PASSED!
AES-128 plaintext CMAC: PASSED!
AES-128 Poly1305 auth.: PASSED!
AES-128 GCM encryption: PASSED!
AES-128 GCM decryption: PASSED!
AES-128 CCM encryption: PASSED!
AES-128 CCM decryption: PASSED!
AES-128 OCB encryption: PASSED!
AES-128 OCB decryption: PASSED!
AES-128 SIV encryption: PASSED!
AES-128 SIV decryption: PASSED!
AES-128 GCMSIV encrypt: PASSED!
AES-128 GCMSIV decrypt: PASSED!
AES-128 EAX encryption: PASSED!
AES-128 EAX decryption: PASSED!
AES-128 FF1 encryption: PASSED!
AES-128 FPE decryption: PASSED!
AES-128 key wrapping  : PASSED!
AES-128 key unwrapping: PASSED!
+-> Let's do some extra tests
AES-128 OCB encryption: PASSED!
AES-128 OCB decryption: PASSED!
AES-128 GCMSIV encrypt: PASSED!
AES-128 GCMSIV decrypt: PASSED!
AES-128 GCMSIV encrypt: PASSED!
AES-128 GCMSIV decrypt: PASSED!
AES-128 SIV encryption: PASSED!
AES-128 SIV decryption: PASSED!
AES-128 SIV encryption: PASSED!
AES-128 SIV decryption: PASSED!
AES-128 EAX encryption: PASSED!
AES-128 EAX decryption: PASSED!
AES-128 EAX encryption: PASSED!
AES-128 EAX decryption: PASSED!
AES-128 Poly1305 auth.: PASSED!
AES-128 Poly1305 auth.: PASSED!

=================================================================
==33140==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 10065 byte(s) in 970 object(s) allocated from:
    #0 0x560ebde7fc82 in operator new(unsigned long) (me/git/rv32jit/build/rv32jit+0x16ac82) (BuildId: d5f40ebc9e253e729fadf45522801b8f8372a477)
    #1 0x560ebdee25ed in dbt::qir::Builder::CreateVGPR(dbt::qir::VType) const (me/git/rv32jit/build/rv32jit+0x1cd5ed) (BuildId: d5f40ebc9e253e729fadf45522801b8f8372a477)

And nqueens.elf said:

Running build/nqueens.elf ...
<---  N-Queens Solutions  --->
 N:        Total       Unique
 2:            0            0
 3:            0            0
 4:            2            1
 5:           10            2
 6:            4            1
 7:           40            6
 8:           92           12
 9:          352           46
10:          724           92
11:         2680          341
12:        14200         1787
13:        73712         9233
14:       365596        45752
15:      2279184       285053

=================================================================
==33144==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1343 byte(s) in 293 object(s) allocated from:
    #0 0x559fd52d8c82 in operator new(unsigned long) (me/git/rv32jit/build/rv32jit+0x16ac82) (BuildId: d5f40ebc9e253e729fadf45522801b8f8372a477)
    #1 0x559fd533b5ed in dbt::qir::Builder::CreateVGPR(dbt::qir::VType) const (me/git/rv32jit/build/rv32jit+0x1cd5ed) (BuildId: d5f40ebc9e253e729fadf45522801b8f8372a477)

and so on.

Would you like to use the smart pointer to replace the new operator?
(Actually, it would be std::shared_ptr and std::weak_ptr, I found there are some caching mechanisms that would need some gc here)

Cannot find debug info with gdb using debug build `-g`

Reproducing steps:

  1. Add debugging option in Makefile
    vim Makefile add -g option in CXXFLAGS
  2. Recompile cpp code
    run make clean and make
  3. Run gdb
    gdb --args ./build/rv32jit build/aes.elf

Error message shown as follows:

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./build/rv32jit...
Dwarf Error: DW_FORM_strx1 found in non-DWO CU [in module /home/livlig/ypaskellPlayground/rv32jit/build/rv32jit]
(No debugging symbols found in ./build/rv32jit)
(gdb) 

Use "clang++-15" only or "clang++" 15 and higher?

The README said "You will need clang version 15+ for the build". However the Makefile is hard-coded clang++-15.

Would you like to use some checks like:

CXX := clang++

# checking CXX version is 15 or higher
CXX_VERSION := $(shell $(CXX) --version | grep -oP 'clang version \K\d+')

ifeq ($(shell echo "$(CXX_VERSION) >= 15" | bc), 1)
    $(info clang++ version is 15 or higher)
else
    $(error clang++ version is below 15)
endif

Drop the dependency on libelf

At present, libelf is used for parsing and reading given ELF files, but it is a bit heavy. Measuring on Ubuntu Linux 20.04, the stripped libelf occupies 107KB in file size, while the stripped rv32jit executable (AsmJit is statically linked into rv32jit) is 280KB in size. Since we do not need the full functionality of libelf, we can follow the approach that rv32emu uses to deal with ELF files. This involves implementing the necessary facilities on our own, without the need for external libraries such as libelf. This issue is about dropping the libelf dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.