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

0_RootFS: Support riscv64 #8468

Merged
merged 5 commits into from
Dec 23, 2024
Merged
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
8 changes: 6 additions & 2 deletions 0_RootFS/PlatformSupport/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ```
# using BinaryBuilder
# using BinaryBuilder: aatriplet
# for platform in supported_platforms()
# for platform in supported_platforms(; experimental=true)
# # Append version numbers for BSD systems
# if Sys.isapple(platform)
# suffix = arch(platform) == "aarch64" ? "20" : "14"
Expand Down Expand Up @@ -90,6 +90,9 @@ target_to_linux_arch()
powerpc*)
echo "powerpc"
;;
riscv64*)
echo "riscv"
;;
i686*)
echo "x86"
;;
Expand Down Expand Up @@ -180,7 +183,8 @@ ln -s "${prefix}" "${sysroot}/usr/local"

# Build the artifacts
ndARGS, deploy_target = find_deploy_arg(ARGS)
build_info = build_tarballs(ndARGS, "$(name)-$(triplet(compiler_target))", version, sources, script, [host_platform], Product[], []; skip_audit=true)
build_info = build_tarballs(ndARGS, "$(name)-$(triplet(compiler_target))", version, sources, script, [host_platform], Product[], [];
skip_audit=true, validate_name=false)
if deploy_target !== nothing
upload_and_insert_shards(deploy_target, name, version, build_info; target=compiler_target)
end
21 changes: 16 additions & 5 deletions 0_RootFS/gcc_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# `--deploy` flag to the `build_tarballs.jl` script. You can either build &
# deploy the compilers one by one or run something like
#
# for p in i686-linux-gnu x86_64-linux-gnu aarch64-linux-gnu armv7l-linux-gnueabihf powerpc64le-linux-gnu i686-linux-musl x86_64-linux-musl aarch64-linux-musl armv7l-linux-musleabihf x86_64-apple-darwin14 x86_64-unknown-freebsd13.2 aarch64-unknown-freebsd13.2 i686-w64-mingw32 x86_64-w64-mingw32; do julia build_tarballs.jl --debug --verbose --deploy "${p}"; done
# for p in i686-linux-gnu x86_64-linux-gnu aarch64-linux-gnu armv7l-linux-gnueabihf powerpc64le-linux-gnu riscv64-linux-gnu i686-linux-musl x86_64-linux-musl aarch64-linux-musl armv7l-linux-musleabihf x86_64-apple-darwin14 x86_64-unknown-freebsd13.2 aarch64-unknown-freebsd13.2 i686-w64-mingw32 x86_64-w64-mingw32; do julia build_tarballs.jl --debug --verbose --deploy "${p}"; done

include("./common.jl")
include("./gcc_sources.jl")
Expand Down Expand Up @@ -70,6 +70,10 @@ function gcc_script(compiler_target::Platform)
ppc64*)
LIB64=lib64
;;
risc64*)
# TODO: Is this correct?
LIB64=lib64
;;
*)
LIB64=lib
;;
Expand Down Expand Up @@ -295,6 +299,7 @@ function gcc_script(compiler_target::Platform)
if [[ ${COMPILER_TARGET} == *-gnu* ]]; then
# patch glibc
cd ${WORKSPACE}/srcdir/glibc-*

# patch glibc to keep around libgcc_s_resume on arm
# ref: https://sourceware.org/ml/libc-alpha/2014-05/msg00573.html
atomic_patch -p1 $WORKSPACE/srcdir/patches/glibc_arm_gcc_fix.patch || true
Expand Down Expand Up @@ -336,13 +341,13 @@ function gcc_script(compiler_target::Platform)

# Patches for building glibc 2.17 on ppc64le
for p in ${WORKSPACE}/srcdir/patches/glibc-ppc64le-*.patch; do
atomic_patch -p1 ${p} || true;
atomic_patch -p1 ${p} || true
done

# Patch bad `movq` argument in glibc 2.17, adapted from:
# https://github.com/bminor/glibc/commit/b1ec623ed50bb8c7b9b6333fa350c3866dbde87f
# X-ref: https://github.com/crosstool-ng/crosstool-ng/issues/1825#issuecomment-1437918391
atomic_patch -p1 $WORKSPACE/srcdir/patches/glibc_movq_fix.patch
atomic_patch -p1 $WORKSPACE/srcdir/patches/glibc_movq_fix.patch || true

# Various configure overrides
GLIBC_CONFIGURE_OVERRIDES=( libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes )
Expand All @@ -352,6 +357,12 @@ function gcc_script(compiler_target::Platform)
GLIBC_CONFIGURE_OVERRIDES+=( libc_cv_ssp=no libc_cv_ssp_strong=no )
fi

if [[ ${COMPILER_TARGET} == riscv64-* ]]; then
# Explicitly disable C++
# (Disable for all architectures?)
GLIBC_CONFIGURE_OVERRIDES+=( CXX=false )
fi
Comment on lines +360 to +364
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? What are the consequences?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this setting, glibc builds the file support/links-dso-program.cc with a C++ compiler. There is no C++ compiler for the host architecture available, so glibc uses /usr/bin/g++ instead. This fails. If we disable C++ (/bin/false always reports an error in the configure stage), then glibc builds a different version of that file (support/links-dso-program-c.c) with a C compiler, and all is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't exist in the earlier glibc versions that we build for other architectures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no C++ compiler for the host architecture available

All this stuff is built with system compilers, we don't use BinayBuilder toolchains, that's the point of these (obscure) lines

@eval BinaryBuilder.BinaryBuilderBase empty!(bootstrap_list)
@eval BinaryBuilder.BinaryBuilderBase push!(bootstrap_list, :rootfs, :platform_support)
The C file is probably being built with /usr/bin/gcc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the C file is built with the host compiler (--target="${COMPILER_TARGET}"). The lines you see here are only configuring glibc. glibc is built much further down (# Finish off libc), after the first stage of GCC has been built (# Back to GCC-land, install libgcc).

/usr/bin/gcc would target the build system x86_64-linux-musl, and that wouldn't work for building a glibc for riscv64.


# Configure glibc
mkdir ${WORKSPACE}/srcdir/glibc_build
cd ${WORKSPACE}/srcdir/glibc_build
Expand Down Expand Up @@ -478,7 +489,7 @@ function gcc_script(compiler_target::Platform)

# Back to GCC-land, install libgcc
cd ${WORKSPACE}/srcdir/gcc_stage1
make all-target-libgcc -j ${nproc}
make all-target-libgcc -j${nproc}
make install-target-libgcc

# Finish off libc
Expand Down Expand Up @@ -578,7 +589,7 @@ function gcc_script(compiler_target::Platform)
${GCC_CONF_ARGS}

## Build, build, build!
make -j ${nproc}
make -j${nproc}
make install

# Remove misleading libtool archives
Expand Down
22 changes: 17 additions & 5 deletions 0_RootFS/gcc_sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function gcc_sources(gcc_version::VersionNumber, compiler_target::Platform; kwar
"634a084377ee2e2932c66459b0396edf76da2e9f"),
]
else
# Different versions of GCC should be pared with different versions of Binutils
# Different versions of GCC should be paired with different versions of Binutils
binutils_gcc_version_mapping = Dict(
v"4.8.5" => v"2.24",
v"5.2.0" => v"2.25.1",
Expand Down Expand Up @@ -241,14 +241,26 @@ function gcc_sources(gcc_version::VersionNumber, compiler_target::Platform; kwar
ArchiveSource("https://mirrors.kernel.org/gnu/glibc/glibc-2.17.tar.xz",
"6914e337401e0e0ade23694e1b2c52a5f09e4eda3270c67e7c3ba93a89b5b23e"),
]
elseif arch(compiler_target) in ["riscv64"]
libc_sources = [
ArchiveSource("https://mirrors.kernel.org/gnu/glibc/glibc-2.35.tar.xz",
"5123732f6b67ccd319305efd399971d58592122bcc2a6518a1bd2510dd0cf52e"),
]
else
error("Unknown arch for glibc for compiler target $(compiler_target)")
end
elseif Sys.islinux(compiler_target) && libc(compiler_target) == "musl"
libc_sources = [
ArchiveSource("https://www.musl-libc.org/releases/musl-1.1.19.tar.gz",
"db59a8578226b98373f5b27e61f0dd29ad2456f4aa9cec587ba8c24508e4c1d9"),
]
if arch(compiler_target) in ["riscv64"]
libc_sources = [
ArchiveSource("https://www.musl-libc.org/releases/musl-1.2.0.tar.gz",
"c6de7b191139142d3f9a7b5b702c9cae1b5ee6e7f57e582da9328629408fd4e8"),
]
else
libc_sources = [
ArchiveSource("https://www.musl-libc.org/releases/musl-1.1.19.tar.gz",
"db59a8578226b98373f5b27e61f0dd29ad2456f4aa9cec587ba8c24508e4c1d9"),
]
end
elseif Sys.isapple(compiler_target)
if arch(compiler_target) == "aarch64"
libc_sources = [
Expand Down
3 changes: 2 additions & 1 deletion RootFS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ The Care and Feeding of a Root Filesystem

This document details some of the journey we have embarked upon to create a Linux environment that supports cross-compilation for a very wide range of architectures and platforms. At the moment of writing, we support the following platforms (expressed in compiler triplet format):

* glibc Linux: `i686-linux-gnu`, `x86_64-linux-gnu`, `aarch64-linux-gnu`, `armv7l-linux-gnueabihf`, `powerpc64le-linux-gnu`, `armv6l-linux-gnueabihf`
* glibc Linux: `i686-linux-gnu`, `x86_64-linux-gnu`, `aarch64-linux-gnu`, `armv7l-linux-gnueabihf`, `armv6l-linux-gnueabihf`, `powerpc64le-linux-gnu`, `riscv64-linux-gnu`
* musl Linux: `i686-linux-musl`, `x86_64-linux-musl`, `aarch64-linux-musl`, `armv7l-linux-musleabihf`, `armv6l-linux-musleabihf`
* MacOS: `x86_64-apple-darwin`, `aarch64-apple-darwin`
* FreeBSD: `x86_64-unknown-freebsd13.2`, `aarch64-unknown-freebsd13.2`
Expand Down Expand Up @@ -40,6 +40,7 @@ The version of `glibc` we can compile against varies by system; we attempt to us
| aarch64 | v2.19 |
| armv7l | v2.19 |
| powerpc64le | v2.17 |
| riscv64 | v2.35 |


Compiler Shards
Expand Down