Cross compiling hsdis for RISC-V

Zixian Cai zixian.cai at
Sun Oct 9 06:55:41 UTC 2022

Hi all,

I made a mistake. I used the binutils version on the FSF wiki , which is neither the latest nor what’s supported by hsdis. I built binutils-2.37 per hsdis/, and everything works fine now.


On 9/10/2022, 17:39, "riscv-port-dev" <riscv-port-dev-retn at> wrote:
Hi all,

I’m just wondering how I can cross compile hsdis for RISC-V.
I downloaded the source of binutils-2.36.1, and configured jdk.

bash configure --openjdk-target=riscv64-linux-gnu --with-sysroot=../sysroot-riscv64/ --with-boot-jdk=/usr/lib/jvm/temurin-19-jdk-amd64 --with-debug-level=slowdebug --with-jvm-variants=server --disable-warnings-as-errors --with-hsdis=binutils --with-binutils-src=$PWD/../binutils-2.36.1

OpenJDK configure exited with error when configuring binutils, because binutils wants to be configured with --host when cross compiling.
I workarounded the problem by configuring and building binutils manually, so OpenJDK configure will skip building binutils.
The flags I used are from jdk/make/autoconf/lib-hsdis.m4

./configure --host=riscv64-linux-gnu --disable-nls CFLAGS="  -fPIC -O0"
make -j

I then run jdk configure again, and build jdk with hsdis.
make CONF=linux-riscv64-server-slowdebug install-hsdis

The build succeeded. But when I try to run a program, JVM will crash with the following backtrace.

/mnt/jdk/build/linux-riscv64-server-slowdebug/jdk/bin/java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints -XX:+PrintStubCode -Xint -version

- - - [BEGIN] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ICache::fake_stub_for_inlined_icache_flush [0x00007fff95000080, 0x00007fff95000084] (4 bytes)
# A fatal error has been detected by the Java Runtime Environment:
#  SIGSEGV (0xb) at pc=0x00007fff9d467e84, pid=14142, tid=14143

The backtrace is as follows.

Current thread (0x00007fffa8028f30):  JavaThread "Unknown thread" [_thread_in_vm, id=13140, stack(0x00007fffaee75000,0x00007fffaf075000)]

Stack: [0x00007fffaee75000,0x00007fffaf075000],  sp=0x00007fffaf072560,  free space=2037k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  []  riscv_get_disassembler+0x1c
C  []  disassembler+0x36
C  []  setup_app_data+0x110
C  []  decode+0x2c
C  []  decode_instructions_virtual+0xbc
V  []  decode_env::decode_instructions(unsigned char*, unsigned char*, unsigned char*)+0x238
V  []  Disassembler::decode(unsigned char*, unsigned char*, outputStream*, AsmRemarks const*, long)+0x10c
V  []  StubCodeGenerator::stub_epilog(StubCodeDesc*)+0xea
V  []  StubCodeMark::~StubCodeMark()+0x124
V  []  ICacheStubGenerator::generate_icache_flush(int (**)(unsigned char*, int, int))+0x72
V  []  AbstractICache::initialize()+0x9a
V  []  icache_init()+0xc
V  []  CodeCache::initialize()+0x1ba
V  []  codeCache_init()+0xc
V  []  init_globals()+0x38
V  []  Threads::create_vm(JavaVMInitArgs*, bool*)+0x348
V  []  JNI_CreateJavaVM_inner(JavaVM_**, void**, void*)+0xe0
V  []  JNI_CreateJavaVM+0x2a
C  []  InitializeJVM+0x118  (java.c:1457)
C  []  JavaMain+0xa0  (java.c:413)
C  []  ThreadJavaMain+0x24  (java_md.c:650)
C  []
C  []

siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000350

FWIW, if I use the hsdis from <><>, everything works fine.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the riscv-port-dev mailing list