Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aarch64 #124

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ vcpkg_installed/*

### ctags ###
tags


### Misc ###
aarch64/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu*
49 changes: 49 additions & 0 deletions aarch64/clang_to_aarch64-linux-gnu.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
macro(set_if_file_exists VARIABLE_NAME VARIABLE_PATH)
if(NOT EXISTS ${VARIABLE_PATH})
message(FATAL_ERROR "${VARIABLE_PATH} does not exist")
endif()
set(${VARIABLE_NAME} ${VARIABLE_PATH})
#set(${VARIABLE_NAME} ${VARIABLE_PATH} PARENT_SCOPE)
endmacro()

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR aarch64)

SET(PATH_TO_TOOLCHAIN_BASE "${CMAKE_CURRENT_SOURCE_DIR}/aarch64/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu")
SET(PATH_TO_COMPILER_BINARIES /usr/bin)
SET(CLANG_VERSION_SUFFIX "-18")

#set_if_file_exists(CMAKE_ADDR2LINE "${PATH_TO_COMPILER_BINARIES}/aarch64-none-linux-gnu-addr2line${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_AR "${PATH_TO_COMPILER_BINARIES}/llvm-ar${CLANG_VERSION_SUFFIX}")
#set_if_file_exists(CMAKE_ASM_COMPILER "${PATH_TO_COMPILER_BINARIES}/aarch64-none-linux-gnu-as${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_C_COMPILER "${PATH_TO_COMPILER_BINARIES}/clang${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_CXX_COMPILER "${PATH_TO_COMPILER_BINARIES}/clang++${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_CXX_COMPILER_AR "${PATH_TO_COMPILER_BINARIES}/llvm-ar${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_CXX_COMPILER_RANLIB "${PATH_TO_COMPILER_BINARIES}/llvm-ranlib${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_C_COMPILER_AR "${PATH_TO_COMPILER_BINARIES}/llvm-ar${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_C_COMPILER_RANLIB "${PATH_TO_COMPILER_BINARIES}/llvm-ranlib${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_LINKER "${PATH_TO_COMPILER_BINARIES}/ld.lld${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_NM "${PATH_TO_COMPILER_BINARIES}/llvm-nm${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_OBJCOPY "${PATH_TO_COMPILER_BINARIES}/llvm-objcopy${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_OBJDUMP "${PATH_TO_COMPILER_BINARIES}/llvm-objdump${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_RANLIB "${PATH_TO_COMPILER_BINARIES}/llvm-ranlib${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_READELF "${PATH_TO_COMPILER_BINARIES}/llvm-readelf${CLANG_VERSION_SUFFIX}")
set_if_file_exists(CMAKE_STRIP "${PATH_TO_COMPILER_BINARIES}/llvm-strip${CLANG_VERSION_SUFFIX}")

# Don't look for programs in the sysroot as they are arm binaries
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

SET(CMAKE_SYSROOT ${PATH_TO_TOOLCHAIN_BASE}/aarch64-none-linux-gnu/libc/)

SET(CMAKE_ASM_COMPILER_TARGET aarch64-none-linux-gnu)
SET(CMAKE_C_COMPILER_TARGET aarch64-none-linux-gnu)
SET(CMAKE_CXX_COMPILER_TARGET aarch64-none-linux-gnu)

SET(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=${PATH_TO_COMPILER_BINARIES}/ld.lld${CLANG_VERSION_SUFFIX} -L${PATH_TO_TOOLCHAIN_BASE}/lib/gcc/aarch64-none-linux-gnu/11.2.1")
SET(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=${PATH_TO_COMPILER_BINARIES}/ld.lld${CLANG_VERSION_SUFFIX} -L${PATH_TO_TOOLCHAIN_BASE}/lib/gcc/aarch64-none-linux-gnu/11.2.1")
SET(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=${PATH_TO_COMPILER_BINARIES}/ld.lld${CLANG_VERSION_SUFFIX} -L${PATH_TO_TOOLCHAIN_BASE}/lib/gcc/aarch64-none-linux-gnu/11.2.1")
SET(CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=${PATH_TO_COMPILER_BINARIES}/ld.lld${CLANG_VERSION_SUFFIX} -L${PATH_TO_TOOLCHAIN_BASE}/lib/gcc/aarch64-none-linux-gnu/11.2.1")
SET(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=${PATH_TO_COMPILER_BINARIES}/ld.lld${CLANG_VERSION_SUFFIX} -L${PATH_TO_TOOLCHAIN_BASE}/lib/gcc/aarch64-none-linux-gnu/11.2.1")
SET(CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=${PATH_TO_COMPILER_BINARIES}/ld.lld${CLANG_VERSION_SUFFIX} -L${PATH_TO_TOOLCHAIN_BASE}/lib/gcc/aarch64-none-linux-gnu/11.2.1")
42 changes: 42 additions & 0 deletions aarch64/cross-compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function do_ArmRuntimeStage() {
current_dir="$PWD"

if true; then
# Download cross-compilation toolchain from https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
AARCH64_TOOLCHAIN_FOLDER="${current_dir}/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu"
AARCH64_TAR_XZ_URL="https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz?rev=33c6e30e5ac64e6dba8f0431f2c35f1b&hash=AE0C3F32FC140B87A05846EBF9494722"
AARCH64_TAR_XZ="$AARCH64_TOOLCHAIN_FOLDER".tar.xz

if [ ! -f "$AARCH64_TAR_XZ" ]; then
wget -O "$AARCH64_TAR_XZ" "$AARCH64_TAR_XZ_URL"
fi

if [ ! -d "$AARCH64_TOOLCHAIN_FOLDER" ]; then
AARCH64_TAR_XZ_EXPECTED_HASH="52dbac3eb71dbe0916f60a8c5ab9b7dc9b66b3ce513047baa09fae56234e53f3"
AARCH64_TAR_XZ_ACTUAL_HASH=$(sha256sum "$AARCH64_TAR_XZ" | awk '{ print $1 }')
if [[ "$AARCH64_TAR_XZ_EXPECTED_HASH" != "$AARCH64_TAR_XZ_ACTUAL_HASH" ]]; then
echo "Hash check failed"
echo "Expected $AARCH64_TAR_XZ_EXPECTED_HASH but got $AARCH64_TAR_XZ_ACTUAL_HASH"
exit
fi

mkdir -p "$AARCH64_TOOLCHAIN_FOLDER"
tar -xvf "$AARCH64_TAR_XZ" -C "$AARCH64_TOOLCHAIN_FOLDER" --strip-components=1

# WORKAROUND. The linker refuses to pick these objects up from the original location.
ln -s ${current_dir}/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/lib/gcc/aarch64-none-linux-gnu/11.2.1/crtbeginS.o \
${current_dir}/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/libc/usr/lib/crtbeginS.o
ln -s ${current_dir}/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/lib/gcc/aarch64-none-linux-gnu/11.2.1/crtendS.o \
${current_dir}/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/libc/usr/lib/crtendS.o
fi
fi

cmake -DCMAKE_TOOLCHAIN_FILE="${current_dir}/clang_to_aarch64-linux-gnu.toolchain.cmake" -G Ninja \
.. \
-DCMAKE_BUILD_TYPE=Release

DESTDIR=$DEST/clang-install-aarch64 ninja -j "$CORE_COUNT" install
}


do_ArmRuntimeStage
Loading