#3739: Support aarch64 natives

This commit is contained in:
Outfluencer 2024-09-08 09:11:05 +10:00 committed by md_5
parent 8f8c270f3b
commit eca6090f1e
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
5 changed files with 48 additions and 2 deletions

29
native/compile-native-arm.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
set -eu
CWD=$(pwd)
echo "Compiling mbedtls"
(cd mbedtls && CFLAGS="-fPIC -I$CWD/src/main/c -DMBEDTLS_USER_CONFIG_FILE='<mbedtls_custom_config.h>'" make CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar no_test)
echo "Compiling zlib"
(cd zlib && CFLAGS="-fPIC -DNO_GZIP" CC=aarch64-linux-gnu-gcc CHOST=arm64 ./configure --target="aarch64" --static && make CFLAGS="-fPIC -march=armv8-a+crc" CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar)
CC="aarch64-linux-gnu-gcc"
CFLAGS="-c -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/"
LDFLAGS="-shared"
echo "Compiling bungee"
$CC $CFLAGS -o shared.o src/main/c/shared.c
$CC $CFLAGS -Imbedtls/include -o NativeCipherImpl.o src/main/c/NativeCipherImpl.c
$CC $CFLAGS -Izlib -o NativeCompressImpl.o src/main/c/NativeCompressImpl.c
echo "Linking native-cipher-arm.so"
$CC $LDFLAGS -o src/main/resources/native-cipher-arm.so shared.o NativeCipherImpl.o mbedtls/library/libmbedcrypto.a
echo "Linking native-compress-arm.so"
$CC $LDFLAGS -o src/main/resources/native-compress-arm.so shared.o NativeCompressImpl.o zlib/libz.a
echo "Cleaning up"
rm shared.o NativeCipherImpl.o NativeCompressImpl.o

View File

@ -3,7 +3,9 @@
#include <zlib.h> #include <zlib.h>
#include "shared.h" #include "shared.h"
#if !defined(__aarch64__)
#include "cpuid_helper.h" #include "cpuid_helper.h"
#endif
#include "net_md_5_bungee_jni_zlib_NativeCompressImpl.h" #include "net_md_5_bungee_jni_zlib_NativeCompressImpl.h"
typedef unsigned char byte; typedef unsigned char byte;
@ -28,7 +30,11 @@ jint throwException(JNIEnv *env, const char* message, int err) {
} }
JNIEXPORT jboolean JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_checkSupported(JNIEnv* env, jobject obj) { JNIEXPORT jboolean JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_checkSupported(JNIEnv* env, jobject obj) {
return (jboolean) checkCompressionNativesSupport(); #if !defined(__aarch64__)
return (jboolean) checkCompressionNativesSupport();
#else
return JNI_TRUE;
#endif
} }
void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_reset(JNIEnv* env, jobject obj, jlong ctx, jboolean compress) { void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_reset(JNIEnv* env, jobject obj, jlong ctx, jboolean compress) {

View File

@ -43,6 +43,7 @@ public final class NativeCode<T>
{ {
if ( enableNativeFlag && !loaded && isSupported() ) if ( enableNativeFlag && !loaded && isSupported() )
{ {
String name = this.name + ( isAarch64() ? "-arm" : "" );
String fullName = "bungeecord-" + name; String fullName = "bungeecord-" + name;
try try
@ -94,6 +95,16 @@ public final class NativeCode<T>
public static boolean isSupported() public static boolean isSupported()
{ {
return "Linux".equals( System.getProperty( "os.name" ) ) && "amd64".equals( System.getProperty( "os.arch" ) ); return "Linux".equals( System.getProperty( "os.name" ) ) && ( isAmd64() || isAarch64() );
}
private static boolean isAmd64()
{
return "amd64".equals( System.getProperty( "os.arch" ) );
}
private static boolean isAarch64()
{
return "aarch64".equals( System.getProperty( "os.arch" ) );
} }
} }

Binary file not shown.

Binary file not shown.