Bug 243265

Summary: emulators/qemu-user-static: qemu-aarch64-static SIGILL with openjdk11-bootstrap
Product: Ports & Packages Reporter: Jonathan Chen <jonc>
Component: Individual Port(s)Assignee: freebsd-emulation (Nobody) <emulation>
Status: Closed Overcome By Events    
Severity: Affects Only Me CC: mikael, smh
Priority: --- Flags: bugzilla: maintainer-feedback? (emulation)
Version: Latest   
Hardware: Any   
OS: Any   
Description Flags
patch none

Description Jonathan Chen 2020-01-11 09:40:48 UTC
I'm trying to crossbuild java/openjdk11 on FreeBSD-12/amd64 for
ARCH=aarch64. All dependencies have been built successfully, but the
build of java/openjdk11 is currently failing when the port attempts to
run "/usr/local/bootstrap-openjdk11/bin/java -version" from the
(just-built) java/bootstrap-openjdk11.

To reproduce, grab the aarch64 bootstrap from:

On a RPI3, it works as expected:
rpi3:~,10:23pm> tar xf bootstrap-openjdk11-aarch64-12-
rpi3:~,10:23pm> bootstrap-openjdk11/bin/java -version
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-1)
OpenJDK 64-Bit Server VM (build 11.0.5+10-1, mixed mode)

But on my aarch64 crossbuild environment:
root@onyx:/tmp # tar xf bootstrap-openjdk11-aarch64-12- 
root@onyx:/tmp # bootstrap-openjdk11/bin/java -version
# A fatal error has been detected by the Java Runtime Environment:
#  SIGILL (0x4) at pc=0x0000004003fa4454, pid=4506, tid=101995
# JRE version:  (11.0.5+10) (build )
# Java VM: OpenJDK 64-Bit Server VM (11.0.5+10-1, mixed mode, sharing, tiered, compressed oops, serial gc, bsd-aarch64)
# Problematic frame:
# V  [libjvm.so+0xb01454]  JVM_RaiseSignal+0x3e2158
# Core dump will be written. Default location: /tmp/java.core
# An error report file with more information is saved as:
# /tmp/hs_err_pid4506.log
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
Segmentation fault (core dumped)
Comment 1 Steven Hartland freebsd_committer 2020-01-11 10:17:47 UTC
It sounds like your actually trying to run the java built for aarch64 on your amd64 machine?

If this is the case it won't work, as the java build will include instructions for the target arch not the builders arch.

The SIGILL signal is sent to a process when it attempts to execute an illegal, malformed, unknown, or privileged instruction.
Comment 2 Jonathan Chen 2020-01-11 10:58:47 UTC
It's a crossbuild environment, used to build binaries for aarch64 on an amd64 host; with the help of binmiscctl and qemu-aarch64-static.

All the other aarch64 dependancies for openjdk11 have been built. The only one that's failing to build is java/openjdk11 itself; and I've tracked it down to SIGILL being generated by qemu-aarch64-static.
Comment 3 Mikael Urankar freebsd_committer 2020-01-11 16:07:21 UTC
duplicate bug #240037
Comment 4 Jonathan Chen 2020-01-11 17:15:07 UTC

*** This bug has been marked as a duplicate of bug 240037 ***
Comment 5 Jonathan Chen 2020-01-14 22:02:06 UTC
Workaround described in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=240037#c2 can possibly be applied to src/hotspot/os_cpu/bsd_aarch64/vm_version_bsd_aarch64.cpp in order to build a new bootstrap.
Comment 6 Mikael Urankar freebsd_committer 2020-01-15 10:53:38 UTC
Created attachment 210756 [details]

Can you try the attached patch (it's for /usr/ports/emulators/qemu-user-static-devel).
It seems to work here, I tried with this program but I haven't checked if the returned value are sane:

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <machine/armreg.h>
#include <machine/_stdint.h>

main(int argc, char **argv)
        uint64_t id_aa64isar0, id_aa64pfr0;
        id_aa64isar0 = READ_SPECIALREG(id_aa64isar0_EL1);
        id_aa64pfr0 = READ_SPECIALREG(id_aa64pfr0_EL1);

        printf("id_aa64isar0: 0x%lx, id_aa64pfr0: 0x%lx\n", id_aa64isar0, id_aa64pfr0);
        return (0);

id_aa64isar0: 0x111110012120, id_aa64pfr0: 0x110000

I haven't tried qemu-user-static.
Comment 7 Jonathan Chen 2020-01-15 21:58:54 UTC
With the patch applied, the bootstrap check completes; but the synth package builder fails further down the track with:

qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x61f9f288
/usr/local/bin/bash: line 1: 62054 Abort trap              (core dumped) /usr/local/bootstrap-openjdk11/bin/javac -g -J-XX:+UseSerialGC -J-Xms32M -J-Xmx512M -J-XX:TieredStopAtLeve
l=1 -source 9 -target 9 -XDignore.symbol.file=true -g -Xlint:all,-deprecation,-options -Werror -Xprefer:source -implicit:none -d /construction/xports/java/openjdk11/work/openjdk-j
dk11u-jdk-11.0.5-10-1/build/bsd-aarch64-normal-server-release/buildtools/langtools_tools_classes @/construction/xports/java/openjdk11/work/openjdk-jdk11u-jdk-11.0.5-10-1/build/bsd
-aarch64-normal-server-release/buildtools/langtools_tools_classes/_the.BUILD_TOOLS_LANGTOOLS_batch.tmp > >(/usr/bin/tee -a /construction/xports/java/openjdk11/work/openjdk-jdk11u-
jdk-11.0.5-10-1/build/bsd-aarch64-normal-server-release/buildtools/langtools_tools_classes/_the.BUILD_TOOLS_LANGTOOLS_batch.log) 2> >(/usr/bin/tee -a /construction/xports/java/ope
njdk11/work/openjdk-jdk11u-jdk-11.0.5-10-1/build/bsd-aarch64-normal-server-release/buildtools/langtools_tools_classes/_the.BUILD_TOOLS_LANGTOOLS_batch.log >&2)

=== Output from failing command(s) repeated here ===
* For target buildtools_langtools_tools_classes__the.BUILD_TOOLS_LANGTOOLS_batch:
qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x61f9f288
* For target hotspot_variant-server_buildtools_tools_classes__the.BUILD_JFR_TOOLS_batch:
qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x6268e888
* For target hotspot_variant-server_tools_jvmti__the.BUILD_JVMTI_TOOLS_batch:
qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x62683788
Comment 8 Mikael Urankar freebsd_committer 2020-01-16 06:50:32 UTC
yeah, that's a different bug
Comment 9 Jonathan Chen 2020-10-03 21:14:40 UTC
I've not tried this out with the latest version of qemu-user-static, as I've not been using aarch64 for a while now. Too many other shiny new toys to play with.