Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code built with address sanitizer crashes when running in qemu-user #1683

Open
yuv418 opened this issue Mar 3, 2025 · 1 comment
Open

Code built with address sanitizer crashes when running in qemu-user #1683

yuv418 opened this issue Mar 3, 2025 · 1 comment

Comments

@yuv418
Copy link

yuv418 commented Mar 3, 2025

Hello, we're trying to cross compile some RISCV code and run it in qemu-user. For testing, it is helpful to have address sanitizer enabled. We used the following:

./configure --prefix=$RV64PREFIX --with-arch=rv64gc --with-abi=lp64 --enable-libsanitizer

Here's a test C program which ASan should say has a memory leak:

#include <stdio.h>
#include <stdlib.h>

int main() {
	int* q = malloc(32);
	printf("%p\n", q);
}

Now, we compile test.c and run as follows:

$RV64PREFIX/bin/riscv64-unknown-linux-gnu-gcc  -fsanitize=address test.c
qemu-riscv64 -L  $RV64PREFIX/sysroot/ ./a.out

Which is then met with the following:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==2608716==ERROR: AddressSanitizer: SEGV on unknown address 0x0015556500f8 (pc 0x0040008d0938 bp 0x0040008007b0 sp 0x0040007fff60 T-1)
==2608716==The signal is caused by a READ memory access.
AddressSanitizer: CHECK failed: asan_suppressions.cpp:47 "((suppression_ctx)) != (0)" (0x0, 0x0) (tid=2608716)
AddressSanitizer: CHECK failed: asan_suppressions.cpp:47 "((suppression_ctx)) != (0)" (0x0, 0x0) (tid=2608716)
Trace/breakpoint trap

Unfortunately, it's been hard to debug this from time constraints. My first thought is to find out whether or not this is something caused by a misconfiguration or an upstream issue where ASan straight up doesn't support running in qemu-user on RISCV.

For what it's worth, I also built a different toolchain with ./configure --prefix=$RV64PREFIX --enable-llvm --enable-linux --enable-libsanitizer, which from my understanding builds for rv64gc/lp64d. Compiling with ASan in both Clang and GCC in this configuration yields the same error as above.

As a stopgap, we've built Valgrind for RISCV, but even that's from my understanding still a WIP and there have been some bugs.

Either way, any pointers in the right direction would be appreciated.

@TommyMurphyTM1234
Copy link
Collaborator

You'll probably need to report/discuss this in the upstream QEMU project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants