<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@DengXian";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-AU" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi all,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I made a mistake. I used the binutils version on the FSF wiki
<a href="https://directory.fsf.org/wiki/Binutils">https://directory.fsf.org/wiki/Binutils</a> , 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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span lang="EN-US">Sincerely,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Zixian</span><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">On 9/10/2022, 17:39, "riscv-port-dev" <riscv-port-dev-retn@openjdk.org> wrote:<o:p></o:p></p>
<div>
<p class="MsoNormal">Hi all,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I’m just wondering how I can cross compile hsdis for RISC-V.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I downloaded the source of binutils-2.36.1, and configured jdk.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">OpenJDK configure exited with error when configuring binutils, because binutils wants to be configured with --host when cross compiling.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I workarounded the problem by configuring and building binutils manually, so OpenJDK configure will skip building binutils.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">The flags I used are from jdk/make/autoconf/lib-hsdis.m4<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">./configure --host=riscv64-linux-gnu --disable-nls CFLAGS=" -fPIC -O0"<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">make -j<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I then run jdk configure again, and build jdk with hsdis.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">make CONF=linux-riscv64-server-slowdebug install-hsdis<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The build succeeded. But when I try to run a program, JVM will crash with the following backtrace.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">/mnt/jdk/build/linux-riscv64-server-slowdebug/jdk/bin/java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints -XX:+PrintStubCode -Xint -version<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">- - - [BEGIN] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">ICache::fake_stub_for_inlined_icache_flush [0x00007fff95000080, 0x00007fff95000084] (4 bytes)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">--------------------------------------------------------------------------------<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">#<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># A fatal error has been detected by the Java Runtime Environment:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">#<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># SIGSEGV (0xb) at pc=0x00007fff9d467e84, pid=14142, tid=14143<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">#<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The backtrace is as follows.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Current thread (0x00007fffa8028f30): JavaThread "Unknown thread" [_thread_in_vm, id=13140, stack(0x00007fffaee75000,0x00007fffaf075000)]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Stack: [0x00007fffaee75000,0x00007fffaf075000], sp=0x00007fffaf072560, free space=2037k<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [hsdis-riscv64.so+0xcbe84] riscv_get_disassembler+0x1c<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [hsdis-riscv64.so+0xc5bb6] disassembler+0x36<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [hsdis-riscv64.so+0x3b6ea] setup_app_data+0x110<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [hsdis-riscv64.so+0x3b0d0] decode+0x2c<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [hsdis-riscv64.so+0x3afea] decode_instructions_virtual+0xbc<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x6f09c2] decode_env::decode_instructions(unsigned char*, unsigned char*, unsigned char*)+0x238<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x6f14f2] Disassembler::decode(unsigned char*, unsigned char*, outputStream*, AsmRemarks const*, long)+0x10c<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0xe9c846] StubCodeGenerator::stub_epilog(StubCodeDesc*)+0xea<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0xe9ca80] StubCodeMark::~StubCodeMark()+0x124<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x8cf36e] ICacheStubGenerator::generate_icache_flush(int (**)(unsigned char*, int, int))+0x72<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x8cef06] AbstractICache::initialize()+0x9a<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x8cf146] icache_init()+0xc<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x5b4e40] CodeCache::initialize()+0x1ba<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x5b4e6c] codeCache_init()+0xc<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x8e13dc] init_globals()+0x38<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0xf3d58e] Threads::create_vm(JavaVMInitArgs*, bool*)+0x348<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x9f32da] JNI_CreateJavaVM_inner(JavaVM_**, void**, void*)+0xe0<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">V [libjvm.so+0x9f34d4] JNI_CreateJavaVM+0x2a<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [libjli.so+0x6a82] InitializeJVM+0x118 (java.c:1457)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [libjli.so+0x3f00] JavaMain+0xa0 (java.c:413)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [libjli.so+0xa050] ThreadJavaMain+0x24 (java_md.c:650)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [libc.so.6+0x6a450]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">C [libc.so.6+0xb7ef2]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000350<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">FWIW, if I use the hsdis from <a href="https://builds.shipilev.net/hsdis/hsdis-riscv64.so">
https://builds.shipilev.net/hsdis/hsdis-riscv64.so</a> <<a href="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">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></a>,
everything works fine.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Sincerely,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Zixian<o:p></o:p></p>
</div>
</div>
</body>
</html>