diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index ffcfede0cef7fff897371adcf68651524d37a98d..e47b3ebbd3ed7a4e13f33eee3428d9c6238d656f 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -78,6 +78,27 @@ jobs: run: sh ci/loongarch64-linux-release.sh timeout-minutes: 180 + powerpc64le-linux-debug: + runs-on: [self-hosted, powerpc64le-linux] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/powerpc64le-linux-debug.sh + timeout-minutes: 360 + powerpc64le-linux-release: + runs-on: [self-hosted, powerpc64le-linux] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/powerpc64le-linux-release.sh + timeout-minutes: 240 + riscv64-linux-debug: if: github.event_name != 'pull_request' runs-on: [self-hosted, riscv64-linux] diff --git a/CMakeLists.txt b/CMakeLists.txt index 4de1a9b99198c178c6f8fbfc57b7802dbc311847..fbd8673ce48b00f22cd95d79200de3f27403614f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -787,6 +787,11 @@ else() set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2") set(ZIG1_COMPILE_FLAGS "-std=c99 -Os") set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector") + # Must match the condition in build.zig. + if(ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$") + set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections") + set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -ffunction-sections -fdata-sections") + endif() if(APPLE) set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000") elseif(MINGW) diff --git a/build.zig b/build.zig index 342c2cfada354e9cccda63484ed9252b7bcafe67..58a5c5def37e2987dee92ede7cf8b0282364a64a 100644 --- a/build.zig +++ b/build.zig @@ -477,7 +477,7 @@ pub fn build(b: *std.Build) !void { .linux => switch (b.graph.host.result.cpu.arch) { .aarch64 => 659_809_075, .loongarch64 => 598_902_374, - .powerpc64le => 550_656_409, + .powerpc64le => 627_431_833, .riscv64 => 827_043_430, .s390x => 580_596_121, .x86_64 => 3_290_894_745, @@ -838,6 +838,12 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Ste }); exe.stack_size = stack_size; + // Must match the condition in CMakeLists.txt. + const function_data_sections = options.target.result.cpu.arch.isPowerPC(); + + exe.link_function_sections = function_data_sections; + exe.link_data_sections = function_data_sections; + return exe; } diff --git a/ci/powerpc64le-linux-debug.sh b/ci/powerpc64le-linux-debug.sh new file mode 100755 index 0000000000000000000000000000000000000000..1b9a51e44debff61729207ec1529e1d494b8c84b --- /dev/null +++ b/ci/powerpc64le-linux-debug.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="powerpc64le-linux-musl" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1594+9fa433d71" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-debug +cd build-debug + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-debug" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts. +stage3-debug/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + -Dtarget=native-native-musl \ + -Dcpu=native+longcall \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 4m + +stage3-debug/bin/zig build \ + --prefix stage4-debug \ + -Denable-llvm \ + -Dno-lib \ + -Dtarget=$TARGET \ + -Dcpu=$MCPU \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-debug/bin/zig version)" + +stage4-debug/bin/zig test ../test/behavior.zig diff --git a/ci/powerpc64le-linux-release.sh b/ci/powerpc64le-linux-release.sh new file mode 100755 index 0000000000000000000000000000000000000000..77e1ca803ae27db49ed7a2b8fed48392f485c4d4 --- /dev/null +++ b/ci/powerpc64le-linux-release.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="powerpc64le-linux-musl" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1594+9fa433d71" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-release +cd build-release + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-release" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Release \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts. +stage3-release/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + -Dtarget=native-native-musl \ + -Dcpu=native+longcall \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 4m + +# Ensure that stage3 and stage4 are byte-for-byte identical. +stage3-release/bin/zig build \ + --prefix stage4-release \ + -Denable-llvm \ + -Dno-lib \ + -Doptimize=ReleaseFast \ + -Dstrip \ + -Dtarget=$TARGET \ + -Dcpu=$MCPU \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-release/bin/zig version)" + +# diff returns an error code if the files differ. +echo "If the following command fails, it means nondeterminism has been" +echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." +diff stage3-release/bin/zig stage4-release/bin/zig diff --git a/src/Compilation.zig b/src/Compilation.zig index 1b17f81c7dbe0e47bec03686701b5d3145f3d883..f308a60bd3e62e309d7dcb9ec38ecfaca18fff2a 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -8084,8 +8084,8 @@ fn buildOutputFromZig( } pub const CrtFileOptions = struct { - function_sections: ?bool = null, - data_sections: ?bool = null, + function_sections: bool = true, + data_sections: bool = true, omit_frame_pointer: ?bool = null, unwind_tables: ?std.builtin.UnwindTables = null, pic: ?bool = null, @@ -8188,8 +8188,8 @@ pub fn build_crt_file( .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, - .function_sections = options.function_sections orelse false, - .data_sections = options.data_sections orelse false, + .function_sections = options.function_sections, + .data_sections = options.data_sections, .c_source_files = c_source_files, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/libcxx.zig b/src/libs/libcxx.zig index bd8863991d63db6ed10d14cc426f0961fec0d676..316ac6d815b3d6023f0d63164194e412cfdd7e5c 100644 --- a/src/libs/libcxx.zig +++ b/src/libs/libcxx.zig @@ -265,6 +265,8 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, + .function_sections = true, + .data_sections = true, .c_source_files = c_source_files.items, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, @@ -459,6 +461,8 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, + .function_sections = true, + .data_sections = true, .c_source_files = c_source_files.items, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/libtsan.zig b/src/libs/libtsan.zig index 2f9574c47343aad0bf7b90013cbdd8c49f46c6cc..c9dcf609537b3cce617d77a5b456be4044cb09f5 100644 --- a/src/libs/libtsan.zig +++ b/src/libs/libtsan.zig @@ -288,6 +288,8 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, + .function_sections = true, + .data_sections = true, .c_source_files = c_source_files.items, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/libunwind.zig b/src/libs/libunwind.zig index 787a87f951094245fe042a22da043b41b833373f..c1437d39bd0c800039b4231f2ae7c172749676ff 100644 --- a/src/libs/libunwind.zig +++ b/src/libs/libunwind.zig @@ -155,7 +155,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .main_mod = null, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, - .function_sections = comp.function_sections, + .function_sections = true, + .data_sections = true, .c_source_files = &c_source_files, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig index 5c57f6d53e8b495fe08932fa3746711c192427f5..da67f476616815c849bc52ab2184ac5f2bf9e49c 100644 --- a/src/libs/mingw.zig +++ b/src/libs/mingw.zig @@ -56,6 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre }, }; return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{ + .function_sections = false, // https://codeberg.org/ziglang/zig/issues/30702 .unwind_tables = unwind_tables, }); }, diff --git a/src/libs/musl.zig b/src/libs/musl.zig index f1983381952d060c646a0a8bc16fe8e73964eaac..744f1f28d24b7c5cb1e9b49e47cdd244fb31aaa6 100644 --- a/src/libs/musl.zig +++ b/src/libs/musl.zig @@ -43,8 +43,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }, }; return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .no_builtin = true, }); @@ -63,8 +61,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }, }; return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .pic = true, .no_builtin = true, @@ -84,8 +80,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }, }; return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .pic = true, .no_builtin = true, @@ -172,8 +166,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }; } return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .no_builtin = true, });