jserv / rv32jit

JIT-accelerated RISC-V instruction set simulator
MIT License
30 stars 7 forks source link

Memory leaking issues #5

Open 25077667 opened 11 months ago

25077667 commented 11 months ago

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)

jserv commented 11 months ago

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)

Please go ahead with C++ smart pointers. Do change the necessary macros accordingly.

pukhovv commented 2 months ago

QuickIR compiler uses Arena chunks, it is just a mistake, use Arena instead of STL allocator :-)