loong64 arch support

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-12-10 17:25:57 +01:00
parent 9fa96b5606
commit 3f4719d83c
15 changed files with 189 additions and 6 deletions

View File

@@ -136,7 +136,8 @@ target "_all-platforms" {
"linux/mips64le",
"linux/ppc64le",
"linux/s390x",
"linux/riscv64"
"linux/riscv64",
"linux/loong64"
]
}
@@ -171,6 +172,7 @@ target "sdk-extras" {
"linux/ppc64le",
"linux/riscv64",
"linux/s390x",
"linux/loong64",
"windows/386",
"windows/amd64",
"windows/arm",

View File

@@ -76,6 +76,14 @@ testHelloCargoRustup() {
testHelloCargoRustup
}
@test "loong64-hellocargo-rustup" {
if ! supportLoong64Go; then
skip "LOONGARCH64 not supported"
fi
export TARGETARCH=loong64
testHelloCargoRustup
}
@test "ppc64le-hellocargo-rustup" {
if [ -f /etc/alpine-release ]; then
skip "rust stdlib not yet available for powerpc64le-unknown-linux-musl"
@@ -130,6 +138,14 @@ testHelloCargoRustup() {
testHelloCargo
}
@test "loong64-hellocargo-rustpkg" {
if ! supportLoong64Go; then
skip "LOONGARCH64 not supported" # rust stdlib package not available
fi
export TARGETARCH=loong64
testHelloCargo
}
@test "ppc64le-hellocargo-rustpkg" {
export TARGETARCH=ppc64le
testHelloCargo

View File

@@ -259,6 +259,28 @@ testBuildHello() {
testHelloCLLD
}
@test "loong64-c-ld" {
if ! supportLoongArch; then
skip "LOONGARCH64 not supported"
fi
if [ -f /etc/alpine-release ]; then
# FIXME: loong64-c-lld issue on alpine < 3.21
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x0): unknown relocation (102) against symbol
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x3c): unknown relocation (102) against symbol
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x64): unknown relocation (102) against symbol
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0xb4): unknown relocation (102) against symbol
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0xdc): unknown relocation (102) against symbol
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x154): unknown relocation (102) against symbol
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x198): unknown relocation (102) against symbol
alpineRelease=$(cat /etc/alpine-release)
if ! grep PRETTY_NAME /etc/os-release | cut -d '=' -f 2 | tr -d '"' | grep -q "edge$" || [ "$(semver compare "$alpineRelease" "3.21.0")" -lt 0 ]; then
skip
fi
fi
export TARGETARCH=loong64
testHelloCLLD
}
@test "386-c-lld" {
export TARGETARCH=386
testHelloCPPLLD
@@ -300,6 +322,24 @@ testBuildHello() {
testHelloCPPLLD # actually runs with ld
}
@test "loong64-c++-lld" {
if ! supportLoongArch; then
skip "LOONGARCH64 not supported"
fi
if [ -f /etc/alpine-release ]; then
# FIXME: loong64-c++-lld issue on alpine < 3.21
# ld.lld: error: unknown emulation: elf64loongarch
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x0): unknown relocation (102) against symbol
# error: unknown target triple 'loongarch64-alpine-linux-musl', please use -triple or -arch
alpineRelease=$(cat /etc/alpine-release)
if ! grep PRETTY_NAME /etc/os-release | cut -d '=' -f 2 | tr -d '"' | grep -q "edge$" || [ "$(semver compare "$alpineRelease" "3.21.0")" -lt 0 ]; then
skip
fi
fi
export TARGETARCH=loong64
testHelloCPPLLD
}
@test "386-c++-lld" {
export TARGETARCH=386
testHelloCPPLLD

View File

@@ -17,7 +17,7 @@ setup_file() {
}
teardown_file() {
for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64; do
for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64 linux/loong64; do
TARGETPLATFORM=$p xxdel xx-c-essentials
root=/$(TARGETPLATFORM=$p xx-info triple)
if [ -d "$root" ] && [ "$root" != "/" ]; then
@@ -173,6 +173,14 @@ testEnv() {
testEnv
}
@test "loong64-env" {
if ! supportLoong64Go; then
skip "LOONGARCH64 not supported"
fi
export TARGETARCH=loong64
testEnv
}
@test "mips-env" {
export TARGETARCH=mips
expMips=hardfloat
@@ -333,6 +341,14 @@ testHelloGO() {
testHelloGO
}
@test "loong64-hellogo" {
if ! supportLoong64Go; then
skip "LOONGARCH64 not supported"
fi
export TARGETARCH=loong64
testHelloGO
}
@test "386-hellogo" {
export TARGETARCH=386
testHelloGO
@@ -452,6 +468,24 @@ testHelloCGO() {
testHelloCGO
}
@test "loong64-hellocgo" {
if ! supportLoong64CGo; then
skip "LOONGARCH64 not supported"
fi
if [ -f /etc/alpine-release ]; then
# FIXME: loong64-hellocgo issue on alpine < 3.21
# ld.lld: error: unknown emulation: elf64loongarch
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x0): unknown relocation (102) against symbol
# error: unknown target triple 'loongarch64-alpine-linux-musl', please use -triple or -arch
alpineRelease=$(cat /etc/alpine-release)
if ! grep PRETTY_NAME /etc/os-release | cut -d '=' -f 2 | tr -d '"' | grep -q "edge$" || [ "$(semver compare "$alpineRelease" "3.21.0")" -lt 0 ]; then
skip
fi
fi
export TARGETARCH=loong64
testHelloCGO
}
@test "386-hellocgo" {
export TARGETARCH=386
testHelloCGO

View File

@@ -92,10 +92,15 @@ load 'assert'
assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc xx-info pkg-arch)" # does not change
}
@test "custom-vendor" {
@test "riscv64-custom-vendor" {
assert_equal "riscv64-unknown-linux-musl" "$(TARGETPLATFORM=linux/riscv64 XX_VENDOR=unknown xx-info triple)"
}
@test "loong64" {
assert_equal "loongarch64-alpine-linux-musl" "$(TARGETPLATFORM=linux/loong64 xx-info triple)"
assert_equal "loongarch64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)"
}
@test "mips" {
assert_equal "mips-alpine-linux-musl" "$(TARGETPLATFORM=linux/mips xx-info triple)"
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)"

View File

@@ -85,6 +85,10 @@ load 'assert'
assert_equal "ppc64le" "$(TARGETPLATFORM=linux/ppc64le xx-info march)"
}
@test "loong64" {
assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info march)"
}
@test "mips" {
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info march)"
}
@@ -134,6 +138,10 @@ load 'assert'
assert_success
assert_output "$(TARGETPLATFORM=linux/riscv64 xx-info)"
TARGETPAIR=linux-loong64 run xx-info
assert_success
assert_output "$(TARGETPLATFORM=linux/loong64 xx-info)"
TARGETPAIR=linux-mips run xx-info
assert_success
assert_output "$(TARGETPLATFORM=linux/mips xx-info)"

