Cross compiling hsdis for RISC-V

Ludovic Henry ludovic at rivosinc.com
Wed Oct 12 09:57:51 UTC 2022


Hi,

I've made a local patch to be able to cross-compile hsdis based on binutils
at
https://github.com/rivosinc/jdk/commit/4c88e66b654e4c29ede7c221d223298497fa06c2

I'm blocked on getting access to my JBS again in order to submit it
upstream. Feel free to use it in the meantime.

Thanks,
Ludovic

On Sun, Oct 9, 2022 at 8:57 AM Zixian Cai <zixian.cai at anu.edu.au> wrote:

> Hi all,
>
>
>
> I made a mistake. I used the binutils version on the FSF wiki
> https://directory.fsf.org/wiki/Binutils , which is neither the latest nor
> what’s supported by hsdis. I built binutils-2.37 per hsdis/README.md, and
> everything works fine now.
>
>
>
> Sincerely,
>
> Zixian
>
>
>
> On 9/10/2022, 17:39, "riscv-port-dev" <riscv-port-dev-retn at openjdk.org>
> 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  [hsdis-riscv64.so+0xcbe84]  riscv_get_disassembler+0x1c
>
> C  [hsdis-riscv64.so+0xc5bb6]  disassembler+0x36
>
> C  [hsdis-riscv64.so+0x3b6ea]  setup_app_data+0x110
>
> C  [hsdis-riscv64.so+0x3b0d0]  decode+0x2c
>
> C  [hsdis-riscv64.so+0x3afea]  decode_instructions_virtual+0xbc
>
> V  [libjvm.so+0x6f09c2]  decode_env::decode_instructions(unsigned char*,
> unsigned char*, unsigned char*)+0x238
>
> V  [libjvm.so+0x6f14f2]  Disassembler::decode(unsigned char*, unsigned
> char*, outputStream*, AsmRemarks const*, long)+0x10c
>
> V  [libjvm.so+0xe9c846]  StubCodeGenerator::stub_epilog(StubCodeDesc*)+0xea
>
> V  [libjvm.so+0xe9ca80]  StubCodeMark::~StubCodeMark()+0x124
>
> V  [libjvm.so+0x8cf36e]  ICacheStubGenerator::generate_icache_flush(int
> (**)(unsigned char*, int, int))+0x72
>
> V  [libjvm.so+0x8cef06]  AbstractICache::initialize()+0x9a
>
> V  [libjvm.so+0x8cf146]  icache_init()+0xc
>
> V  [libjvm.so+0x5b4e40]  CodeCache::initialize()+0x1ba
>
> V  [libjvm.so+0x5b4e6c]  codeCache_init()+0xc
>
> V  [libjvm.so+0x8e13dc]  init_globals()+0x38
>
> V  [libjvm.so+0xf3d58e]  Threads::create_vm(JavaVMInitArgs*, bool*)+0x348
>
> V  [libjvm.so+0x9f32da]  JNI_CreateJavaVM_inner(JavaVM_**, void**,
> void*)+0xe0
>
> V  [libjvm.so+0x9f34d4]  JNI_CreateJavaVM+0x2a
>
> C  [libjli.so+0x6a82]  InitializeJVM+0x118  (java.c:1457)
>
> C  [libjli.so+0x3f00]  JavaMain+0xa0  (java.c:413)
>
> C  [libjli.so+0xa050]  ThreadJavaMain+0x24  (java_md.c:650)
>
> C  [libc.so.6+0x6a450]
>
> C  [libc.so.6+0xb7ef2]
>
>
>
>
>
> siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr:
> 0x0000000000000350
>
>
>
> FWIW, if I use the hsdis from
> https://builds.shipilev.net/hsdis/hsdis-riscv64.so <
> https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbuilds.shipilev.net%2Fhsdis%2Fhsdis-riscv64.so&data=05%7C01%7Czixian.cai%40anu.edu.au%7C33c79318a1244d1202f608daa9c0f2fc%7Ce37d725cab5c46249ae5f0533e486437%7C0%7C0%7C638008943428531908%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FyJ9RFlwnkhXCWZdihUsHQtMdHlpMCqL8fo26Czakmc%3D&reserved=0>
> <https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbuilds.shipilev.net%2Fhsdis%2Fhsdis-riscv64.so&data=05%7C01%7Czixian.cai%40anu.edu.au%7C33c79318a1244d1202f608daa9c0f2fc%7Ce37d725cab5c46249ae5f0533e486437%7C0%7C0%7C638008943428531908%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FyJ9RFlwnkhXCWZdihUsHQtMdHlpMCqL8fo26Czakmc%3D&reserved=0%3e>,
> everything works fine.
>
>
>
> Sincerely,
>
> Zixian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/riscv-port-dev/attachments/20221012/bbc0f70d/attachment.htm>


More information about the riscv-port-dev mailing list