From fc9823a4afeef908addf8ab12155bee888bbc35b Mon Sep 17 00:00:00 2001
From: Simon Frankenberger <simon-alpine@fraho.eu>
Date: Tue, 11 Jul 2023 05:59:52 +0200
Subject: [PATCH] testing/openjdk21: new aport

---
 testing/openjdk21/APKBUILD                    | 288 ++++++++++++++++++
 .../JDK-8218814_Wformat-security.patch        |  17 ++
 .../openjdk21/JDK-8299245_disable-tests.patch |  53 ++++
 testing/openjdk21/ppc64le.patch               | 177 +++++++++++
 4 files changed, 535 insertions(+)
 create mode 100644 testing/openjdk21/APKBUILD
 create mode 100644 testing/openjdk21/JDK-8218814_Wformat-security.patch
 create mode 100644 testing/openjdk21/JDK-8299245_disable-tests.patch
 create mode 100644 testing/openjdk21/ppc64le.patch

diff --git a/testing/openjdk21/APKBUILD b/testing/openjdk21/APKBUILD
new file mode 100644
index 000000000000..37d1c8371daa
--- /dev/null
+++ b/testing/openjdk21/APKBUILD
@@ -0,0 +1,288 @@
+# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
+# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
+pkgname=openjdk21
+pkgver=21.0.0_p35
+#_pkgver=${pkgver%_p*}-ga
+_pkgver=21+35
+pkgrel=0
+pkgdesc="Oracle OpenJDK 21"
+provider_priority=21
+url="https://github.com/openjdk/jdk21u"
+arch="all !ppc64le !x86 !armhf !armv7 !riscv64" # oracle dropped support for 32 bit
+license="GPL-2.0-with-classpath-exception"
+makedepends="autoconf
+	bash
+	gawk
+	grep
+	make
+	openjdk20-jdk
+	zip
+	alsa-lib-dev
+	cups-dev
+	elfutils-dev
+	fontconfig-dev
+	freetype-dev
+	giflib-dev
+	lcms2-dev
+	libffi-dev
+	libjpeg-turbo-dev
+	libx11-dev
+	libxext-dev
+	libxrandr-dev
+	libxrender-dev
+	libxt-dev
+	libxtst-dev
+	linux-headers
+	zlib-dev"
+depends="$pkgname-jdk $pkgname-demos $pkgname-doc" # for the virtual openjdk18 package
+subpackages="$pkgname-jmods:_jmods:noarch
+	$pkgname-demos:_demos:noarch
+	$pkgname-doc:_doc:noarch
+	$pkgname-jre:_jre
+	$pkgname-src:_src:noarch
+	$pkgname-static-libs:_static_libs
+	$pkgname-jre-headless:_jre_headless
+	$pkgname-jdk:_jdk
+	"
+	#JDK-8282306_disable-test.patch
+source="jdk-$_pkgver.tar.gz::https://github.com/openjdk/jdk21u/archive/jdk-$_pkgver.tar.gz
+	gtest-1.13.0.tar.gz::https://github.com/google/googletest/archive/v1.13.0.tar.gz
+
+	ppc64le.patch
+	JDK-8299245_disable-tests.patch
+	JDK-8218814_Wformat-security.patch
+"
+builddir="$srcdir/jdk21u-jdk-${_pkgver/+/-}"
+
+_java_home="/usr/lib/jvm/java-21-openjdk"
+
+ldpath="$_java_home/lib:$_java_home/lib/server"
+sonameprefix="$pkgname:"
+
+# enable running the JTReg tests in check?
+# see comment in that function for explanation
+_run_jtreg=${_run_jtreg:-0}
+if [ $_run_jtreg -ne 0 ]; then
+	makedepends="$makedepends java-jtreg"
+	checkdepends="$checkdepends ttf-freefont xvfb-run"
+fi
+
+build() {
+	if [ $_run_jtreg -ne 0 ]; then
+		_with_jtreg="--with-jtreg=/usr/share/java/jtreg"
+	else
+		_with_jtreg="--with-jtreg=no"
+	fi
+
+	if [ -n "$USE_CCACHE" ]; then
+		# workaround ccache being disallowed
+		export PATH="/usr/bin:/bin:/sbin:/usr/sbin"
+		local ccache="--enable-ccache"
+	fi
+
+	# CFLAGS, CXXFLAGS and LDFLAGS are ignored as shown by a warning
+	# in the output of ./configure unless used like such:
+	#  --with-extra-cflags="$CFLAGS"
+	#  --with-extra-cxxflags="$CXXFLAGS"
+	#  --with-extra-ldflags="$LDFLAGS"
+	# See also paragraph "Configure Control Variables" from "common/doc/building.md"
+	# shellcheck disable=2097 disable=2098
+	CFLAGS='' CXXFLAGS='' LDFLAGS='' \
+		bash ./configure \
+		--build=$CBUILD \
+		--host=$CHOST \
+		--target=$CTARGET \
+		--prefix="$_java_home" \
+		--sysconfdir=/etc \
+		--mandir=/usr/share/man \
+		--infodir=/usr/share/info \
+		--localstatedir=/var \
+		--with-extra-cflags="$CFLAGS -D_LARGEFILE64_SOURCE" \
+		--with-extra-cxxflags="$CXXFLAGS -D_LARGEFILE64_SOURCE" \
+		--with-extra-ldflags="$LDFLAGS" \
+		--with-zlib=system \
+		--with-libjpeg=system \
+		--with-giflib=system \
+		--with-libpng=system \
+		--with-lcms=system \
+		--with-jobs=${JOBS:-4} \
+		--with-test-jobs=${JOBS:-4} \
+		--with-native-debug-symbols=none \
+		--with-gtest=../googletest-1.13.0 \
+		$ccache \
+		$_with_jtreg \
+		--disable-warnings-as-errors \
+		--disable-precompiled-headers \
+		--enable-dtrace=no \
+		--with-jvm-variants=server \
+		--with-debug-level=release \
+		--with-version-pre= \
+		--with-version-opt="alpine-r$pkgrel" \
+		--with-version-build="${pkgver##*p}" \
+		--with-vendor-name="Alpine" \
+		--with-vendor-url="https://alpinelinux.org/" \
+		--with-vendor-bug-url="https://gitlab.alpinelinux.org/alpine/aports/issues" \
+		--with-vendor-vm-bug-url="https://gitlab.alpinelinux.org/alpine/aports/issues"
+	MAKEFLAGS='' make jdk-image
+	MAKEFLAGS='' make static-libs-image
+}
+
+check() {
+	# run the gtest unittest suites
+	# they don't take long, DO NOT DISABLE THEM!
+	# override make variable, disable -Werror
+	MAKEFLAGS='' make test-hotspot-gtest
+
+	# The jtreg tests take very, very long to finish and show some failures (9 - 12 on my machine, varying between runs)
+	# I think these are not critical and can be safely ignored.
+	# As the tests take too long, they are disabled by default.
+	# When updating this aport please let them run at least once on your machine to see if the failure count changes.
+	if [ $_run_jtreg -ne 0 ]; then
+		_logfile=$( mktemp -p "$builddir" )
+		MAKEFLAGS='' xvfb-run make \
+			run-test-tier1 \
+			run-test-tier2 \
+			run-test-tier3 \
+			| tee "$_logfile"
+		msg "---------------------------------------"
+		msg "The build log can be found at $_logfile"
+		# abort the build so you may take a look at the logfile
+		false
+		return 1
+	fi
+}
+
+package() {
+	local libstaticdir="lib/static/linux-${CARCH/x86_64/amd64}/musl"
+
+	mkdir -p "$pkgdir/$_java_home/$libstaticdir"
+
+	cd build/linux-*-server-release/images/
+	cp -r jdk/* "$pkgdir/$_java_home"
+	cp -r static-libs/lib/* "$pkgdir/$_java_home/$libstaticdir"
+}
+
+_jmods() {
+	pkgdesc="Oracle OpenJDK 21 (jmods)"
+	depends=""
+	_fromroot="$pkgdir/$_java_home"
+	_toroot="$subpkgdir/$_java_home"
+
+	mkdir -p "$_toroot"
+	mv "$_fromroot/jmods" "$_toroot"
+}
+
+_demos() {
+	pkgdesc="Oracle OpenJDK 21 (demos)"
+	depends=""
+	_fromroot="$pkgdir/$_java_home"
+	_toroot="$subpkgdir/$_java_home"
+
+	mkdir -p "$_toroot"
+	mv "$_fromroot/demo" "$_toroot"
+}
+
+_doc() {
+	pkgdesc="Oracle OpenJDK 21 (Documentation)"
+	depends=""
+	_fromroot="$pkgdir/$_java_home"
+	_toroot="$subpkgdir/$_java_home"
+
+	mkdir -p "$_toroot"
+	mv "$_fromroot/man" "$_toroot"
+}
+
+_jre() {
+	pkgdesc="Oracle OpenJDK 21 (JRE)"
+	depends="$pkgname-jre-headless"
+	provides=java-jre
+	_fromroot="$pkgdir/$_java_home"
+	_toroot="$subpkgdir/$_java_home"
+
+	mkdir -p "$_toroot/lib"
+	mv "$_fromroot/lib/libawt_xawt.so" \
+		"$_fromroot/lib/libfontmanager.so" \
+		"$_fromroot/lib/libjavajpeg.so" \
+		"$_fromroot/lib/libjawt.so" \
+		"$_fromroot/lib/libjsound.so" \
+		"$_fromroot/lib/liblcms.so" \
+		"$_fromroot/lib/libsplashscreen.so" \
+		"$_toroot/lib"
+}
+
+_src() {
+	pkgdesc="Oracle OpenJDK 21 (sources)"
+	depends="$pkgname-jre-headless"
+	mkdir -p "$subpkgdir/$_java_home"/lib
+	mv "$pkgdir"/$_java_home/lib/src.zip \
+		"$subpkgdir"/$_java_home/lib/
+}
+
+_static_libs() {
+	pkgdesc="Oracle OpenJDK 21 libraries for static linking"
+	provides="java-jdk-static-libs"
+	depends="$pkgname=$pkgver-r$pkgrel"
+
+	amove $_java_home/lib/static
+}
+
+_jre_headless() {
+	pkgdesc="Oracle OpenJDK 21 (JRE headless)"
+	depends="java-common java-cacerts"
+	provides=java-jre-headless
+	_fromroot="$pkgdir/$_java_home"
+	_toroot="$subpkgdir/$_java_home"
+
+	mkdir -p "$_toroot"
+	mv "$_fromroot/lib" "$_toroot"
+
+	# ct.sym should stay in -jdk
+	mkdir "$_fromroot/lib"
+	mv "$_toroot/lib/ct.sym" "$_fromroot/lib"
+
+	mkdir -p "$_toroot/bin"
+	for i in java \
+		jfr \
+		jrunscript \
+		jwebserver \
+		keytool \
+		rmiregistry; do
+		mv "$_fromroot/bin/$i" "$_toroot/bin/$i"
+	done
+
+	mv "$_fromroot/legal"              "$_toroot"
+	mv "$_fromroot/conf"               "$_toroot"
+	mv "$_fromroot/release"            "$_toroot"
+	cp "$builddir/ASSEMBLY_EXCEPTION"  "$_toroot"
+	cp "$builddir/LICENSE"             "$_toroot"
+	cp "$builddir/README.md"           "$_toroot"
+
+	# symlink to shared cacerts store
+	rm "$_toroot/lib/security/cacerts"
+	ln -sf /etc/ssl/certs/java/cacerts \
+		"$_toroot/lib/security/cacerts"
+
+	# symlink for java-common to work (expects jre in $_java_home/jre)
+	ln -sf . "$_toroot/jre"
+}
+
+_jdk() {
+	pkgdesc="Oracle OpenJDK 21 (JDK)"
+	depends="$pkgname-jre $pkgname-jmods"
+	provides=java-jdk
+	_fromroot="$pkgdir/$_java_home"
+	_toroot="$subpkgdir/$_java_home"
+
+	mkdir -p "$_toroot"
+	mv "$_fromroot/bin" "$_toroot"
+	mv "$_fromroot/lib" "$_toroot"
+	mv "$_fromroot/include" "$_toroot"
+}
+
+sha512sums="
+492a37fc73fda00c95e388e5ed894ed35f1631057401b4c5f7943a73f544fa595f1e89846b64dd7b757cea509d50d5e3a76b7e73d931a26ea9e5f20b89975572  jdk-21+35.tar.gz
+70c0cfb1b4147bdecb467ecb22ae5b5529eec0abc085763213a796b7cdbd81d1761d12b342060539b936fa54f345d33f060601544874d6213fdde79111fa813e  gtest-1.13.0.tar.gz
+40d83692dd5bafdfa92032f6d02b07bd822011e4f252c9fbf44a9e3c6d0f5536eb43aa486eb9a6ff7bbef00dc46de08a89878d0c444674e0125430959011a479  ppc64le.patch
+403862d6e6919f40d705c59463e9d6ecc5ac5b3f95e107a7e91f84d64068176e4abe7b63f15ba8fc9b4ab2f1ab58f3a489e07716e4c370356e40c2699e870b4f  JDK-8299245_disable-tests.patch
+218217c4f0e41f709deff812e3b5dd80bf9b98935ba637f83b88a70773fefc08639a13c8072173921cd6e5605fb6e8b328758759683e7cfd3758d4bbc10a5a88  JDK-8218814_Wformat-security.patch
+"
diff --git a/testing/openjdk21/JDK-8218814_Wformat-security.patch b/testing/openjdk21/JDK-8218814_Wformat-security.patch
new file mode 100644
index 000000000000..95a54d9a09d5
--- /dev/null
+++ b/testing/openjdk21/JDK-8218814_Wformat-security.patch
@@ -0,0 +1,17 @@
+Author: Simon Frankenberger <simon-alpine@fraho.eu>
+Subject: Fix compilation of jtreg / gtest objects with -Werror=format-security CFLAGS
+Upstream: Yes / closed unresolved (https://bugs.openjdk.org/browse/JDK-8218814)
+
+Remove the -Wno-format CLFAG for test objects
+
+--- old/make/common/TestFilesCompilation.gmk	2023-07-11 17:28:44.345270760 +0200
++++ new/make/common/TestFilesCompilation.gmk	2023-07-11 17:29:57.941716556 +0200
+@@ -100,7 +100,7 @@
+         CFLAGS := $$($1_BASE_CFLAGS) $$($1_CFLAGS) $$($1_CFLAGS_$$(name)), \
+         CXXFLAGS := $$($1_BASE_CXXFLAGS) $$($1_CFLAGS) $$($1_CFLAGS_$$(name)), \
+         LDFLAGS := $$($1_LDFLAGS) $$($1_LDFLAGS_$$(name)), \
+-        DISABLED_WARNINGS_gcc := format undef unused-function unused-value, \
++        DISABLED_WARNINGS_gcc := undef unused-function unused-value, \
+         DISABLED_WARNINGS_clang := undef format-nonliteral \
+             missing-field-initializers sometimes-uninitialized, \
+         LIBS := $$($1_LIBS_$$(name)), \
diff --git a/testing/openjdk21/JDK-8299245_disable-tests.patch b/testing/openjdk21/JDK-8299245_disable-tests.patch
new file mode 100644
index 000000000000..907fd3a6edea
--- /dev/null
+++ b/testing/openjdk21/JDK-8299245_disable-tests.patch
@@ -0,0 +1,53 @@
+Author: Simon Frankenberger <simon-alpine@fraho.eu>
+Subject: Disable failing tests
+Upstream: Yes (https://bugs.openjdk.org/browse/JDK-8299245)
+
+"Some gtests do not work well in non-debug build"
+Disable failing tests as workaround
+
+--- old/test/hotspot/gtest/runtime/test_os_linux.cpp
++++ new/test/hotspot/gtest/runtime/test_os_linux.cpp
+@@ -439,6 +439,7 @@
+ 
+ #if !defined(__clang_major__) || (__clang_major__ >= 5) // DWARF does not support Clang versions older than 5.0.
+ // Test valid address of method ReportJNIFatalError in jniCheck.hpp. We should get "jniCheck.hpp" in the buffer and a valid line number.
++#if 0
+ TEST_VM(os_linux, decoder_get_source_info_valid) {
+   char buf[128] = "";
+   int line = -1;
+@@ -447,6 +448,7 @@
+   ASSERT_TRUE(strcmp(buf, "jniCheck.hpp") == 0);
+   ASSERT_TRUE(line > 0);
+ }
++#endif
+ 
+ // Test invalid addresses. Should not cause harm and output buffer and line must contain "" and -1, respectively.
+ TEST_VM(os_linux, decoder_get_source_info_invalid) {
+@@ -466,6 +468,7 @@
+ 
+ // Test with valid address but a too small buffer to store the entire filename. Should find generic <OVERFLOW> message
+ // and a valid line number.
++#if 0
+ TEST_VM(os_linux, decoder_get_source_info_valid_overflow) {
+   char buf[11] = "";
+   int line = -1;
+@@ -474,9 +477,11 @@
+   ASSERT_TRUE(strcmp(buf, "<OVERFLOW>") == 0);
+   ASSERT_TRUE(line > 0);
+ }
++#endif
+ 
+ // Test with valid address but a too small buffer that can neither store the entire filename nor the generic <OVERFLOW>
+ // message. We should find "L" as filename and a valid line number.
++#if 0
+ TEST_VM(os_linux, decoder_get_source_info_valid_overflow_minimal) {
+   char buf[2] = "";
+   int line = -1;
+@@ -485,6 +490,7 @@
+   ASSERT_TRUE(strcmp(buf, "L") == 0); // Overflow message does not fit, so we fall back to "L:line_number"
+   ASSERT_TRUE(line > 0); // Line should correctly be found and returned
+ }
++#endif
+ #endif // clang
+ 
+ #ifdef __GLIBC__
diff --git a/testing/openjdk21/ppc64le.patch b/testing/openjdk21/ppc64le.patch
new file mode 100644
index 000000000000..3d18bcaa5d3e
--- /dev/null
+++ b/testing/openjdk21/ppc64le.patch
@@ -0,0 +1,177 @@
+diff -ru old/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp new/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp
+--- old/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp	2023-07-11 05:46:53.695833944 +0200
++++ new/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp	2023-07-11 05:47:46.082286878 +0200
+@@ -47,6 +47,10 @@
+ #include "utilities/macros.hpp"
+ #include "utilities/powerOfTwo.hpp"
+ 
++#if ! (defined(__GLIBC__) || defined(__UCLIBC__))
++#include <asm/ptrace.h>
++#endif
++
+ #ifdef PRODUCT
+ #define BLOCK_COMMENT(str) // nothing
+ #else
+diff -ru old/src/hotspot/cpu/ppc/vm_version_ppc.cpp new/src/hotspot/cpu/ppc/vm_version_ppc.cpp
+--- old/src/hotspot/cpu/ppc/vm_version_ppc.cpp	2023-07-11 05:46:53.699834128 +0200
++++ new/src/hotspot/cpu/ppc/vm_version_ppc.cpp	2023-07-11 05:47:46.082286878 +0200
+@@ -53,6 +53,10 @@
+ #endif
+ #endif
+ 
++#if ! (defined(__GLIBC__) || defined(__UCLIBC__))
++#include <asm/ptrace.h>
++#endif
++
+ bool VM_Version::_is_determine_features_test_running = false;
+ uint64_t VM_Version::_dscr_val = 0;
+ 
+@@ -687,7 +691,7 @@
+   unsigned long auxv = getauxval(AT_HWCAP2);
+ 
+   if (auxv & PPC_FEATURE2_HTM_NOSC) {
+-    if (auxv & PPC_FEATURE2_HAS_HTM) {
++    if (auxv & PPC_FEATURE2_HTM) {
+       // TM on POWER8 and POWER9 in compat mode (VM) is supported by the JVM.
+       // TM on POWER9 DD2.1 NV (baremetal) is not supported by the JVM (TM on
+       // POWER9 DD2.1 NV has a few issues that need a couple of firmware
+diff -ru old/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp new/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp
+--- old/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp	2023-07-11 05:46:53.743836141 +0200
++++ new/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp	2023-07-11 05:54:46.319138789 +0200
+@@ -78,6 +78,10 @@
+ # include <poll.h>
+ # include <ucontext.h>
+ 
++#if ! (defined(__GLIBC__) || defined(__UCLIBC__))
++#include <asm/ptrace.h>
++#endif
++
+ 
+ address os::current_stack_pointer() {
+   return (address)__builtin_frame_address(0);
+@@ -105,24 +109,42 @@
+   // - if uc was filled by getcontext(), it is undefined - getcontext() does not fill
+   //   it because the volatile registers are not needed to make setcontext() work.
+   //   Hopefully it was zero'd out beforehand.
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+   guarantee(uc->uc_mcontext.regs != nullptr, "only use ucontext_get_pc in sigaction context");
+   return (address)uc->uc_mcontext.regs->nip;
++#else // Musl
++  guarantee(uc->uc_mcontext.gp_regs != NULL, "only use ucontext_get_pc in sigaction context");
++  return (address)uc->uc_mcontext.gp_regs[PT_NIP];
++#endif
+ }
+ 
+ // modify PC in ucontext.
+ // Note: Only use this for an ucontext handed down to a signal handler. See comment
+ // in ucontext_get_pc.
+ void os::Posix::ucontext_set_pc(ucontext_t * uc, address pc) {
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+   guarantee(uc->uc_mcontext.regs != nullptr, "only use ucontext_set_pc in sigaction context");
+   uc->uc_mcontext.regs->nip = (unsigned long)pc;
++#else // Musl
++  guarantee(uc->uc_mcontext.gp_regs != NULL, "only use ucontext_set_pc in sigaction context");
++  uc->uc_mcontext.gp_regs[PT_NIP] = (unsigned long)pc;
++#endif
+ }
+ 
+ static address ucontext_get_lr(const ucontext_t * uc) {
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+   return (address)uc->uc_mcontext.regs->link;
++#else // Musl
++  return (address)uc->uc_mcontext.gp_regs[PT_LNK];
++#endif
+ }
+ 
+ intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+   return (intptr_t*)uc->uc_mcontext.regs->gpr[1/*REG_SP*/];
++#else // Musl
++  return (intptr_t*)uc->uc_mcontext.gp_regs[1/*REG_SP*/];
++#endif
+ }
+ 
+ intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
+@@ -130,7 +152,11 @@
+ }
+ 
+ static unsigned long ucontext_get_trap(const ucontext_t * uc) {
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+   return uc->uc_mcontext.regs->trap;
++#else // Musl
++  return uc->uc_mcontext.gp_regs[PT_TRAP];
++#endif
+ }
+ 
+ address os::fetch_frame_from_context(const void* ucVoid,
+@@ -196,7 +222,11 @@
+     // 3.2.1 "Machine State Register"), however note that ISA notation for bit
+     // numbering is MSB 0, so for normal bit numbering (LSB 0) they come to be
+     // bits 33 and 34. It's not related to endianness, just a notation matter.
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+     if (second_uc->uc_mcontext.regs->msr & 0x600000000) {
++#else // Musl
++    if (second_uc->uc_mcontext.gp_regs[PT_MSR] & 0x600000000) {
++#endif
+       if (TraceTraps) {
+         tty->print_cr("caught signal in transaction, "
+                         "ignoring to jump to abort handler");
+@@ -452,6 +482,7 @@
+   const ucontext_t* uc = (const ucontext_t*)context;
+ 
+   st->print_cr("Registers:");
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+   st->print("pc =" INTPTR_FORMAT "  ", uc->uc_mcontext.regs->nip);
+   st->print("lr =" INTPTR_FORMAT "  ", uc->uc_mcontext.regs->link);
+   st->print("ctr=" INTPTR_FORMAT "  ", uc->uc_mcontext.regs->ctr);
+@@ -460,6 +491,16 @@
+     st->print("r%-2d=" INTPTR_FORMAT "  ", i, uc->uc_mcontext.regs->gpr[i]);
+     if (i % 3 == 2) st->cr();
+   }
++#else // Musl
++  st->print("pc =" INTPTR_FORMAT "  ", uc->uc_mcontext.gp_regs[PT_NIP]);
++  st->print("lr =" INTPTR_FORMAT "  ", uc->uc_mcontext.gp_regs[PT_LNK]);
++  st->print("ctr=" INTPTR_FORMAT "  ", uc->uc_mcontext.gp_regs[PT_CTR]);
++  st->cr();
++  for (int i = 0; i < 32; i++) {
++    st->print("r%-2d=" INTPTR_FORMAT "  ", i, uc->uc_mcontext.gp_regs[i]);
++    if (i % 3 == 2) st->cr();
++  }
++#endif
+   st->cr();
+   st->cr();
+ }
+@@ -495,17 +536,33 @@
+     continuation = n + 1;
+     switch (n) {
+     case 0:
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+       st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.regs->nip);
++#else // Musl
++      st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.gp_regs[PT_NIP]);
++#endif
+       break;
+     case 1:
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+       st->print("lr ="); print_location(st, (intptr_t)uc->uc_mcontext.regs->link);
++#else // Musl
++      st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.gp_regs[PT_LINK]);
++#endif
+       break;
+     case 2:
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+       st->print("ctr ="); print_location(st, (intptr_t)uc->uc_mcontext.regs->ctr);
++#else // Musl
++      st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.gp_regs[PT_CTR]);
++#endif
+       break;
+     default:
+       st->print("r%-2d=", n-3);
++#if defined(__GLIBC__) || defined(__UCLIBC__)
+       print_location(st, (intptr_t)uc->uc_mcontext.regs->gpr[n-3]);
++#else // Musl
++      print_location(st, (intptr_t)uc->uc_mcontext.gp_regs[n-3]);
++#endif
+       break;
+     }
+     ++n;
-- 
GitLab