Skip to content

Commit

Permalink
aarch64: build rust
Browse files Browse the repository at this point in the history
  • Loading branch information
hadfl committed Dec 29, 2024
1 parent 385a602 commit eccf588
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 37 deletions.
105 changes: 105 additions & 0 deletions build/rust/build-arch-aarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/bash
#
# {{{ CDDL HEADER
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
# }}}

# Copyright 2024 OmniOS Community Edition (OmniOSce) Association.

. ../../lib/build.sh

PROG=rust
PKG=ooce/developer/rust
VER=1.83.0
SUMMARY="Rust systems programming language"
DESC="Rust is a systems programming language that runs blazingly fast, "
DESC+="prevents segfaults, and guarantees thread safety."

set_builddir ${PROG}c-${VER}-src

OPREFIX=$PREFIX
PREFIX+=/$PROG

BUILD_DEPENDS_IPS="developer/gnu-binutils"
# TODO: globbing only works reliably as long as we just have
# one cross compiler version per arch.
crossgccver=`pkg_ver aarch64/gcc*`
crossgccver=${crossgccver%%.*}
# `rustc` uses `gcc` as its linker. Other dependencies such as the C runtime
# and linker are themselves pulled in as dependencies of the gcc package.
RUN_DEPENDS_IPS="developer/gcc$crossgccver"

# rust build requires the final install directory to be present
[ -d "$PREFIX" ] || logcmd $PFEXEC mkdir -p $PREFIX

XFORM_ARGS="
-DPREFIX=${PREFIX#/}
-DOPREFIX=${OPREFIX#/}
-DPROG=$PROG
"

SKIP_RTIME_CHECK=1
SKIP_SSP_CHECK=1
NO_SONAME_EXPECTED=1

aarch64prefix=$CROSSTOOLS/aarch64/bin/${TRIPLETS[aarch64]}
CONFIGURE_OPTS[aarch64]="
--prefix=$PREFIX
--sysconfdir=/etc$PREFIX
--localstatedir=/var$PREFIX
--set target.${RUSTTRIPLETS[aarch64]}.cc=$aarch64prefix-gcc
--set target.${RUSTTRIPLETS[aarch64]}.cxx=$aarch64prefix-g++
--set target.${RUSTTRIPLETS[aarch64]}.ar=$aarch64prefix-ar
"
CONFIGURE_OPTS+="
--release-description=OmniOS/$RELVER
--enable-vendor
--enable-local-rust
--enable-extended
--build=${RUSTTRIPLETS[$BUILD_ARCH]}
--host=${RUSTTRIPLETS[aarch64]}
--target=${RUSTTRIPLETS[aarch64]}
--enable-rpath
--enable-ninja
--disable-codegen-tests
--disable-dist-src
--disable-llvm-static-stdcpp
--disable-docs
--release-channel=stable
--python=$PYTHON
"

pre_configure() { :;
# rust needs to find the native gcc for bootstrapping
set_gccver $DEFAULT_GCC_VER

tripus=${RUSTTRIPLETS[aarch64]//-/_}
tripuc=${tripus^^}
export CARGO_TARGET_${tripuc}_RUSTFLAGS="
-C link-arg=--sysroot=${SYSROOT[aarch64]}
"
export CXXFLAGS_${tripus}="-mno-outline-atomics -mtls-dialect=trad"
}

pre_install() {
logcmd $MKDIR -p $DESTDIR/$PREFIX || logerr "failed to create directory"
}

init
download_source $PROG ${PROG}c $VER-src
patch_source
prep_build autoconf-like
build -noctf
make_package
clean_up

# Vim hints
# vim:ts=4:sw=4:et:fdm=marker
1 change: 1 addition & 0 deletions build/rust/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# Copyright 2024 OmniOS Community Edition (OmniOSce) Association.

. ../../lib/arch.sh
. ../../lib/build.sh

PROG=rust
Expand Down
167 changes: 167 additions & 0 deletions build/rust/patches/0001-aarch64-cpu-feature-support-for-illumos.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
From 3e39942698fdc876135000d3fa12f5bad0eecfcc Mon Sep 17 00:00:00 2001
From: Dominik Hassler <[email protected]>
Date: Fri, 20 Dec 2024 15:17:18 +0000
Subject: [PATCH] aarch64 cpu feature support for illumos

---
compiler-rt/lib/builtins/cpu_model/aarch64.c | 7 ++
.../cpu_model/aarch64/fmv/illumos.inc | 109 ++++++++++++++++++
.../cpu_model/aarch64/lse_atomics/illumos.inc | 5 +
3 files changed, 121 insertions(+)
create mode 100644 compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc
create mode 100644 compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc

diff --git a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c
index b868caa991b2..a789a9c47745 100644
--- a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c
+++ b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c
@@ -45,6 +45,11 @@ _Bool __aarch64_have_lse_atomics
#elif defined(__ANDROID__)
#include "aarch64/hwcap.inc"
#include "aarch64/lse_atomics/android.inc"
+#elif defined(__illumos__)
+// clang-format off: should not reorder sys/auxv.h alphabetically
+#include <sys/auxv.h>
+// clang-format on
+#include "aarch64/lse_atomics/illumos.inc"
#elif __has_include(<sys/auxv.h>)
#include "aarch64/hwcap.inc"
#include "aarch64/lse_atomics/sysauxv.inc"
@@ -73,6 +78,8 @@ struct {
#elif defined(__ANDROID__)
#include "aarch64/fmv/mrs.inc"
#include "aarch64/fmv/android.inc"
+#elif defined(__illumos__)
+#include "aarch64/fmv/illumos.inc"
#elif __has_include(<sys/auxv.h>)
#include "aarch64/fmv/mrs.inc"
#include "aarch64/fmv/sysauxv.inc"
diff --git a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc
new file mode 100644
index 000000000000..2a968e1a1d1f
--- /dev/null
+++ b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc
@@ -0,0 +1,109 @@
+#include <sys/auxv.h>
+#define HAVE_SYS_AUXV_H
+
+static void __init_cpu_features_constructor(unsigned long hwcap,
+ const __ifunc_arg_t *arg) {
+
+ uint64_t features = 0;
+ uint64_t hwcaps[] = { hwcap, arg->_hwcap2 };
+
+ static const struct hwcap_map_t {
+ uint32_t hw_cap;
+ uint32_t hw_index;
+ enum CPUFeatures hw_feature;
+ } hwcap_map[] = {
+ { AV_AARCH64_FP, 1, FEAT_FP },
+ { AV_AARCH64_ADVSIMD, 1, FEAT_SIMD },
+ { AV_AARCH64_SVE, 1, FEAT_SVE },
+ { AV_AARCH64_CRC32, 1, FEAT_CRC },
+ { AV_AARCH64_SB, 1, FEAT_SB },
+// { AV_AARCH64_SSBS, 1, RESERVED_FEAT_SSBS},
+// { AV_AARCH64_DGH, 1, RESERVED_FEAT_DGH},
+// { AV_AARCH64_AES, 1, RESERVED_FEAT_AES},
+ { AV_AARCH64_PMULL, 1, FEAT_PMULL},
+// { AV_AARCH64_SHA1, 1, RESERVED_FEAT_SHA1},
+ { AV_AARCH64_SHA256, 1, FEAT_SHA2},
+ { AV_AARCH64_SHA512, 1, FEAT_SHA2},
+ { AV_AARCH64_SHA3, 1, FEAT_SHA3},
+// { AV_AARCH64_SM3, 1,
+// { AV_AARCH64_SM4, 1,
+ { AV_AARCH64_LSE, 1, FEAT_LSE},
+ { AV_AARCH64_RDM, 1, FEAT_RDM},
+ { AV_AARCH64_FP16, 1, FEAT_FP16},
+ { AV_AARCH64_DOTPROD, 1, FEAT_DOTPROD},
+// { AV_AARCH64_FHM, 1,
+// { AV_AARCH64_DCPOP, 1,
+ { AV_AARCH64_F32MM, 1, FEAT_SVE_F32MM},
+ { AV_AARCH64_F64MM, 1, FEAT_SVE_F64MM},
+// { AV_AARCH64_DCPODP, 1,
+ { AV_AARCH64_BF16, 1, FEAT_BF16},
+ { AV_AARCH64_I8MM, 1, FEAT_I8MM},
+ { AV_AARCH64_FCMA, 1, FEAT_FCMA},
+ { AV_AARCH64_JSCVT, 1, FEAT_JSCVT},
+ { AV_AARCH64_LRCPC, 1, FEAT_RCPC},
+// { AV_AARCH64_PACA, 1,
+// { AV_AARCH64_PACG, 1,
+ { AV_AARCH64_DIT, 1, FEAT_DIT},
+ { AV_AARCH64_2_FLAGM, 2, FEAT_FLAGM},
+ { AV_AARCH64_2_ILRCPC, 2, FEAT_RCPC},
+// { AV_AARCH64_2_LSE2, 2,
+ { AV_AARCH64_2_FLAGM2, 2, FEAT_FLAGM2},
+ { AV_AARCH64_2_FRINTTS, 2, FEAT_FRINTTS},
+ { AV_AARCH64_2_BTI, 2, FEAT_BTI},
+ { AV_AARCH64_2_RNG, 2, FEAT_RNG},
+ { AV_AARCH64_2_MTE, 2, FEAT_MEMTAG2},
+// { AV_AARCH64_2_MTE3, 2, RESERVED_FEAT_MEMTAG3},
+// { AV_AARCH64_2_ECV, 2,
+// { AV_AARCH64_2_AFP, 2,
+// { AV_AARCH64_2_RPRES, 2, RESERVED_FEAT_RPRES},
+// { AV_AARCH64_2_LD64B, 2,
+// { AV_AARCH64_2_ST64BV, 2,
+// { AV_AARCH64_2_ST64BV0, ,2
+ { AV_AARCH64_2_WFXT, 2, FEAT_WFXT},
+ { AV_AARCH64_2_MOPS, 2, FEAT_MOPS},
+// { AV_AARCH64_2_HBC, 2,
+// { AV_AARCH64_2_CMOW, 2,
+ { AV_AARCH64_2_SVE2, 2, FEAT_SVE2},
+// { AV_AARCH64_2_SVE2_AES, 2, RESERVED_FEAT_SVE_AES},
+ { AV_AARCH64_2_SVE2_BITPERM, 2, FEAT_SVE_BITPERM},
+ { AV_AARCH64_2_SVE2_PMULL128, 2, FEAT_SVE_PMULL128},
+ { AV_AARCH64_2_SVE2_SHA3, 2, FEAT_SVE_SHA3},
+ { AV_AARCH64_2_SVE2_SM4, 2, FEAT_SVE_SM4},
+// { AV_AARCH64_2_TME, 2,
+ { AV_AARCH64_2_SME, 2, FEAT_SME},
+// { AV_AARCH64_2_SME_FA64, 2,
+// { AV_AARCH64_2_EBF16, 2, RESERVED_FEAT_EBF16},
+ { AV_AARCH64_2_SME_F64F64, 2, FEAT_SME_F64},
+ { AV_AARCH64_2_SME_I16I64, 2, FEAT_SME_I64}
+ };
+
+ for (size_t i = 0; i < sizeof (hwcap_map) / sizeof (hwcap_map[0]); i++)
+ if (hwcaps[hwcap_map[i].hw_index - 1] & hwcap_map[i].hw_cap)
+ features |= (1ULL << hwcap_map[i].hw_feature);
+
+ __atomic_store_n(&__aarch64_cpu_features.features, features, __ATOMIC_RELAXED);
+}
+
+void __init_cpu_features_resolver(unsigned long hwcap,
+ const __ifunc_arg_t *arg) {
+ if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED))
+ return;
+ __init_cpu_features_constructor(hwcap, arg);
+}
+
+void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
+ uint32_t hwcap[2] = {0};
+ // CPU features already initialized.
+ if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED))
+ return;
+
+ uint_t res = getisax(hwcap, 2);
+ if (res == 0)
+ return;
+
+ __ifunc_arg_t arg;
+ arg._size = sizeof(__ifunc_arg_t);
+ arg._hwcap = hwcap[0],
+ arg._hwcap2 = hwcap[1];
+ __init_cpu_features_constructor(hwcap[0], &arg);
+}
diff --git a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc
new file mode 100644
index 000000000000..78af1a19f48d
--- /dev/null
+++ b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc
@@ -0,0 +1,5 @@
+static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
+ uint32_t hwcap = 0;
+ uint_t res = getisax(&hwcap, 1);
+ __aarch64_have_lse_atomics = res != 0 && (hwcap & AV_AARCH64_LSE) != 0;
+}
--
2.47.1

35 changes: 0 additions & 35 deletions build/rust/patches/aarch64-cpu-features.patch

This file was deleted.

2 changes: 1 addition & 1 deletion build/rust/patches/aarch64-eh_frame-ro.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Ensure .eh_frame is consistently read-only for aarch64
diff -wpruN --no-dereference '--exclude=*.orig' a~/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp a/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp
--- a~/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp 1970-01-01 00:00:00
+++ a/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp 1970-01-01 00:00:00
@@ -381,8 +381,10 @@ void MCObjectFileInfo::initELFMCObjectFi
@@ -383,8 +383,10 @@ void MCObjectFileInfo::initELFMCObjectFi
// Solaris requires different flags for .eh_frame to seemingly every other
// platform.
unsigned EHSectionFlags = ELF::SHF_ALLOC;
Expand Down
2 changes: 1 addition & 1 deletion build/rust/patches/series
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
aarch64-eh_frame-ro.patch
aarch64-cpu-features.patch
0001-aarch64-cpu-feature-support-for-illumos.patch
1 change: 1 addition & 0 deletions doc/baseline.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extra.omnios ooce/developer/cunit
extra.omnios ooce/developer/git-absorb
extra.omnios ooce/developer/ninja
extra.omnios ooce/developer/protobuf
extra.omnios ooce/developer/rust
extra.omnios ooce/editor/joe
extra.omnios ooce/file/tree
extra.omnios ooce/fonts/liberation
Expand Down
1 change: 1 addition & 0 deletions doc/pkglist.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# .SYSROOT Wait, rebuild the repo, `pkg install *` to the
# arch-specific sysroot.

ooce/developer/rust
ooce/system/htop
ooce/library/libogg
ooce/library/nettle
Expand Down

0 comments on commit eccf588

Please sign in to comment.