View File

@@ -77,6 +77,11 @@ fi
assert_equal "riscv64gc-unknown-linux-gnu" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc XX_VENDOR=unknown xx-info triple)"
}
@test "loong64" {
assert_equal "loongarch64-linux-gnu" "$(TARGETPLATFORM=linux/loong64 xx-info triple)"
assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)"
}
@test "mips" {
assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)"
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)"

View File

@@ -60,6 +60,10 @@ fi
assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 xx-info pkg-arch)"
}
@test "loong64" {
assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)"
}
@test "mips" {
assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)"
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)"

View File

@@ -250,6 +250,15 @@ load 'assert'
run xx-verify /idontexist
assert_failure
export XX_VERIFY_FILE_CMD_OUTPUT=": ELF 64-bit LSB executable, LoongArch, version 1 (SYSV), statically linked, BuildID[sha1]=4d126b33c220ba2efd23ed68a46ef0db96c31f76, not stripped"
export TARGETPLATFORM=linux/loong64
run xx-verify /idontexist
assert_success
export TARGETPLATFORM=linux/amd64
run xx-verify /idontexist
assert_failure
unset XX_VERIFY_FILE_CMD_OUTPUT
unset TARGETPLATFORM
}

View File

@@ -45,7 +45,7 @@ xxrun() {
wasclang=1
fi
if [ "$p" = "golang" ]; then
p="golang-1.15"
p="golang-1.19"
wasgolang=1
fi
set -- "$@" "$p"
@@ -63,7 +63,7 @@ xxrun() {
fi
fi
if [ -n "$wasgolang" ] && ! command -v go 2>/dev/null >/dev/null; then
ln -s /usr/lib/go-1.15/bin/go /usr/bin/go
ln -s /usr/lib/go-1.19/bin/go /usr/bin/go
fi
}
@@ -87,6 +87,17 @@ supportRiscV() {
return 0
}
supportLoongArch() {
if [ -f /etc/debian_version ]; then
if grep "sid main" /etc/apt/sources.list 2>/dev/null >/dev/null; then
return 0
else
return 1
fi
fi
return 0
}
versionGTE() { test "$(printf '%s\n' "$@" | sort -V | tail -n 1)" = "$1"; }
supportRiscVGo() {
@@ -114,6 +125,20 @@ supportWindowsArm64Go() {
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.17"
}
supportLoong64Go() {
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.19"
}
supportLoong64CGo() {
if ! supportLoongArch; then
return 1
fi
if ! supportLoong64Go; then
return 1
fi
return 0
}
supportRC() {
command -v llvm-rc >/dev/null 2>&1
}

View File

@@ -59,6 +59,11 @@ setup() {
echo "https://dl-cdn.alpinelinux.org/alpine/v3.20/main" >"$apk_dir/repositories"
echo "https://dl-cdn.alpinelinux.org/alpine/v3.20/community" >>"$apk_dir/repositories"
fi
# loong64 supported since alpine 3.21
if [ "$TARGETARCH" = "loong64" ] && ! supportLoong64; then
echo "https://dl-cdn.alpinelinux.org/alpine/v3.21/main" >"$apk_dir/repositories"
echo "https://dl-cdn.alpinelinux.org/alpine/v3.21/community" >>"$apk_dir/repositories"
fi
mkdir -p "$apk_dir/keys"
mkdir -p "$apk_dir/protected_paths.d"
echo "$XX_PKG_ARCH" >"$apk_dir/arch"
@@ -146,6 +151,10 @@ supportRiscV() {
versionGTE "$(xx-info os-version | cut -d'.' -f1-2)" "3.20"
}
supportLoong64() {
versionGTE "$(xx-info os-version | cut -d'.' -f1-2)" "3.21"
}
case "$1" in
"setup")
setup

View File

@@ -175,6 +175,8 @@ detectTargetOSArch() {
targetarch="s390x"
elif [ "$arch" = "powerpc64le" ]; then
targetarch="ppc64le"
elif [ "$arch" = "loong64" ]; then
targetarch="loong64"
fi
if [ -z "$targetarch" ]; then
@@ -342,6 +344,10 @@ setup() {
if [ "${target#riscv64}" != "${target}" ]; then
prefer_lld=
fi
# lld has no support for loong64
if [ "${target#loong64}" != "${target}" ]; then
prefer_lld=
fi
if [ -n "${XX_CC_PREFER_STATIC_LINKER}" ] && { [ "${target#386}" != "${target}" ] || [ "${target#powerpc64le}" != "${target}" ]; }; then
prefer_lld=
@@ -410,6 +416,9 @@ setup() {
if [ "$exp" = "riscv64" ]; then
exp="riscv"
fi
if [ "$exp" = "loong64" ]; then
exp="loongarch64"
fi
if ld -V 2>/dev/null | grep "$exp" >/dev/null; then
ln -s "$(command -v ld)" "/usr/bin/${target}-ld"
linker="/usr/bin/${target}-ld"

View File

@@ -190,6 +190,9 @@ if [ -z "$TARGETARCH" ]; then
"s390x")
TARGETARCH="s390x"
;;
"loong64")
TARGETARCH="loong64"
;;
"mips")
TARGETARCH="mips"
;;
@@ -221,6 +224,8 @@ if [ "$TARGETOS" = "darwin" ] && [ -z "$MACOSX_VERSION_MIN" ]; then
fi
fi
# debian: https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/data/cputable
# alpine: https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/master/src/apk_arch.h?ref_type=heads
case "$TARGETARCH" in
"amd64")
XX_MARCH="x86_64"
@@ -309,6 +314,13 @@ case "$TARGETARCH" in
XX_RHEL_ARCH="s390x"
XX_TRIPLE="s390x${vendor}-linux-${XX_LIBC}"
;;
"loong64")
XX_MARCH="loong64"
XX_DEBIAN_ARCH="loong64"
XX_ALPINE_ARCH="loongarch64"
XX_RHEL_ARCH="loong64"
XX_TRIPLE="loongarch64${vendor}-linux-${XX_LIBC}"
;;
"386")
XX_MARCH="i386"
XX_DEBIAN_ARCH="i386"

View File

@@ -214,6 +214,10 @@ for f in "$@"; do
expArch="IBM S/390"
expArch2="64-bit MSB"
;;
"loong64")
expArch="LoongArch"
expArch2="64-bit LSB"
;;
"mips")
expArch="MIPS"
expArch2="32-bit MSB"

View File

@@ -19,7 +19,8 @@ target "all" {
"linux/386",
"linux/riscv64",
"linux/s390x",
"linux/ppc64le"
"linux/ppc64le",
"linux/loong64"
]
}