From f265b90357480b9e5a8343a6a50288645f98e08a Mon Sep 17 00:00:00 2001 From: Trung Nguyen <57174311+trungnt2910@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:49:56 +0000 Subject: [PATCH] build: Initial support for arm64 - Detects the current architecture based on the current machine (`uname -m` or `CMAKE_SYSETM_PROCESSOR`) instead of assuming `x86_64`. - When appropriate, distinguish between the "Unix architecture" (the one reported by `uname -m` and GCC target triples, such as `aarch64`) and the "Haiku architecture" (the one used by Haiku's toolchains, like `arm64`). --- CMakeLists.txt | 5 ++++- build_hprefix.sh | 14 ++++++++++++-- copy_objects.sh | 16 +++++++++++++--- runtime_loader/CMakeLists.txt | 6 +++--- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6072a56..39af358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,10 @@ add_custom_target(CopyHaikuObjects COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/copy_objects.sh) if(NOT DEFINED HYCLONE_ARCH) - set(HYCLONE_ARCH "x86_64") + set(HYCLONE_ARCH "${CMAKE_SYSTEM_PROCESSOR}") + if(HYCLONE_ARCH MATCHES "aarch64") + set(HYCLONE_ARCH "arm64") + endif() endif() add_compile_definitions(HYCLONE_ARCH=${HYCLONE_ARCH}) diff --git a/build_hprefix.sh b/build_hprefix.sh index 40b65d6..b944e8a 100755 --- a/build_hprefix.sh +++ b/build_hprefix.sh @@ -65,7 +65,17 @@ done SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -HAIKU_ARCH=${HAIKU_ARCH:-"x86_64"} +HAIKU_UNIX_ARCH=${HAIKU_UNIX_ARCH:-"$(uname -m)"} + +case $HAIKU_UNIX_ARCH in + "aarch64") + HAIKU_ARCH="arm64" + ;; + *) + HAIKU_ARCH=$HAIKU_UNIX_ARCH + ;; +esac + HAIKU_BUILD_ENVIRONMENT_ROOT=${HAIKU_BUILD_ENVIRONMENT_ROOT:-"$SCRIPT_DIR/.."} HAIKU_BUILD_SOURCE_DIRECTORY=${HAIKU_BUILD_SOURCE_DIRECTORY:-"$HAIKU_BUILD_ENVIRONMENT_ROOT/haiku"} HPREFIX=${HPREFIX:-"$HOME/.hprefix"} @@ -162,4 +172,4 @@ if [ ! -L "$HPREFIX/system" ]; then ln -s boot/system $HPREFIX/system fi -echo "Done" \ No newline at end of file +echo "Done" diff --git a/copy_objects.sh b/copy_objects.sh index ac2668f..8ea3cf6 100755 --- a/copy_objects.sh +++ b/copy_objects.sh @@ -1,7 +1,17 @@ #!/bin/bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -HAIKU_ARCH=${HAIKU_ARCH:-"x86_64"} +HAIKU_UNIX_ARCH=${HAIKU_UNIX_ARCH:-"$(uname -m)"} + +case $HAIKU_UNIX_ARCH in + "aarch64") + HAIKU_ARCH="arm64" + ;; + *) + HAIKU_ARCH=$HAIKU_UNIX_ARCH + ;; +esac + # TODO: This is personalized for my local environment, but making this a subdirectory of the HyClone # tree (such as "haiku-build") seems to be a better idea. HAIKU_BUILD_ENVIRONMENT_ROOT=${HAIKU_BUILD_ENVIRONMENT_ROOT:-"$SCRIPT_DIR/.."} @@ -17,9 +27,9 @@ HAIKU_GLUE="$HAIKU_BUILD_OUTPUT_ROOT/objects/haiku/$HAIKU_ARCH/release/system/gl HAIKU_GLUE_ARCH="$HAIKU_GLUE/arch/$HAIKU_ARCH" # Some distros store the GCC glue objects in lib64, others in lib. -HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib64/gcc/$HAIKU_ARCH-unknown-haiku/**) +HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib64/gcc/$HAIKU_UNIX_ARCH-unknown-haiku/**) if [ ! -f "$HAIKU_GLUE_GCC/crtbeginS.o" ]; then - HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib/gcc/$HAIKU_ARCH-unknown-haiku/**) + HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib/gcc/$HAIKU_UNIX_ARCH-unknown-haiku/**) fi # If Haiku is not built, build it! diff --git a/runtime_loader/CMakeLists.txt b/runtime_loader/CMakeLists.txt index 8cedb19..f42f517 100644 --- a/runtime_loader/CMakeLists.txt +++ b/runtime_loader/CMakeLists.txt @@ -27,7 +27,7 @@ add_custom_target(RemoveHaikuSyscalls COMMAND ar d ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_nosyscalls.a syscalls.o tls.o) add_library(runtime_loader SHARED blank.c) -target_link_options(runtime_loader PRIVATE +target_link_options(runtime_loader PRIVATE -nodefaultlibs -nostartfiles -Wl,--no-undefined,-shared,-Bsymbolic,-soname=runtime_loader,-entry=runtime_loader @@ -42,7 +42,7 @@ target_link_libraries(runtime_loader PRIVATE monika) target_link_libraries(runtime_loader PRIVATE root_os_tls) target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libgcc_eh-kernel.a) target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libgcc-kernel.a) -target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_x86_64.a) +target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_${HYCLONE_ARCH}.a) target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_nosyscalls.a) -install(TARGETS runtime_loader DESTINATION bin) \ No newline at end of file +install(TARGETS runtime_loader DESTINATION bin)