diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8f836b65b..b0e5fe5ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: - runner: ubuntu-latest os: linux - - runner: macos-15-intel + - runner: macos-26-intel os: macos - runner: macos-26 @@ -92,6 +92,22 @@ jobs: working-directory: ./build run: ../download.sh + - name: Show host GCC version + shell: bash + run: | + echo "which gcc: $(command -v gcc || true)" + echo "which g++: $(command -v g++ || true)" + echo "which cc: $(command -v cc || true)" + echo "----- gcc --version -----" + gcc --version + echo "----- g++ --version -----" + g++ --version + echo "----- cc --version -----" + cc --version + echo "----- gcc -dumpfullversion / -dumpmachine -----" + gcc -dumpfullversion -dumpversion + gcc -dumpmachine + - name: Build Binutils (PPU) run: ./toolchain.sh 001 diff --git a/.github/workflows/deploy-docker.yaml b/.github/workflows/deploy-docker.yaml new file mode 100644 index 000000000..4c1f0305a --- /dev/null +++ b/.github/workflows/deploy-docker.yaml @@ -0,0 +1,64 @@ +name: ci-docker +on: + pull_request: + branches: + - master + + # Runs on pushes targeting the default branch + push: + branches: ['master'] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + dockerhub-push: + # Always skipped. Pushing :latest needs the DockerHub environment, which + # fails closed in a few seconds when those secrets are unavailable. + if: false + runs-on: ubuntu-latest + environment: DockerHub + env: + DOCKERHUB_REPONAME: ps3dev + strategy: + matrix: + platform: [linux/amd64] + + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: README to Dockerhub + uses: christian-korneck/update-container-description-action@v1 + env: + DOCKER_USER: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKER_PASS: ${{ secrets.DOCKERHUB_TOKEN }} + with: + destination_container_repo: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_REPONAME }} + provider: dockerhub + short_description: 'A Docker Image for PS3 Development' + readme_file: 'README.md' + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: ${{ matrix.platform }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: ${{ matrix.platform }} + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_REPONAME }}:latest \ No newline at end of file diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 9aa99971d..4f1be9020 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,11 +1,24 @@ -name: Build toolchain docker image +name: ci on: workflow_dispatch jobs: - Docker: - runs-on: ubuntu-latest + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + architecture: [x64] + defaults: + run: + shell: bash + + outputs: + sha8: ${{ steps.slug.outputs.sha8 }} + date: ${{ steps.date.outputs.date }} + steps: - name: Checkout uses: actions/checkout@v6 @@ -23,19 +36,13 @@ jobs: if: success() id: prepare run: | - echo ::set-output name=docker_platforms::linux/amd64,linux/386 - echo ::set-output name=docker_username::miigotu - echo ::set-output name=github_image::docker.pkg.github.com/${GITHUB_REPOSITORY,,}/ps3dev - VERSION_TAG=${GITHUB_REF#refs/*/} - echo ::set-output name=version::${VERSION_TAG%/merge} - - name: Available platforms - if: success() - run: echo ${{ steps.buildx.outputs.platforms }} - - name: Docker Login and set build command - if: success() - id: login - env: - GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + sudo apt update + sudo apt -y install autoconf automake bison flex gcc g++ libelf-dev make texinfo libncurses5-dev patch python2-dev subversion wget zlib1g-dev libtool-bin python-dev-is-python3 bzip2 libgmp3-dev pkg-config libssl-dev && \ + if [ "$(uname -m)" = "x86_64" ]; then sudo apt install -y nvidia-cg-toolkit ; fi + + - name: Install macOS requirements + if: startsWith(matrix.os, 'macos') + # act -P macos-latest=-self-hosted --container-architecture linux/amd64 run: | echo "${GITHUB_PASSWORD}" | docker login --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin docker.pkg.github.com echo ::set-output name=buildx::$(echo docker buildx build --output type=image,name=${{ steps.prepare.outputs.github_image }},push=true \ @@ -52,12 +59,51 @@ jobs: - name: Run Buildx (master) if: success() && steps.prepare.outputs.version == 'master' && github.event_name != 'pull_request' run: | - ${{ steps.login.outputs.buildx }} --tag "${{ steps.prepare.outputs.github_image }}:latest" --file Dockerfile . - - name: Run Buildx (non-master) - if: success() && steps.prepare.outputs.version != 'master' && github.event_name != 'pull_request' - run: | - ${{ steps.login.outputs.buildx }} --file Dockerfile . - - name: Clear - if: always() + . ~/.bashrc + mkdir -p $PWD/ps3dev + export PS3DEV=$PWD/ps3dev + export PSL1GHT=$PS3DEV + export PATH=$PATH:$PS3DEV/bin + export PATH=$PATH:$PS3DEV/ppu/bin + export PATH=$PATH:$PS3DEV/spu/bin + export PATH=$PATH:$PS3DEV/portlibs/ppu/bin + export PKG_CONFIG_PATH=$PS3DEV/portlibs/ppu/lib/pkgconfig + ./toolchain.sh + + - name: Compress ps3dev folder run: | - rm -rf ${HOME}/.docker/config.json + tar -zcvf ps3dev-${{matrix.os}}-${{steps.arch.outputs.arch}}-${{steps.date.outputs.date}}.tar.gz ps3dev + + - name: Archive Folder + uses: actions/upload-artifact@v4 + with: + name: ${{matrix.os}}-${{matrix.architecture}} + path: ps3dev-*.tar.gz + + publish: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Download all Artifact + uses: actions/download-artifact@v4 + + - name: Set SemVer + id: semver + run: echo "::set-output name=semver::0.1.0+${{ needs.build.outputs.date }}.${{ needs.build.outputs.sha8 }}" + + - name: Create Tag + uses: negz/create-tag@v1 + with: + version: ${{ steps.semver.outputs.semver }} + message: "automatic tag creation" + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Release + id: create_release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.semver.outputs.semver }} + files: | + ${{ github.workspace }}/**/*.tar.gz + diff --git a/.gitignore b/.gitignore index 90200203a..44dc0aa71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -/build /archives/* !/archives/archives.txt /ps3dev +.DS_Store +.idea/** +.vscode \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 97556c450..986ce50a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,50 @@ -# FROM ubuntu:xenial -FROM debian:12-slim +# Stay on Debian 12 so the host-linked cross gcc needs only glibc 2.36 +# (Bookworm). Building on Trixie produces GLIBC_2.38+ binaries that fail +# on Debian 12 and similar hosts. +FROM debian:12-slim AS base LABEL maintainer="miigotu@gmail.com" -ENV PS3DEV /usr/local/ps3dev -ENV PSL1GHT ${PS3DEV} -ENV PATH ${PATH}:${PS3DEV}/bin:${PS3DEV}/ppu/bin:${PS3DEV}/spu/bin +ENV PS3DEV=/usr/local/ps3dev \ + PSL1GHT=/usr/local/ps3dev \ + DEBIAN_FRONTEND=noninteractive \ + PYTHON_VERSION=3.10 \ + PYENV_ROOT=/root/.pyenv \ + PIP_ROOT_USER_ACTION=ignore \ + PKG_CONFIG_PATH=/usr/local/ps3dev/portlibs/ppu/lib/pkgconfig +ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}:${PS3DEV}/bin:${PS3DEV}/ppu/bin:${PS3DEV}/spu/bin:${PS3DEV}/portlibs/ppu/bin" -ENV DEBIAN_FRONTEND=noninteractive - -RUN \ - apt-get -y update && \ - apt-get -y install \ - autoconf bison build-essential ca-certificates flex git libelf-dev\ - libgmp-dev libncurses5-dev libssl-dev libtool-bin pkg-config \ - texinfo wget zlib1g-dev && \ - apt-get -y clean autoclean autoremove && \ - rm -rf /var/lib/{apt,dpkg,cache,log}/ +RUN apt-get update -y && \ + apt-get --no-install-recommends install -y autoconf automake bison build-essential bzip2 \ + ca-certificates cmake flex gettext-base git libelf-dev libgmp3-dev libncurses5-dev libssl-dev \ + libtool libtool-bin make patch pkg-config texinfo wget xz-utils zlib1g-dev && \ + # Fixes certificate errors with letsencrypt in ARMv7 + echo 'ca_certificate=/etc/ssl/certs/ca-certificates.crt' >> /etc/wgetrc && \ + # nvidia-cg-toolkit is non-free and amd64-only + if [ "$(uname -m)" = "x86_64" ]; then \ + sed -i 's/ main$/ main contrib non-free non-free-firmware/' /etc/apt/sources.list && \ + apt-get update -y && apt-get install -y nvidia-cg-toolkit ; \ + fi && \ + # pyenv + apt-get --no-install-recommends install -y zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \ + llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev curl git && \ + echo 'cacert=/etc/ssl/certs/ca-certificates.crt' >> ~/.curlrc && \ + git config --global http.sslverify 'false' && \ + curl https://pyenv.run | bash && \ + pyenv update && pyenv install $PYTHON_VERSION && pyenv global $PYTHON_VERSION && pyenv rehash && \ + pip install pycrypto && \ + apt-get -y clean autoclean autoremove && \ + rm -rf /var/lib/apt/lists/* +FROM base AS builder RUN mkdir /build WORKDIR /build COPY . /build +RUN mkdir -p "${PS3DEV}" && /build/toolchain.sh -# Fixes certificate errors with letsencrypt in ARMv7 -# RUN echo "\nca_certificate=/etc/ssl/certs/ca-certificates.crt" | tee -a /etc/wgetrc -# RUN /build/toolchain.sh +FROM base AS runtime +COPY --from=builder ${PS3DEV} ${PS3DEV} +# How to build and run a multi platform image +# Tested platforms: linux/amd64 or linux/arm64 +# DOCKER_DEFAULT_PLATFORM=linux/arm64 docker build . -t ps3dev +# DOCKER_DEFAULT_PLATFORM=linux/arm64 docker run -it -v `pwd`:/build -w /build ps3dev diff --git a/archives/archives.txt b/archives/archives.txt index 35fd5be8b..a7776b984 100644 --- a/archives/archives.txt +++ b/archives/archives.txt @@ -1,6 +1,8 @@ 6c7af8ed1c8cf9b4b9d6e6fe09a3e1d3d479fe63984ba8b9b26bf356b6313ca9 19973532 https://sourceware.org/pub/binutils/releases/binutils-2.22.tar.bz2 -> binutils-2.22.tar.bz2 +aa54850ebda5064c72cd4ec2d9b056c294252991486350d9a97ab2a6dfdfaf12 38254526 https://sourceware.org/pub/binutils/releases/binutils-2.42.tar.bz2 -> binutils-2.42.tar.bz2 27769f64ef1d4cd5e2be8682c0c93f9887983e6cfd1a927ce5a0a2915a95cf8f 72462752 https://sourceware.org/pub/gcc/releases/gcc-9.5.0/gcc-9.5.0.tar.xz -> gcc-9.5.0.tar.xz e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da 87858592 https://sourceware.org/pub/gcc/releases/gcc-13.2.0/gcc-13.2.0.tar.xz -> gcc-13.2.0.tar.xz c644b2847244278c57bec2ddda69d8fab5a7c767f3b9af69aa7aa3da823ff692 14571004 https://sourceware.org/pub/newlib/newlib-1.20.0.tar.gz -> newlib-1.20.0.tar.gz -- - https://github.com/ps3dev/psl1ght/tarball/master -> psl1ght.tar.gz -- - https://github.com/ps3dev/ps3libraries/tarball/master -> ps3libraries.tar.gz +1e55b4d7cdca7b34be12f4ceae651623aa73b2fd640152313f9f66a7149757c4 20489528 https://sourceware.org/pub/gdb/releases/gdb-8.3.1.tar.xz -> gdb-8.3.1.tar.xz +- - https://github.com/ps3dev/psl1ght/tarball/master -> psl1ght.tar.gz +- - https://github.com/ps3dev/ps3libraries/tarball/master -> ps3libraries.tar.gz diff --git a/depends/check-python.sh b/depends/check-python.sh new file mode 100755 index 000000000..b1d8076f1 --- /dev/null +++ b/depends/check-python.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# check-python.sh by Naomi Peori (naomi@peori.ca) + +## Prefer python3 (pyenv, Debian) over the unversioned python name. +python_bin="" +for c in python3 python; do + command -v "$c" >/dev/null 2>&1 || continue + python_bin="$c" + break +done +[ -n "$python_bin" ] || { echo "ERROR: Install python before continuing."; exit 1; } + +## python-config is often not on PATH; pyenv ships python3-config next to the interpreter. +pyconfig="" +for c in python3-config python-config; do + command -v "$c" >/dev/null 2>&1 || continue + pyconfig="$c" + break +done +if [ -z "$pyconfig" ]; then + pyhome=$("$python_bin" -c "import sys; print(sys.base_prefix)") + for c in "$pyhome"/bin/python3-config "$pyhome"/bin/python*-config; do + [ -x "$c" ] || continue + pyconfig="$c" + break + done +fi +[ -n "$pyconfig" ] || { echo "ERROR: Install python-dev before continuing."; exit 1; } + +pyprefix=$("$pyconfig" --prefix) || { echo "ERROR: Install python-dev before continuing."; exit 1; } + +python_h="" +for h in \ + "$pyprefix"/include/python*/Python.h \ + ${PYENV_ROOT:+$PYENV_ROOT/versions/*/include/python*/Python.h} \ + /opt/local/include/python*/Python.h \ + ${PYINSTALLDIR:+$PYINSTALLDIR/include/Python.h} +do + [ -f "$h" ] || continue + python_h="$h" + break +done +[ -n "$python_h" ] || { echo "ERROR: Install python-dev before continuing."; exit 1; } diff --git a/download.sh b/download.sh index 7807826dc..99df8510a 100755 --- a/download.sh +++ b/download.sh @@ -5,7 +5,8 @@ cd "$(dirname "$0")" cd archives || exit 1 ARCHIVE="archives.txt" -WGET="wget --tries=5 --timeout=15 --quiet --show-progress" +# 15s was aborting slow Sourceware transfers. Keep the partial file and resume. +WGET_OPTS=(--continue --tries=20 --timeout=60 --waitretry=5 --retry-connrefused --quiet --show-progress) # ----------------------------------------------------------------------------- # verify_sha256 @@ -29,17 +30,67 @@ verify_sha256() { return 0 } +file_size() { + wc -c < "$1" | tr -d ' ' +} + # ----------------------------------------------------------------------------- -# fetch +# mirror_urls +# Prints the primary URL plus GNU/kernel.org fallbacks. # ----------------------------------------------------------------------------- -fetch() { +mirror_urls() { url="$1" - dest="$2" - $WGET -O "$dest" "$url" || { - echo " !! Download failed: $url" >&2 - rm -f "$dest" - return 1 - } + file="$(basename "$url")" + printf '%s\n' "$url" + + case "$url" in + */binutils/releases/*|*/gnu/binutils/*) + printf '%s\n' \ + "https://ftpmirror.gnu.org/gnu/binutils/${file}" \ + "https://ftp.gnu.org/gnu/binutils/${file}" \ + "https://sourceware.org/pub/binutils/releases/${file}" \ + "https://mirrors.kernel.org/sourceware/binutils/releases/${file}" + ;; + */gcc/releases/*|*/gnu/gcc/*) + ver="${file%.tar.*}" + printf '%s\n' \ + "https://ftpmirror.gnu.org/gnu/gcc/${ver}/${file}" \ + "https://ftp.gnu.org/gnu/gcc/${ver}/${file}" \ + "https://sourceware.org/pub/gcc/releases/${ver}/${file}" \ + "https://gcc.gnu.org/pub/gcc/releases/${ver}/${file}" + ;; + */gdb/releases/*|*/gnu/gdb/*) + printf '%s\n' \ + "https://ftpmirror.gnu.org/gnu/gdb/${file}" \ + "https://ftp.gnu.org/gnu/gdb/${file}" \ + "https://sourceware.org/pub/gdb/releases/${file}" + ;; + */newlib/*) + printf '%s\n' \ + "https://sourceware.org/pub/newlib/${file}" \ + "https://mirrors.kernel.org/sourceware/newlib/${file}" + ;; + esac +} + +# ----------------------------------------------------------------------------- +# fetch [url...] +# Resumes into dest; does not delete a partial file on failure. +# ----------------------------------------------------------------------------- +fetch() { + dest="$1" + shift + url="" + for url in "$@"; do + [ -n "$url" ] || continue + echo " -> $url" + if wget "${WGET_OPTS[@]}" -O "$dest" "$url"; then + return 0 + fi + echo " !! failed, trying next mirror..." >&2 + done + echo " !! Download failed: ${1:-$url}" >&2 + return 1 } # ----------------------------------------------------------------------------- @@ -54,7 +105,6 @@ download() { printf '==> %s\n' "$file" - # If already present, verify immediately — size alone is not enough. if [ -f "$file" ]; then if [ "$sha" = "-" ]; then echo " -- no checksum, skipping re-download of existing file" @@ -64,19 +114,27 @@ download() { echo " -- already good" return 0 fi - echo " -- existing file failed verification, re-downloading..." - rm -f "$file" + actual=$(file_size "$file") + if [ "$size" != "-" ] && [ "$actual" -lt "$size" ]; then + echo " -- incomplete (${actual}/${size} bytes), resuming..." + else + echo " -- existing file failed verification, re-downloading..." + rm -f "$file" + fi fi - # First attempt - fetch "$url" "$file" + # Unique mirror list, primary URL first. + urls=$(mirror_urls "$url" | awk 'NF && !seen[$0]++') + + # shellcheck disable=SC2086 + fetch "$file" $urls - # Verify, with one retry on mismatch if [ "$sha" != "-" ]; then if ! verify_sha256 "$file" "$sha"; then - echo " -- retrying download..." + echo " -- checksum failed, retrying from another mirror..." rm -f "$file" - fetch "$url" "$file" + # shellcheck disable=SC2086 + fetch "$file" $urls verify_sha256 "$file" "$sha" || { rm -f "$file" echo " !! Giving up on $file" >&2 @@ -120,11 +178,35 @@ EOF done < "$ARCHIVE" } +# Guess a GNU/sourceware URL when archives.txt has no matching line. +guess_url() { + file="$1" + case "$file" in + binutils-*.tar.*) + printf 'https://ftpmirror.gnu.org/gnu/binutils/%s\n' "$file" + ;; + gcc-*.tar.*) + ver="${file%.tar.*}" + printf 'https://ftpmirror.gnu.org/gnu/gcc/%s/%s\n' "$ver" "$file" + ;; + newlib-*.tar.*) + printf 'https://sourceware.org/pub/newlib/%s\n' "$file" + ;; + gdb-*.tar.*) + printf 'https://ftpmirror.gnu.org/gnu/gdb/%s\n' "$file" + ;; + *) + return 1 + ;; + esac +} + run_one() { target="$1" found=0 while IFS= read -r line; do case "$line" in + \#*|"") continue ;; *"$target"*) ;; *) continue ;; esac @@ -136,10 +218,17 @@ EOF found=1 break done < "$ARCHIVE" - [ "$found" -eq 1 ] || { - echo "Not found: $target" >&2 - exit 1 - } + [ "$found" -eq 1 ] && return 0 + + if url=$(guess_url "$target"); then + echo "Not in $ARCHIVE; fetching $url" >&2 + download "-" "-" "$url" "$target" + return 0 + fi + + echo "Not found: $target" >&2 + echo "Add a line to archives/archives.txt or use a GNU/sourceware tarball name." >&2 + exit 1 } # ----------------------------------------------------------------------------- @@ -147,4 +236,4 @@ if [ "$#" -eq 0 ]; then run_all else run_one "$1" -fi \ No newline at end of file +fi diff --git a/patches/binutils-2.22-PS3.patch b/patches/binutils-2.22-PS3-SPU.patch similarity index 97% rename from patches/binutils-2.22-PS3.patch rename to patches/binutils-2.22-PS3-SPU.patch index ac2ac2368..8fba3c6c1 100644 --- a/patches/binutils-2.22-PS3.patch +++ b/patches/binutils-2.22-PS3-SPU.patch @@ -86,5 +86,5 @@ index 20e0271..48df959 100644 + else if (config.has_pie) + link_info.pie = TRUE; else - einfo (_("%P%F: -pie not supported\n")); - break; + einfo (_("%P%F: -pie not supported\n")); + break; diff --git a/patches/binutils-2.42-PS3-PPU.patch b/patches/binutils-2.42-PS3-PPU.patch new file mode 100644 index 000000000..f1aff8f97 --- /dev/null +++ b/patches/binutils-2.42-PS3-PPU.patch @@ -0,0 +1,90 @@ +# Original from https://github.com/ps3dev/ps3toolchain +# Updated for binutils 2.40 by Darjan Krijan [https://disc-kuraudo.eu] +diff '--color=auto' -urN a/ld/emulparams/elf32_spu.sh b/ld/emulparams/elf32_spu.sh +--- a/ld/emulparams/elf32_spu.sh 2022-07-08 11:46:48.000000000 +0200 ++++ b/ld/emulparams/elf32_spu.sh 2023-01-04 22:15:19.310575828 +0100 +@@ -6,6 +6,8 @@ + ARCH=spu + MACHINE= + ALIGNMENT=16 ++GENERATE_PIE_SCRIPT=yes ++GENERATE_COMBRELOC_SCRIPT=yes + TEXT_START_ADDR=0 + INITIAL_READONLY_SECTIONS='.interrupt : { KEEP(*(.interrupt)) }' + if test -z "${CREATE_SHLIB}"; then +diff '--color=auto' -urN a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em +--- a/ld/emultempl/spuelf.em 2022-07-08 11:46:48.000000000 +0200 ++++ b/ld/emultempl/spuelf.em 2023-01-04 22:17:32.998687355 +0100 +@@ -258,6 +258,14 @@ + return total; + } + ++static void ++spu_before_parse (void) ++{ ++ gld${EMULATION_NAME}_before_parse (); ++ ++ config.has_pie = `if test -n "$GENERATE_PIE_SCRIPT" ; then echo true ; else echo false ; fi`; ++} ++ + /* Go find if we need to do anything special for overlays. */ + + static void +@@ -851,5 +859,6 @@ + + LDEMUL_AFTER_OPEN=spu_after_open + LDEMUL_BEFORE_ALLOCATION=spu_before_allocation ++LDEMUL_BEFORE_PARSE=spu_before_parse + LDEMUL_FINISH=gld${EMULATION_NAME}_finish + LDEMUL_CHOOSE_TARGET=gld${EMULATION_NAME}_choose_target +diff '--color=auto' -urN a/ld/ld.h b/ld/ld.h +--- a/ld/ld.h 2022-07-08 11:46:48.000000000 +0200 ++++ b/ld/ld.h 2023-01-04 22:24:33.832738444 +0100 +@@ -229,6 +229,9 @@ + parameter. */ + bool has_shared; + ++ /* If TRUE, -pie is supported. */ ++ bool has_pie; ++ + /* If TRUE, build constructors. */ + bool build_constructors; + +diff '--color=auto' -urN a/ld/ldmain.c b/ld/ldmain.c +--- a/ld/ldmain.c 2022-07-08 11:46:48.000000000 +0200 ++++ b/ld/ldmain.c 2023-01-04 22:16:46.319346843 +0100 +@@ -315,6 +315,7 @@ + config.make_executable = true; + config.magic_demand_paged = true; + config.text_read_only = true; ++ config.has_pie = false; + config.print_map_discarded = true; + link_info.disable_target_specific_optimizations = -1; + +diff '--color=auto' -urN a/ld/lexsup.c b/ld/lexsup.c +--- a/ld/lexsup.c 2022-07-08 11:46:48.000000000 +0200 ++++ b/ld/lexsup.c 2023-01-04 22:17:19.218882047 +0100 +@@ -1286,6 +1286,8 @@ + if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) + link_info.unresolved_syms_in_shared_libs = RM_IGNORE; + } ++ else if (config.has_pie) ++ link_info.type = type_pie; + else + einfo (_("%F%P: -shared not supported\n")); + break; + +# Apple Clang 17+ (Xcode 16.3 / macOS 26) defines TARGET_OS_MAC as a builtin. +# zlib then #define fdopen(...) NULL, which breaks the SDK fdopen prototype. +diff --git a/zlib/zutil.h b/zlib/zutil.h +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -137,7 +137,7 @@ + # endif + #endif + +-#if defined(MACOS) || defined(TARGET_OS_MAC) ++#if defined(MACOS) || (defined(TARGET_OS_MAC) && !defined(__APPLE__)) + # define OS_CODE 7 + # ifndef Z_SOLO + # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os diff --git a/patches/gcc-9.5.0-PS3.patch b/patches/gcc-13.2.0-PS3-PPU.patch similarity index 80% rename from patches/gcc-9.5.0-PS3.patch rename to patches/gcc-13.2.0-PS3-PPU.patch index e394a67d9..df5564463 100644 --- a/patches/gcc-9.5.0-PS3.patch +++ b/patches/gcc-13.2.0-PS3-PPU.patch @@ -1,8 +1,12 @@ +# Original from https://github.com/ps3dev/ps3toolchain +# Updated to gcc 9.5.0 by Darjan Krijan [https://disc-kuraudo.eu] +# Updated to gcc 13.2.0 by luizfernandonb +# Updated to gcc 13.2.0 by humbertodias diff --git a/Makefile.in b/Makefile.in -index 64e091ba71..33570f9dad 100644 +index 06a9398e172..7419f7ed67a 100644 --- a/Makefile.in +++ b/Makefile.in -@@ -27294,7 +27294,6 @@ check-libiberty: +@@ -28118,7 +28118,6 @@ check-libiberty: .PHONY: install-libiberty maybe-install-libiberty maybe-install-libiberty: @if libiberty @@ -11,15 +15,15 @@ index 64e091ba71..33570f9dad 100644 install-libiberty: installdirs @: $(MAKE); $(unstage) diff --git a/gcc/config.gcc b/gcc/config.gcc -index 94885c7d75..3a2d236656 100644 +index 648b3dc2110..650d65fe28d 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc -@@ -2587,6 +2587,15 @@ pdp11-*-*) +@@ -2863,6 +2863,15 @@ pdp11-*-*) # tmake_file="${tmake_file} rs6000/t-fprules" # extra_headers= # ;; +powerpc64-ps3-elf) -+ tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h usegas.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/default64.h" ++ tm_file="${tm_file} elfos.h gnu-user.h usegas.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/default64.h" + tm_file="rs6000/biarch64.h ${tm_file} rs6000/cell64lv2.h" + if test x${enable_secureplt} = xyes; then + tm_file="rs6000/secureplt.h ${tm_file}" @@ -28,87 +32,14 @@ index 94885c7d75..3a2d236656 100644 + tmake_file="rs6000/t-fprules rs6000/t-fprules-fpbit rs6000/t-ppcgas rs6000/t-ppccomm" + ;; powerpc-*-darwin*) - extra_options="${extra_options} ${cpu_type}/darwin.opt" - case ${target} in -diff --git a/gcc/config.host b/gcc/config.host -index 816a0f06cb..2d9bf9ed48 100644 ---- a/gcc/config.host -+++ b/gcc/config.host -@@ -99,7 +99,8 @@ case ${host} in - esac - - case ${host} in -- aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia*) -+ aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia* |\ -+ aarch64*-*-darwin*) - case ${target} in - aarch64*-*-*) - host_extra_gcc_objs="driver-aarch64.o" -@@ -251,6 +252,10 @@ case ${host} in - host_extra_gcc_objs="${host_extra_gcc_objs} driver-mingw32.o" - host_lto_plugin_soname=liblto_plugin-0.dll - ;; -+ aarch64*-*-darwin*) -+ out_host_hook_obj="${out_host_hook_obj} host-aarch64-darwin.o" -+ host_xmake_file="${host_xmake_file} aarch64/x-darwin" -+ ;; - i[34567]86-*-darwin* | x86_64-*-darwin*) - out_host_hook_obj="${out_host_hook_obj} host-i386-darwin.o" - host_xmake_file="${host_xmake_file} i386/x-darwin" -diff --git a/gcc/config/aarch64/host-aarch64-darwin.c b/gcc/config/aarch64/host-aarch64-darwin.c -new file mode 100644 -index 0000000000..d70f2df3bf ---- /dev/null -+++ b/gcc/config/aarch64/host-aarch64-darwin.c -@@ -0,0 +1,33 @@ -+/* aarch64/arm64-darwin host-specific hook definitions. -+ -+Copyright The GNU Toolchain Authors. -+ -+This file is part of GCC. -+ -+GCC is free software; you can redistribute it and/or modify it under -+the terms of the GNU General Public License as published by the Free -+Software Foundation; either version 3, or (at your option) any later -+version. -+ -+GCC is distributed in the hope that it will be useful, but WITHOUT ANY -+WARRANTY; without even the implied warranty of MERCHANTABILITY or -+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -+for more details. -+ -+You should have received a copy of the GNU General Public License -+along with GCC; see the file COPYING3. If not see -+. */ -+ -+#define IN_TARGET_CODE 1 -+ -+#include "config.h" -+#include "system.h" -+#include "coretypes.h" -+#include "hosthooks.h" -+#include "hosthooks-def.h" -+#include "config/host-darwin.h" -+ -+/* Darwin doesn't do anything special for arm64/aarch64 hosts; this file -+ exists just to include the generic config/host-darwin.h. */ -+ -+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER; -diff --git a/gcc/config/aarch64/x-darwin b/gcc/config/aarch64/x-darwin -new file mode 100644 -index 0000000000..6d788d5e89 ---- /dev/null -+++ b/gcc/config/aarch64/x-darwin -@@ -0,0 +1,3 @@ -+host-aarch64-darwin.o : $(srcdir)/config/aarch64/host-aarch64-darwin.c -+ $(COMPILE) $< -+ $(POSTCOMPILE) + extra_options="${extra_options} ${cpu_type}/darwin.opt" + case ${target} in diff --git a/gcc/config/rs6000/cell64lv2.h b/gcc/config/rs6000/cell64lv2.h new file mode 100644 -index 0000000000..31ebbd9552 +index 00000000000..df93791e501 --- /dev/null +++ b/gcc/config/rs6000/cell64lv2.h -@@ -0,0 +1,587 @@ +@@ -0,0 +1,584 @@ +/* Definitions of target machine for GNU compiler, + for 64 bit PowerPC linux. + Copyright (C) 2000-2017 Free Software Foundation, Inc. @@ -171,7 +102,6 @@ index 0000000000..31ebbd9552 +#undef TARGET_KEEP_LEAF_WHEN_PROFILED +#define TARGET_KEEP_LEAF_WHEN_PROFILED rs6000_keep_leaf_when_profiled + -+#define TARGET_USES_LINUX64_OPT 1 +#ifdef HAVE_LD_LARGE_TOC +#undef TARGET_CMODEL +#define TARGET_CMODEL rs6000_current_cmodel @@ -403,11 +333,9 @@ index 0000000000..31ebbd9552 +/* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */ +#undef ADJUST_FIELD_ALIGN +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ -+ (rs6000_special_adjust_field_align_p ((TYPE), (COMPUTED)) \ -+ ? 128 \ -+ : (TARGET_64BIT \ -+ && TARGET_ALIGN_NATURAL == 0 \ -+ && TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ ++ ((TARGET_64BIT \ ++ && TARGET_ALIGN_NATURAL == 0 \ ++ && TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ + ? MIN ((COMPUTED), 32) \ + : (COMPUTED)) + @@ -696,13 +624,13 @@ index 0000000000..31ebbd9552 + enabling the __float128 keyword. */ +#undef TARGET_FLOAT128_ENABLE_TYPE +#define TARGET_FLOAT128_ENABLE_TYPE 1 -diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c -index 991dcca18e..68900a85c8 100644 ---- a/gcc/config/rs6000/rs6000.c -+++ b/gcc/config/rs6000/rs6000.c -@@ -1424,6 +1424,10 @@ rtl_opt_pass *make_pass_analyze_swaps (gcc::context*); - static bool rs6000_keep_leaf_when_profiled () __attribute__ ((unused)); - static tree rs6000_fold_builtin (tree, int, tree *, bool); +diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc +index 196bcbe1ca3..ea3764278c9 100644 +--- a/gcc/config/rs6000/rs6000.cc ++++ b/gcc/config/rs6000/rs6000.cc +@@ -1178,6 +1178,10 @@ static bool rs6000_secondary_reload_move (enum rs6000_reg_type, + bool); + rtl_opt_pass *make_pass_analyze_swaps (gcc::context*); +#ifdef POWERPC_CELL64LV2 +static bool rs6000_cell64lv2_valid_pointer_mode (scalar_int_mode); @@ -711,11 +639,10 @@ index 991dcca18e..68900a85c8 100644 /* Hash table stuff for keeping track of TOC entries. */ struct GTY((for_user)) toc_hash_struct -@@ -39732,7 +39736,20 @@ rs6000_mangle_decl_assembler_name (tree decl, tree id) - return id; +@@ -29043,6 +29047,20 @@ rs6000_opaque_type_invalid_use_p (gimple *stmt) + return false; } -- +#ifdef POWERPC_CELL64LV2 + +#undef TARGET_VALID_POINTER_MODE @@ -734,10 +661,10 @@ index 991dcca18e..68900a85c8 100644 #include "gt-rs6000.h" diff --git a/gcc/configure b/gcc/configure -index 8c25a18fa0..60d12e6bc4 100755 +index c7b26d1927d..85e83d312f9 100755 --- a/gcc/configure +++ b/gcc/configure -@@ -28944,12 +28944,12 @@ $as_echo "#define HAVE_LD_PPC_GNU_ATTR_LONG_DOUBLE 1" >>confdefs.h +@@ -30787,12 +30787,12 @@ $as_echo "#define HAVE_LD_PPC_GNU_ATTR_LONG_DOUBLE 1" >>confdefs.h esac case "$target:$tm_file" in @@ -753,10 +680,10 @@ index 8c25a18fa0..60d12e6bc4 100755 ;; *le-*-freebsd*) diff --git a/gcc/configure.ac b/gcc/configure.ac -index d67f72df8a..2f7fc60c0c 100644 +index 09082e8ccae..96cccce56a2 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac -@@ -5671,12 +5671,12 @@ EOF +@@ -6470,12 +6470,12 @@ EOF esac case "$target:$tm_file" in @@ -771,80 +698,39 @@ index d67f72df8a..2f7fc60c0c 100644 emul_name="-melf64ppc" ;; *le-*-freebsd*) -diff --git a/gcc/system.h b/gcc/system.h -index d04f8fd336..97be99e4a0 100644 ---- a/gcc/system.h -+++ b/gcc/system.h -@@ -194,27 +194,8 @@ extern int fprintf_unlocked (FILE *, const char *, ...); - #undef fread_unlocked - #undef fwrite_unlocked - --/* Include before "safe-ctype.h" to avoid GCC poisoning -- the ctype macros through safe-ctype.h */ -- --#ifdef __cplusplus --#ifdef INCLUDE_STRING --# include --#endif --#endif -- --/* There are an extraordinary number of issues with . -- The last straw is that it varies with the locale. Use libiberty's -- replacement instead. */ --#include "safe-ctype.h" -- --#include -- --#include -- --#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO --extern int errno; --#endif -+/* Include C++ standard headers before "safe-ctype.h" to avoid GCC -+ poisoning the ctype macros through safe-ctype.h */ - - #ifdef __cplusplus - #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY) -@@ -229,6 +210,9 @@ extern int errno; - #ifdef INCLUDE_SET - # include - #endif -+#ifdef INCLUDE_STRING -+# include -+#endif - #ifdef INCLUDE_VECTOR - # include - #endif -@@ -237,6 +221,19 @@ extern int errno; - # include - #endif - -+/* There are an extraordinary number of issues with . -+ The last straw is that it varies with the locale. Use libiberty's -+ replacement instead. */ -+#include "safe-ctype.h" -+ -+#include -+ -+#include -+ -+#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO -+extern int errno; -+#endif -+ - /* Some of glibc's string inlines cause warnings. Plus we'd rather - rely on (and therefore test) GCC's string builtins. */ - #define __NO_STRING_INLINES diff --git a/libgcc/config.host b/libgcc/config.host -index 0486a0135e..842252d106 100644 +index 9d7212028d0..7ddde1dc464 100644 --- a/libgcc/config.host +++ b/libgcc/config.host -@@ -1134,6 +1134,8 @@ powerpc-*-rtems*) +@@ -1224,6 +1224,9 @@ powerpc-*-rtems*) tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-savresfgpr rs6000/t-crtstuff t-crtstuff-pic t-fdpbit" extra_parts="$extra_parts crtbeginS.o crtendS.o crtbeginT.o ecrti.o ecrtn.o ncrti.o ncrtn.o" ;; +powerpc64-ps3-elf) ++ tmake_file="${tmake_file} rs6000/t-crtstuff-cell64lv2" + ;; powerpc*-*-linux*) tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-savresfgpr rs6000/t-crtstuff rs6000/t-linux t-dfprules rs6000/t-ppc64-fp t-slibgcc-libgcc" tmake_file="${tmake_file} t-stack rs6000/t-stack-rs6000" +diff --git a/libgcc/config/rs6000/t-crtstuff-cell64lv2 b/libgcc/config/rs6000/t-crtstuff-cell64lv2 +new file mode 100644 +index 00000000000..9eb9ca7ac35 +--- /dev/null ++++ b/libgcc/config/rs6000/t-crtstuff-cell64lv2 +@@ -0,0 +1 @@ ++CRTSTUFF_T_CFLAGS = -fno-asynchronous-unwind-tables +\ No newline at end of file + +# Apple Clang 17+ defines TARGET_OS_MAC; do not stub fdopen() on macOS. +diff --git a/zlib/zutil.h b/zlib/zutil.h +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -130,7 +130,7 @@ + # endif + #endif + +-#if defined(MACOS) || defined(TARGET_OS_MAC) ++#if defined(MACOS) || (defined(TARGET_OS_MAC) && !defined(__APPLE__)) + # define OS_CODE 7 + # ifndef Z_SOLO + # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os diff --git a/patches/gcc-13.2.0-PS3-host.patch b/patches/gcc-13.2.0-PS3-host.patch new file mode 100644 index 000000000..7f586508d --- /dev/null +++ b/patches/gcc-13.2.0-PS3-host.patch @@ -0,0 +1,285 @@ +# Host GCC 16 / libc++ 17+: include C++ headers before safe-ctype.h on every +# OS, and teach libcody about char8_t (u8"" is char8_t* under -fchar8_t). +# Packet (unsigned, size_t) vs Packet (unsigned, char8_t*) is ambiguous for +# integer 0 on C++20+ host compilers; cast BOOL payloads to size_t. +diff --git a/gcc/system.h b/gcc/system.h +--- a/gcc/system.h ++++ b/gcc/system.h +@@ -194,27 +194,9 @@ + #undef fread_unlocked + #undef fwrite_unlocked + +-/* Include before "safe-ctype.h" to avoid GCC poisoning +- the ctype macros through safe-ctype.h */ +- +-#ifdef __cplusplus +-#ifdef INCLUDE_STRING +-# include +-#endif +-#endif +- +-/* There are an extraordinary number of issues with . +- The last straw is that it varies with the locale. Use libiberty's +- replacement instead. */ +-#include "safe-ctype.h" +- +-#include +- +-#include +- +-#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO +-extern int errno; +-#endif ++/* Include C++ headers before "safe-ctype.h". Host GCC 16 libstdc++ and ++ libc++ 17+ pull ctype names through //; the ++ poison macros break islower/toupper. */ + + #ifdef __cplusplus + #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY) +@@ -243,8 +225,24 @@ + # include + # include + # include ++# include ++# include ++# include + #endif + ++/* There are an extraordinary number of issues with . ++ The last straw is that it varies with the locale. Use libiberty's ++ replacement instead. */ ++#include "safe-ctype.h" ++ ++#include ++ ++#include ++ ++#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO ++extern int errno; ++#endif ++ + /* Some of glibc's string inlines cause warnings. Plus we'd rather + rely on (and therefore test) GCC's string builtins. */ + #define __NO_STRING_INLINES +diff --git a/libcody/cody.hh b/libcody/cody.hh +--- a/libcody/cody.hh ++++ b/libcody/cody.hh +@@ -47,12 +47,21 @@ + + // C++11 doesn't have utf8 character literals :( + ++#if __cpp_char8_t >= 201811 + template ++constexpr char S2C (char8_t const (&s)[I]) ++{ ++ static_assert (I == 2, "only single octet strings may be converted"); ++ return s[0]; ++} ++#else ++template + constexpr char S2C (char const (&s)[I]) + { + static_assert (I == 2, "only single octet strings may be converted"); + return s[0]; + } ++#endif + + /// Internal buffering class. Used to concatenate outgoing messages + /// and Lex incoming ones. +@@ -122,7 +131,14 @@ + if (buffer.size () != lastBol) + Space (); + Append (str, maybe_quote, len); ++ } ++#if __cpp_char8_t >= 201811 ++ void AppendWord (char8_t const *str, bool maybe_quote = false, ++ size_t len = ~size_t (0)) ++ { ++ AppendWord ((const char *) str, maybe_quote, len); + } ++#endif + /// Add a word as with AppendWord + /// @param str the string to append + /// @param maybe_quote string might need quoting, as for Append +@@ -262,8 +278,14 @@ + } + Packet (unsigned c, std::string const &s) + : string (s), cat (STRING), code (c) ++ { ++ } ++#if __cpp_char8_t >= 201811 ++ Packet (unsigned c, const char8_t *s) ++ : string ((const char *) s), cat (STRING), code (c) + { + } ++#endif + Packet (unsigned c, std::vector &&v) + : vector (std::move (v)), cat (VECTOR), code (c) + { +diff --git a/libcody/client.cc b/libcody/client.cc +--- a/libcody/client.cc ++++ b/libcody/client.cc +@@ -97,7 +97,7 @@ + + static Packet CommunicationError (int err) + { +- std::string e {u8"communication error:"}; ++ std::string e {(const char *) u8"communication error:"}; + e.append (strerror (err)); + + return Packet (Client::PC_ERROR, std::move (e)); +@@ -110,33 +110,33 @@ + { + if (e == EINVAL) + { +- std::string msg (u8"malformed string '"); ++ std::string msg ((const char *) u8"malformed string '"); + msg.append (words[0]); +- msg.append (u8"'"); ++ msg.append ((const char *) u8"'"); + return Packet (Client::PC_ERROR, std::move (msg)); + } + else +- return Packet (Client::PC_ERROR, u8"missing response"); ++ return Packet (Client::PC_ERROR, (const char *) u8"missing response"); + } + + Assert (!words.empty ()); +- if (words[0] == u8"ERROR") ++ if (words[0] == (const char *) u8"ERROR") + return Packet (Client::PC_ERROR, +- words.size () == 2 ? words[1]: u8"malformed error response"); ++ words.size () == 2 ? words[1]: (const char *) u8"malformed error response"); + + if (isLast && !read.IsAtEnd ()) + return Packet (Client::PC_ERROR, +- std::string (u8"unexpected extra response")); ++ std::string ((const char *) u8"unexpected extra response")); + + Assert (code < Detail::RC_HWM); + Packet result (responseTable[code] (words)); + result.SetRequest (code); + if (result.GetCode () == Client::PC_ERROR && result.GetString ().empty ()) + { +- std::string msg {u8"malformed response '"}; ++ std::string msg {(const char *) u8"malformed response '"}; + + read.LexedLine (msg); +- msg.append (u8"'"); ++ msg.append ((const char *) u8"'"); + result.GetString () = std::move (msg); + } + else if (result.GetCode () == Client::PC_CONNECT) +@@ -199,7 +199,7 @@ + size_t alen, size_t ilen) + { + write.BeginLine (); +- write.AppendWord (u8"HELLO"); ++ write.AppendWord ((const char *) u8"HELLO"); + write.AppendInteger (Version); + write.AppendWord (agent, true, alen); + write.AppendWord (ident, true, ilen); +@@ -211,7 +211,7 @@ + // HELLO $version $agent [$flags] + Packet ConnectResponse (std::vector &words) + { +- if (words[0] == u8"HELLO" && (words.size () == 3 || words.size () == 4)) ++ if (words[0] == (const char *) u8"HELLO" && (words.size () == 3 || words.size () == 4)) + { + char *eptr; + unsigned long val = strtoul (words[1].c_str (), &eptr, 10); +@@ -247,7 +247,7 @@ + // PATHNAME $dir | ERROR + Packet PathnameResponse (std::vector &words) + { +- if (words[0] == u8"PATHNAME" && words.size () == 2) ++ if (words[0] == (const char *) u8"PATHNAME" && words.size () == 2) + return Packet (Client::PC_PATHNAME, std::move (words[1])); + + return Packet (Client::PC_ERROR, u8""); +@@ -256,7 +256,7 @@ + // OK or ERROR + Packet OKResponse (std::vector &words) + { +- if (words[0] == u8"OK") ++ if (words[0] == (const char *) u8"OK") + return Packet (Client::PC_OK); + else + return Packet (Client::PC_ERROR, +@@ -319,11 +319,11 @@ + // PATHNAME $cmifile + Packet IncludeTranslateResponse (std::vector &words) + { +- if (words[0] == u8"BOOL" && words.size () == 2) ++ if (words[0] == (const char *) u8"BOOL" && words.size () == 2) + { +- if (words[1] == u8"FALSE") ++ if (words[1] == (const char *) u8"FALSE") +- return Packet (Client::PC_BOOL, 0); ++ return Packet (Client::PC_BOOL, size_t (0)); +- else if (words[1] == u8"TRUE") ++ else if (words[1] == (const char *) u8"TRUE") +- return Packet (Client::PC_BOOL, 1); ++ return Packet (Client::PC_BOOL, size_t (1)); + else + return Packet (Client::PC_ERROR, u8""); +diff --git a/libcody/server.cc b/libcody/server.cc +--- a/libcody/server.cc ++++ b/libcody/server.cc +@@ -36,12 +36,12 @@ + const requestTable[Detail::RC_HWM] = + { + // Same order as enum RequestCode +- RequestPair {u8"HELLO", nullptr}, +- RequestPair {u8"MODULE-REPO", ModuleRepoRequest}, +- RequestPair {u8"MODULE-EXPORT", ModuleExportRequest}, +- RequestPair {u8"MODULE-IMPORT", ModuleImportRequest}, +- RequestPair {u8"MODULE-COMPILED", ModuleCompiledRequest}, +- RequestPair {u8"INCLUDE-TRANSLATE", IncludeTranslateRequest}, ++ RequestPair {(const char *) u8"HELLO", nullptr}, ++ RequestPair {(const char *) u8"MODULE-REPO", ModuleRepoRequest}, ++ RequestPair {(const char *) u8"MODULE-EXPORT", ModuleExportRequest}, ++ RequestPair {(const char *) u8"MODULE-IMPORT", ModuleImportRequest}, ++ RequestPair {(const char *) u8"MODULE-COMPILED", ModuleCompiledRequest}, ++ RequestPair {(const char *) u8"INCLUDE-TRANSLATE", IncludeTranslateRequest}, + }; + } + +@@ -135,21 +135,21 @@ + std::string msg; + + if (err > 0) +- msg = u8"error processing '"; ++ msg = (const char *) u8"error processing '"; + else if (ix >= Detail::RC_HWM) +- msg = u8"unrecognized '"; ++ msg = (const char *) u8"unrecognized '"; + else if (IsConnected () && ix == Detail::RC_CONNECT) +- msg = u8"already connected '"; ++ msg = (const char *) u8"already connected '"; + else if (!IsConnected () && ix != Detail::RC_CONNECT) +- msg = u8"not connected '"; ++ msg = (const char *) u8"not connected '"; + else +- msg = u8"malformed '"; ++ msg = (const char *) u8"malformed '"; + + read.LexedLine (msg); +- msg.append (u8"'"); ++ msg.append ((const char *) u8"'"); + if (err > 0) + { +- msg.append (u8" "); ++ msg.append ((const char *) u8" "); + msg.append (strerror (err)); + } + resolver->ErrorResponse (this, std::move (msg)); +@@ -176,7 +176,7 @@ + return nullptr; + + if (words.size () == 3) +- words.emplace_back (u8""); ++ words.emplace_back ((const char *) u8""); + unsigned version = ParseUnsigned (words[1]); + if (version == ~0u) + return nullptr; diff --git a/patches/gcc-13.2.0-PS3-macos-arm64.patch b/patches/gcc-13.2.0-PS3-macos-arm64.patch new file mode 100644 index 000000000..425f9bff9 --- /dev/null +++ b/patches/gcc-13.2.0-PS3-macos-arm64.patch @@ -0,0 +1,32 @@ +# Build GCC 13.2.0 as a cross compiler on Apple Silicon. +# host_detect_local_cpu / driver-aarch64.o are not linked for Darwin hosts, +# and host-darwin.cc must export host_hooks. +diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h +--- a/gcc/config/aarch64/aarch64.h ++++ b/gcc/config/aarch64/aarch64.h +@@ -1191,5 +1191,5 @@ + /* Extra specs when building a native AArch64-hosted compiler. + Option rewriting rules based on host system. */ +-#if defined(__aarch64__) ++#if defined(__aarch64__) && !defined(__APPLE__) + extern const char *host_detect_local_cpu (int argc, const char **argv); + #define HAVE_LOCAL_CPU_DETECT +diff --git a/gcc/config/host-darwin.cc b/gcc/config/host-darwin.cc +--- a/gcc/config/host-darwin.cc ++++ b/gcc/config/host-darwin.cc +@@ -23,6 +23,8 @@ + #include "options.h" + #include "diagnostic-core.h" + #include "config/host-darwin.h" ++#include "hosthooks.h" ++#include "hosthooks-def.h" + #include + + /* For Darwin (macOS only) platforms, without ASLR (PIE) enabled on the +@@ -180,4 +182,6 @@ + } + + return 1; + } ++ ++const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER; diff --git a/patches/gcc-13.2.0-PS3.patch b/patches/gcc-9.5.0-PS3-SPU.patch similarity index 65% rename from patches/gcc-13.2.0-PS3.patch rename to patches/gcc-9.5.0-PS3-SPU.patch index 621f82db5..5c65bb271 100644 --- a/patches/gcc-13.2.0-PS3.patch +++ b/patches/gcc-9.5.0-PS3-SPU.patch @@ -1,41 +1,9 @@ -diff --git a/Makefile.in b/Makefile.in -index 06a9398e1..7419f7ed6 100644 ---- a/Makefile.in -+++ b/Makefile.in -@@ -28118,7 +28118,6 @@ check-libiberty: - .PHONY: install-libiberty maybe-install-libiberty - maybe-install-libiberty: - @if libiberty --maybe-install-libiberty: install-libiberty - - install-libiberty: installdirs - @: $(MAKE); $(unstage) -diff --git a/gcc/config.gcc b/gcc/config.gcc -index 648b3dc21..650d65fe2 100644 ---- a/gcc/config.gcc -+++ b/gcc/config.gcc -@@ -2863,6 +2863,15 @@ pdp11-*-*) - # tmake_file="${tmake_file} rs6000/t-fprules" - # extra_headers= - # ;; -+powerpc64-ps3-elf) -+ tm_file="${tm_file} elfos.h gnu-user.h usegas.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/default64.h" -+ tm_file="rs6000/biarch64.h ${tm_file} rs6000/cell64lv2.h" -+ if test x${enable_secureplt} = xyes; then -+ tm_file="rs6000/secureplt.h ${tm_file}" -+ fi -+ extra_options="${extra_options} rs6000/sysv4.opt" -+ tmake_file="rs6000/t-fprules rs6000/t-fprules-fpbit rs6000/t-ppcgas rs6000/t-ppccomm" -+ ;; - powerpc-*-darwin*) - extra_options="${extra_options} ${cpu_type}/darwin.opt" - case ${target} in -diff --git a/gcc/config/rs6000/cell64lv2.h b/gcc/config/rs6000/cell64lv2.h -new file mode 100644 -index 000000000..df93791e5 ---- /dev/null -+++ b/gcc/config/rs6000/cell64lv2.h -@@ -0,0 +1,584 @@ +# Original from https://github.com/ps3dev/ps3toolchain +# Updated to gcc 9.5.0 by Darjan Krijan [https://disc-kuraudo.eu] +diff '--color=auto' -urN a/gcc/config/rs6000/cell64lv2.h b/gcc/config/rs6000/cell64lv2.h +--- a/gcc/config/rs6000/cell64lv2.h 1970-01-01 01:00:00.000000000 +0100 ++++ b/gcc/config/rs6000/cell64lv2.h 2023-01-01 17:58:23.274094209 +0100 +@@ -0,0 +1,587 @@ +/* Definitions of target machine for GNU compiler, + for 64 bit PowerPC linux. + Copyright (C) 2000-2017 Free Software Foundation, Inc. @@ -98,6 +66,7 @@ index 000000000..df93791e5 +#undef TARGET_KEEP_LEAF_WHEN_PROFILED +#define TARGET_KEEP_LEAF_WHEN_PROFILED rs6000_keep_leaf_when_profiled + ++#define TARGET_USES_LINUX64_OPT 1 +#ifdef HAVE_LD_LARGE_TOC +#undef TARGET_CMODEL +#define TARGET_CMODEL rs6000_current_cmodel @@ -329,9 +298,11 @@ index 000000000..df93791e5 +/* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */ +#undef ADJUST_FIELD_ALIGN +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ -+ ((TARGET_64BIT \ -+ && TARGET_ALIGN_NATURAL == 0 \ -+ && TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ ++ (rs6000_special_adjust_field_align_p ((TYPE), (COMPUTED)) \ ++ ? 128 \ ++ : (TARGET_64BIT \ ++ && TARGET_ALIGN_NATURAL == 0 \ ++ && TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ + ? MIN ((COMPUTED), 32) \ + : (COMPUTED)) + @@ -620,35 +591,33 @@ index 000000000..df93791e5 + enabling the __float128 keyword. */ +#undef TARGET_FLOAT128_ENABLE_TYPE +#define TARGET_FLOAT128_ENABLE_TYPE 1 -diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc -index 196bcbe1c..ea3764278 100644 ---- a/gcc/config/rs6000/rs6000.cc -+++ b/gcc/config/rs6000/rs6000.cc -@@ -1178,6 +1178,10 @@ static bool rs6000_secondary_reload_move (enum rs6000_reg_type, - bool); - rtl_opt_pass *make_pass_analyze_swaps (gcc::context*); +diff '--color=auto' -urN a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c +--- a/gcc/config/rs6000/rs6000.c 2022-05-27 09:21:11.000000000 +0200 ++++ b/gcc/config/rs6000/rs6000.c 2023-01-01 18:00:32.742783224 +0100 +@@ -1424,6 +1424,10 @@ + static bool rs6000_keep_leaf_when_profiled () __attribute__ ((unused)); + static tree rs6000_fold_builtin (tree, int, tree *, bool); +#ifdef POWERPC_CELL64LV2 -+static bool rs6000_cell64lv2_valid_pointer_mode (scalar_int_mode); ++static bool rs6000_cell64lv2_valid_pointer_mode(scalar_int_mode); +#endif + /* Hash table stuff for keeping track of TOC entries. */ struct GTY((for_user)) toc_hash_struct -@@ -29043,6 +29047,20 @@ rs6000_opaque_type_invalid_use_p (gimple *stmt) - return false; +@@ -39732,7 +39736,18 @@ + return id; } +- +#ifdef POWERPC_CELL64LV2 -+ +#undef TARGET_VALID_POINTER_MODE +#define TARGET_VALID_POINTER_MODE rs6000_cell64lv2_valid_pointer_mode + +static bool -+rs6000_cell64lv2_valid_pointer_mode (scalar_int_mode mode) ++rs6000_cell64lv2_valid_pointer_mode(scalar_int_mode mode) +{ -+ return (mode == SImode || (TARGET_64BIT && mode == DImode) -+ || mode == ptr_mode || mode == Pmode); ++ return (mode == SImode || (TARGET_64BIT && mode == DImode) || mode == ptr_mode || mode == Pmode); +} + +#endif @@ -656,11 +625,29 @@ index 196bcbe1c..ea3764278 100644 struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-rs6000.h" -diff --git a/gcc/configure b/gcc/configure -index c7b26d192..85e83d312 100755 ---- a/gcc/configure -+++ b/gcc/configure -@@ -30787,12 +30787,12 @@ $as_echo "#define HAVE_LD_PPC_GNU_ATTR_LONG_DOUBLE 1" >>confdefs.h +diff '--color=auto' -urN a/gcc/config.gcc b/gcc/config.gcc +--- a/gcc/config.gcc 2022-05-27 09:21:10.000000000 +0200 ++++ b/gcc/config.gcc 2023-01-01 14:28:35.684278963 +0100 +@@ -2587,6 +2587,15 @@ + # tmake_file="${tmake_file} rs6000/t-fprules" + # extra_headers= + # ;; ++powerpc64-ps3-elf) ++ tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h usegas.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/default64.h" ++ tm_file="rs6000/biarch64.h ${tm_file} rs6000/cell64lv2.h" ++ if test x${enable_secureplt} = xyes; then ++ tm_file="rs6000/secureplt.h ${tm_file}" ++ fi ++ extra_options="${extra_options} rs6000/sysv4.opt" ++ tmake_file="rs6000/t-fprules rs6000/t-fprules-fpbit rs6000/t-ppcgas rs6000/t-ppccomm" ++ ;; + powerpc-*-darwin*) + extra_options="${extra_options} ${cpu_type}/darwin.opt" + case ${target} in +diff '--color=auto' -urN a/gcc/configure b/gcc/configure +--- a/gcc/configure 2022-05-27 09:21:46.000000000 +0200 ++++ b/gcc/configure 2023-01-01 14:52:19.312078588 +0100 +@@ -28944,12 +28944,12 @@ esac case "$target:$tm_file" in @@ -675,11 +662,10 @@ index c7b26d192..85e83d312 100755 emul_name="-melf64ppc" ;; *le-*-freebsd*) -diff --git a/gcc/configure.ac b/gcc/configure.ac -index 09082e8cc..96cccce56 100644 ---- a/gcc/configure.ac -+++ b/gcc/configure.ac -@@ -6470,12 +6470,12 @@ EOF +diff '--color=auto' -urN a/gcc/configure.ac b/gcc/configure.ac +--- a/gcc/configure.ac 2022-05-27 09:21:11.000000000 +0200 ++++ b/gcc/configure.ac 2023-01-01 14:51:42.742384668 +0100 +@@ -5671,12 +5671,12 @@ esac case "$target:$tm_file" in @@ -694,312 +680,40 @@ index 09082e8cc..96cccce56 100644 emul_name="-melf64ppc" ;; *le-*-freebsd*) -diff --git a/gcc/system.h b/gcc/system.h -index cf45db3f9..10f051dcf 100644 ---- a/gcc/system.h -+++ b/gcc/system.h -@@ -194,27 +194,8 @@ extern int fprintf_unlocked (FILE *, const char *, ...); - #undef fread_unlocked - #undef fwrite_unlocked - --/* Include before "safe-ctype.h" to avoid GCC poisoning -- the ctype macros through safe-ctype.h */ -- --#ifdef __cplusplus --#ifdef INCLUDE_STRING --# include --#endif --#endif -- --/* There are an extraordinary number of issues with . -- The last straw is that it varies with the locale. Use libiberty's -- replacement instead. */ --#include "safe-ctype.h" -- --#include -- --#include -- --#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO --extern int errno; --#endif -+/* Include C++ standard headers before "safe-ctype.h" to avoid GCC -+ poisoning the ctype macros through safe-ctype.h */ - - #ifdef __cplusplus - #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY) -@@ -229,6 +210,9 @@ extern int errno; - #ifdef INCLUDE_SET - # include - #endif -+#ifdef INCLUDE_STRING -+# include -+#endif - #ifdef INCLUDE_VECTOR - # include - #endif -@@ -245,6 +229,19 @@ extern int errno; - # include - #endif - -+/* There are an extraordinary number of issues with . -+ The last straw is that it varies with the locale. Use libiberty's -+ replacement instead. */ -+#include "safe-ctype.h" -+ -+#include -+ -+#include -+ -+#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO -+extern int errno; -+#endif -+ - /* Some of glibc's string inlines cause warnings. Plus we'd rather - rely on (and therefore test) GCC's string builtins. */ - #define __NO_STRING_INLINES -diff --git a/libcody/client.cc b/libcody/client.cc -index ae69d190c..147fecdbe 100644 ---- a/libcody/client.cc -+++ b/libcody/client.cc -@@ -97,7 +97,7 @@ int Client::CommunicateWithServer () - - static Packet CommunicationError (int err) - { -- std::string e {u8"communication error:"}; -+ std::string e {(const char *) u8"communication error:"}; - e.append (strerror (err)); - - return Packet (Client::PC_ERROR, std::move (e)); -@@ -110,33 +110,34 @@ Packet Client::ProcessResponse (std::vector &words, - { - if (e == EINVAL) - { -- std::string msg (u8"malformed string '"); -+ std::string msg ((const char *) u8"malformed string '"); - msg.append (words[0]); -- msg.append (u8"'"); -+ msg.append ((const char *) u8"'"); - return Packet (Client::PC_ERROR, std::move (msg)); - } - else -- return Packet (Client::PC_ERROR, u8"missing response"); -+ return Packet (Client::PC_ERROR, (const char *) u8"missing response"); - } - - Assert (!words.empty ()); -- if (words[0] == u8"ERROR") -+ if (words[0] == (const char *) u8"ERROR") - return Packet (Client::PC_ERROR, -- words.size () == 2 ? words[1]: u8"malformed error response"); -+ words.size () == 2 ? words[1] -+ : (const char *) u8"malformed error response"); - - if (isLast && !read.IsAtEnd ()) - return Packet (Client::PC_ERROR, -- std::string (u8"unexpected extra response")); -+ std::string ((const char *) u8"unexpected extra response")); - - Assert (code < Detail::RC_HWM); - Packet result (responseTable[code] (words)); - result.SetRequest (code); - if (result.GetCode () == Client::PC_ERROR && result.GetString ().empty ()) - { -- std::string msg {u8"malformed response '"}; -+ std::string msg {(const char *) u8"malformed response '"}; - - read.LexedLine (msg); -- msg.append (u8"'"); -+ msg.append ((const char *) u8"'"); - result.GetString () = std::move (msg); - } - else if (result.GetCode () == Client::PC_CONNECT) -@@ -199,7 +200,7 @@ Packet Client::Connect (char const *agent, char const *ident, - size_t alen, size_t ilen) - { - write.BeginLine (); -- write.AppendWord (u8"HELLO"); -+ write.AppendWord ((const char *) u8"HELLO"); - write.AppendInteger (Version); - write.AppendWord (agent, true, alen); - write.AppendWord (ident, true, ilen); -@@ -211,7 +212,8 @@ Packet Client::Connect (char const *agent, char const *ident, - // HELLO $version $agent [$flags] - Packet ConnectResponse (std::vector &words) - { -- if (words[0] == u8"HELLO" && (words.size () == 3 || words.size () == 4)) -+ if (words[0] == (const char *) u8"HELLO" -+ && (words.size () == 3 || words.size () == 4)) - { - char *eptr; - unsigned long val = strtoul (words[1].c_str (), &eptr, 10); -@@ -247,7 +249,7 @@ Packet Client::ModuleRepo () - // PATHNAME $dir | ERROR - Packet PathnameResponse (std::vector &words) - { -- if (words[0] == u8"PATHNAME" && words.size () == 2) -+ if (words[0] == (const char *) u8"PATHNAME" && words.size () == 2) - return Packet (Client::PC_PATHNAME, std::move (words[1])); - - return Packet (Client::PC_ERROR, u8""); -@@ -256,7 +258,7 @@ Packet PathnameResponse (std::vector &words) - // OK or ERROR - Packet OKResponse (std::vector &words) - { -- if (words[0] == u8"OK") -+ if (words[0] == (const char *) u8"OK") - return Packet (Client::PC_OK); - else - return Packet (Client::PC_ERROR, -@@ -319,11 +321,11 @@ Packet Client::IncludeTranslate (char const *include, Flags flags, size_t ilen) - // PATHNAME $cmifile - Packet IncludeTranslateResponse (std::vector &words) - { -- if (words[0] == u8"BOOL" && words.size () == 2) -+ if (words[0] == (const char *) u8"BOOL" && words.size () == 2) - { -- if (words[1] == u8"FALSE") -- return Packet (Client::PC_BOOL, 0); -- else if (words[1] == u8"TRUE") -+ if (words[1] == (const char *) u8"FALSE") -+ return Packet (Client::PC_BOOL); -+ else if (words[1] == (const char *) u8"TRUE") - return Packet (Client::PC_BOOL, 1); - else - return Packet (Client::PC_ERROR, u8""); -diff --git a/libcody/cody.hh b/libcody/cody.hh -index 789ce9e70..93bce93aa 100644 ---- a/libcody/cody.hh -+++ b/libcody/cody.hh -@@ -47,12 +47,21 @@ namespace Detail { - - // C++11 doesn't have utf8 character literals :( - -+#if __cpp_char8_t >= 201811 -+template -+constexpr char S2C (char8_t const (&s)[I]) -+{ -+ static_assert (I == 2, "only single octet strings may be converted"); -+ return s[0]; -+} -+#else - template - constexpr char S2C (char const (&s)[I]) - { - static_assert (I == 2, "only single octet strings may be converted"); - return s[0]; - } -+#endif - - /// Internal buffering class. Used to concatenate outgoing messages - /// and Lex incoming ones. -@@ -123,6 +132,13 @@ public: - Space (); - Append (str, maybe_quote, len); - } -+#if __cpp_char8_t >= 201811 -+ void AppendWord (char8_t const *str, bool maybe_quote = false, -+ size_t len = ~size_t (0)) -+ { -+ AppendWord ((const char *) str, maybe_quote, len); -+ } -+#endif - /// Add a word as with AppendWord - /// @param str the string to append - /// @param maybe_quote string might need quoting, as for Append -@@ -264,6 +280,12 @@ public: - : string (s), cat (STRING), code (c) - { - } -+#if __cpp_char8_t >= 201811 -+ Packet (unsigned c, const char8_t *s) -+ : string ((const char *) s), cat (STRING), code (c) -+ { -+ } -+#endif - Packet (unsigned c, std::vector &&v) - : vector (std::move (v)), cat (VECTOR), code (c) - { -diff --git a/libcody/server.cc b/libcody/server.cc -index e2fa069bb..c18469fae 100644 ---- a/libcody/server.cc -+++ b/libcody/server.cc -@@ -36,12 +36,12 @@ static RequestPair - const requestTable[Detail::RC_HWM] = - { - // Same order as enum RequestCode -- RequestPair {u8"HELLO", nullptr}, -- RequestPair {u8"MODULE-REPO", ModuleRepoRequest}, -- RequestPair {u8"MODULE-EXPORT", ModuleExportRequest}, -- RequestPair {u8"MODULE-IMPORT", ModuleImportRequest}, -- RequestPair {u8"MODULE-COMPILED", ModuleCompiledRequest}, -- RequestPair {u8"INCLUDE-TRANSLATE", IncludeTranslateRequest}, -+ RequestPair {(const char *) u8"HELLO", nullptr}, -+ RequestPair {(const char *) u8"MODULE-REPO", ModuleRepoRequest}, -+ RequestPair {(const char *) u8"MODULE-EXPORT", ModuleExportRequest}, -+ RequestPair {(const char *) u8"MODULE-IMPORT", ModuleImportRequest}, -+ RequestPair {(const char *) u8"MODULE-COMPILED", ModuleCompiledRequest}, -+ RequestPair {(const char *) u8"INCLUDE-TRANSLATE", IncludeTranslateRequest}, - }; - } - -@@ -135,21 +135,21 @@ void Server::ProcessRequests (void) - std::string msg; - - if (err > 0) -- msg = u8"error processing '"; -+ msg = (const char *) u8"error processing '"; - else if (ix >= Detail::RC_HWM) -- msg = u8"unrecognized '"; -+ msg = (const char *) u8"unrecognized '"; - else if (IsConnected () && ix == Detail::RC_CONNECT) -- msg = u8"already connected '"; -+ msg = (const char *) u8"already connected '"; - else if (!IsConnected () && ix != Detail::RC_CONNECT) -- msg = u8"not connected '"; -+ msg = (const char *) u8"not connected '"; - else -- msg = u8"malformed '"; -+ msg = (const char *) u8"malformed '"; - - read.LexedLine (msg); -- msg.append (u8"'"); -+ msg.append ((const char *) u8"'"); - if (err > 0) - { -- msg.append (u8" "); -+ msg.append ((const char *) u8" "); - msg.append (strerror (err)); - } - resolver->ErrorResponse (this, std::move (msg)); -@@ -176,7 +176,7 @@ Resolver *ConnectRequest (Server *s, Resolver *r, - return nullptr; - - if (words.size () == 3) -- words.emplace_back (u8""); -+ words.emplace_back ((const char *) u8""); - unsigned version = ParseUnsigned (words[1]); - if (version == ~0u) - return nullptr; -diff --git a/libgcc/config.host b/libgcc/config.host -index 9d7212028..7ddde1dc4 100644 ---- a/libgcc/config.host -+++ b/libgcc/config.host -@@ -1224,6 +1224,9 @@ powerpc-*-rtems*) +diff '--color=auto' -urN a/libgcc/config.host b/libgcc/config.host +--- a/libgcc/config.host 2022-05-27 09:21:12.000000000 +0200 ++++ b/libgcc/config.host 2023-01-01 14:29:07.913987821 +0100 +@@ -1134,6 +1134,8 @@ tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-savresfgpr rs6000/t-crtstuff t-crtstuff-pic t-fdpbit" extra_parts="$extra_parts crtbeginS.o crtendS.o crtbeginT.o ecrti.o ecrtn.o ncrti.o ncrtn.o" ;; +powerpc64-ps3-elf) -+ tmake_file="${tmake_file} rs6000/t-crtstuff-cell64lv2" + ;; powerpc*-*-linux*) tmake_file="${tmake_file} rs6000/t-ppccomm rs6000/t-savresfgpr rs6000/t-crtstuff rs6000/t-linux t-dfprules rs6000/t-ppc64-fp t-slibgcc-libgcc" tmake_file="${tmake_file} t-stack rs6000/t-stack-rs6000" -diff --git a/libgcc/config/rs6000/t-crtstuff-cell64lv2 b/libgcc/config/rs6000/t-crtstuff-cell64lv2 -new file mode 100644 -index 000000000..9eb9ca7ac ---- /dev/null -+++ b/libgcc/config/rs6000/t-crtstuff-cell64lv2 -@@ -0,0 +1 @@ -+CRTSTUFF_T_CFLAGS = -fno-asynchronous-unwind-tables -\ No newline at end of file +diff '--color=auto' -urN a/Makefile.in b/Makefile.in +--- a/Makefile.in 2022-05-27 09:21:10.000000000 +0200 ++++ b/Makefile.in 2023-01-01 14:54:20.241067239 +0100 +@@ -27294,7 +27294,6 @@ + .PHONY: install-libiberty maybe-install-libiberty + maybe-install-libiberty: + @if libiberty +-maybe-install-libiberty: install-libiberty + + install-libiberty: installdirs + @: $(MAKE); $(unstage) + +# Apple Clang 17+ defines TARGET_OS_MAC; do not stub fdopen() on macOS. +diff --git a/zlib/zutil.h b/zlib/zutil.h +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -137,7 +137,7 @@ + # endif + #endif + +-#if defined(MACOS) || defined(TARGET_OS_MAC) ++#if defined(MACOS) || (defined(TARGET_OS_MAC) && !defined(__APPLE__)) + # define OS_CODE 7 + # ifndef Z_SOLO + # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os diff --git a/patches/gcc-9.5.0-PS3-host.patch b/patches/gcc-9.5.0-PS3-host.patch new file mode 100644 index 000000000..3306f48a8 --- /dev/null +++ b/patches/gcc-9.5.0-PS3-host.patch @@ -0,0 +1,60 @@ +# Host GCC 16 / libc++ 17+: include C++ headers before safe-ctype.h on every OS. +diff --git a/gcc/system.h b/gcc/system.h +--- a/gcc/system.h ++++ b/gcc/system.h +@@ -194,27 +194,9 @@ + #undef fread_unlocked + #undef fwrite_unlocked + +-/* Include before "safe-ctype.h" to avoid GCC poisoning +- the ctype macros through safe-ctype.h */ +- +-#ifdef __cplusplus +-#ifdef INCLUDE_STRING +-# include +-#endif +-#endif +- +-/* There are an extraordinary number of issues with . +- The last straw is that it varies with the locale. Use libiberty's +- replacement instead. */ +-#include "safe-ctype.h" +- +-#include +- +-#include +- +-#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO +-extern int errno; +-#endif ++/* Include C++ headers before "safe-ctype.h". Host GCC 16 libstdc++ and ++ libc++ 17+ pull ctype names through //; the ++ poison macros break islower/toupper. */ + + #ifdef __cplusplus + #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY) +@@ -235,8 +217,24 @@ + # include + # include + # include ++# include ++# include ++# include + #endif + ++/* There are an extraordinary number of issues with . ++ The last straw is that it varies with the locale. Use libiberty's ++ replacement instead. */ ++#include "safe-ctype.h" ++ ++#include ++ ++#include ++ ++#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO ++extern int errno; ++#endif ++ + /* Some of glibc's string inlines cause warnings. Plus we'd rather + rely on (and therefore test) GCC's string builtins. */ + #define __NO_STRING_INLINES diff --git a/patches/gcc-9.5.0-PS3-macos-arm64.patch b/patches/gcc-9.5.0-PS3-macos-arm64.patch new file mode 100644 index 000000000..1442b1a90 --- /dev/null +++ b/patches/gcc-9.5.0-PS3-macos-arm64.patch @@ -0,0 +1,105 @@ +# Build GCC 9.5.0 as a cross compiler on Apple Silicon. +diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h +--- a/gcc/config/aarch64/aarch64.h ++++ b/gcc/config/aarch64/aarch64.h +@@ -1088,6 +1088,6 @@ + #define MCPU_TO_MARCH_SPEC_FUNCTIONS \ + { "rewrite_mcpu", aarch64_rewrite_mcpu }, + +-#if defined(__aarch64__) ++#if defined(__aarch64__) && !defined(__APPLE__) + extern const char *host_detect_local_cpu (int argc, const char **argv); + #define HAVE_LOCAL_CPU_DETECT +diff --git a/gcc/config/host-darwin.c b/gcc/config/host-darwin.c +--- a/gcc/config/host-darwin.c ++++ b/gcc/config/host-darwin.c +@@ -22,6 +22,8 @@ + #include "coretypes.h" + #include "diagnostic-core.h" + #include "config/host-darwin.h" ++#include "hosthooks.h" ++#include "hosthooks-def.h" + + /* Yes, this is really supposed to work. */ + /* This allows for a pagesize of 16384, which we have on Darwin20, but should +@@ -76,5 +76,7 @@ + gcc_assert (!ret || mmap_result == addr); + } + + return ret; + } ++ ++const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER; +diff --git a/gcc/config.host b/gcc/config.host +index 816a0f06cb..2d9bf9ed48 100644 +--- a/gcc/config.host ++++ b/gcc/config.host +@@ -99,7 +99,8 @@ case ${host} in + esac + + case ${host} in +- aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia*) ++ aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia* |\ ++ aarch64*-*-darwin*) + case ${target} in + aarch64*-*-*) + host_extra_gcc_objs="driver-aarch64.o" +@@ -251,6 +252,10 @@ case ${host} in + host_extra_gcc_objs="${host_extra_gcc_objs} driver-mingw32.o" + host_lto_plugin_soname=liblto_plugin-0.dll + ;; ++ aarch64*-*-darwin*) ++ out_host_hook_obj="${out_host_hook_obj} host-aarch64-darwin.o" ++ host_xmake_file="${host_xmake_file} aarch64/x-darwin" ++ ;; + i[34567]86-*-darwin* | x86_64-*-darwin*) + out_host_hook_obj="${out_host_hook_obj} host-i386-darwin.o" + host_xmake_file="${host_xmake_file} i386/x-darwin" +diff --git a/gcc/config/aarch64/host-aarch64-darwin.c b/gcc/config/aarch64/host-aarch64-darwin.c +new file mode 100644 +index 0000000000..d70f2df3bf +--- /dev/null ++++ b/gcc/config/aarch64/host-aarch64-darwin.c +@@ -0,0 +1,33 @@ ++/* aarch64/arm64-darwin host-specific hook definitions. ++ ++Copyright The GNU Toolchain Authors. ++ ++This file is part of GCC. ++ ++GCC is free software; you can redistribute it and/or modify it under ++the terms of the GNU General Public License as published by the Free ++Software Foundation; either version 3, or (at your option) any later ++version. ++ ++GCC is distributed in the hope that it will be useful, but WITHOUT ANY ++WARRANTY; without even the implied warranty of MERCHANTABILITY or ++FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ++for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GCC; see the file COPYING3. If not see ++. */ ++ ++#define IN_TARGET_CODE 1 ++ ++#include "config.h" ++#include "system.h" ++#include "coretypes.h" ++#include "hosthooks.h" ++#include "hosthooks-def.h" ++#include "config/host-darwin.h" ++ ++/* Darwin doesn't do anything special for arm64/aarch64 hosts; this file ++ exists just to include the generic config/host-darwin.h. */ ++ ++const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER; +diff --git a/gcc/config/aarch64/x-darwin b/gcc/config/aarch64/x-darwin +new file mode 100644 +index 0000000000..6d788d5e89 +--- /dev/null ++++ b/gcc/config/aarch64/x-darwin +@@ -0,0 +1,3 @@ ++host-aarch64-darwin.o : $(srcdir)/config/aarch64/host-aarch64-darwin.c ++ $(COMPILE) $< ++ $(POSTCOMPILE) diff --git a/patches/gdb-8.3.1-PS3.patch b/patches/gdb-8.3.1-PS3.patch index 979fa68ea..d5968b1f3 100644 --- a/patches/gdb-8.3.1-PS3.patch +++ b/patches/gdb-8.3.1-PS3.patch @@ -1,5 +1,48 @@ +# Updated for mac gdb 8.3.1-PS3 by humbertodias +diff --git a/gdb/Makefile.in b/gdb/Makefile.in +index 5614cc3386c..a7942e6c37f 100644 +--- a/gdb/Makefile.in ++++ b/gdb/Makefile.in +@@ -1100,6 +1100,7 @@ COMMON_SFILES = \ + remote-fileio.c \ + remote-notif.c \ + reverse.c \ ++ run-on-main-thread.c \ + rust-lang.c \ + sentinel-frame.c \ + ser-event.c \ +@@ -1362,6 +1363,7 @@ HFILES_NO_SRCDIR = \ + riscv-tdep.h \ + rs6000-aix-tdep.h \ + rs6000-tdep.h \ ++ run-on-main-thread.h \ + s390-linux-tdep.h \ + s390-tdep.h \ + score-tdep.h \ +diff --git a/gdb/python/lib/gdb/command/prompt.py b/gdb/python/lib/gdb/command/prompt.py +index 3d662a7d3f1..04b9e49c229 100644 +--- a/gdb/python/lib/gdb/command/prompt.py ++++ b/gdb/python/lib/gdb/command/prompt.py +@@ -45,7 +45,7 @@ The currently defined substitutions are: + self.hook_set = False + + def get_show_string (self, pvalue): +- if self.value is not '': ++ if self.value: + return "The extended prompt is: " + self.value + else: + return "The extended prompt is not set." +@@ -57,7 +57,7 @@ The currently defined substitutions are: + return "" + + def before_prompt_hook(self, current): +- if self.value is not '': ++ if self.value: + return gdb.prompt.substitute_prompt(self.value) + else: + return None diff --git a/gdb/python/python.c b/gdb/python/python.c -index 67f362b852d0..4bdd2201abc3 100644 +index c23db2c1261..422b61bedf6 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -28,14 +28,13 @@ @@ -18,7 +61,7 @@ index 67f362b852d0..4bdd2201abc3 100644 /* Declared constants and enum for python stack printing. */ static const char python_excp_none[] = "none"; -@@ -228,13 +227,37 @@ +@@ -228,13 +227,37 @@ gdbpy_enter::~gdbpy_enter () m_error->restore (); @@ -57,7 +100,7 @@ index 67f362b852d0..4bdd2201abc3 100644 /* Set the quit flag. */ static void -@@ -248,6 +271,10 @@ +@@ -248,6 +271,10 @@ gdbpy_set_quit_flag (const struct extension_language_defn *extlang) static int gdbpy_check_quit_flag (const struct extension_language_defn *extlang) { @@ -68,7 +111,7 @@ index 67f362b852d0..4bdd2201abc3 100644 return PyOS_InterruptOccurred (); } -@@ -942,60 +969,54 @@ +@@ -942,60 +969,54 @@ gdbpy_source_script (const struct extension_language_defn *extlang, /* A single event. */ struct gdbpy_event { @@ -81,25 +124,20 @@ index 67f362b852d0..4bdd2201abc3 100644 + : m_func (func.release ()) + { + } -+ + +-/* All pending events. */ +-static struct gdbpy_event *gdbpy_event_list; +-/* The final link of the event list. */ +-static struct gdbpy_event **gdbpy_event_list_end; + gdbpy_event (gdbpy_event &&other) + : m_func (other.m_func) + { + other.m_func = nullptr; + } --/* All pending events. */ --static struct gdbpy_event *gdbpy_event_list; --/* The final link of the event list. */ --static struct gdbpy_event **gdbpy_event_list_end; -- -/* So that we can wake up the main thread even when it is blocked in - poll(). */ -static struct serial_event *gdbpy_serial_event; -- --/* The file handler callback. This reads from the internal pipe, and -- then processes the Python event queue. This will always be run in -- the main gdb thread. */ + gdbpy_event (const gdbpy_event &other) + : m_func (other.m_func) + { @@ -107,23 +145,29 @@ index 67f362b852d0..4bdd2201abc3 100644 + Py_XINCREF (m_func); + } --static void --gdbpy_run_events (int error, gdb_client_data client_data) --{ -- gdbpy_enter enter_py (get_current_arch (), current_language); +-/* The file handler callback. This reads from the internal pipe, and +- then processes the Python event queue. This will always be run in +- the main gdb thread. */ + ~gdbpy_event () + { + gdbpy_gil gil; + Py_XDECREF (m_func); + } -+ + +-static void +-gdbpy_run_events (int error, gdb_client_data client_data) +-{ +- gdbpy_enter enter_py (get_current_arch (), current_language); + gdbpy_event &operator= (const gdbpy_event &other) = delete; - /* Clear the event fd. Do this before flushing the events list, so - that any new event post afterwards is sure to re-awake the event - loop. */ - serial_event_clear (gdbpy_serial_event); -- ++ void operator() () ++ { ++ gdbpy_enter enter_py (get_current_arch (), current_language); + - while (gdbpy_event_list) - { - /* Dispatching the event might push a new element onto the event @@ -132,10 +176,7 @@ index 67f362b852d0..4bdd2201abc3 100644 - gdbpy_event_list = gdbpy_event_list->next; - if (gdbpy_event_list == NULL) - gdbpy_event_list_end = &gdbpy_event_list; -+ void operator() () -+ { -+ gdbpy_enter enter_py (get_current_arch (), current_language); - +- - gdbpy_ref<> call_result (PyObject_CallObject (item->event, NULL)); + gdbpy_ref<> call_result (PyObject_CallObject (m_func, NULL)); if (call_result == NULL) @@ -164,7 +205,7 @@ index 67f362b852d0..4bdd2201abc3 100644 if (!PyArg_ParseTuple (args, "O", &func)) return NULL; -@@ -1007,38 +1028,13 @@ +@@ -1007,38 +1028,13 @@ gdbpy_post_event (PyObject *self, PyObject *args) return NULL; } @@ -206,7 +247,7 @@ index 67f362b852d0..4bdd2201abc3 100644 /* This is the extension_language_ops.before_prompt "method". */ -@@ -1573,6 +1569,7 @@ +@@ -1573,6 +1569,7 @@ finalize_python (void *ignore) Py_Finalize (); @@ -214,7 +255,7 @@ index 67f362b852d0..4bdd2201abc3 100644 restore_active_ext_lang (previous_active); } -@@ -1701,7 +1698,6 @@ +@@ -1701,7 +1698,6 @@ do_start_initialization () || gdbpy_initialize_linetable () < 0 || gdbpy_initialize_thread () < 0 || gdbpy_initialize_inferior () < 0 @@ -222,7 +263,7 @@ index 67f362b852d0..4bdd2201abc3 100644 || gdbpy_initialize_eventregistry () < 0 || gdbpy_initialize_py_events () < 0 || gdbpy_initialize_event () < 0 -@@ -1736,8 +1732,7 @@ +@@ -1736,8 +1732,7 @@ do_start_initialization () return false; /* Release the GIL while gdb runs. */ @@ -232,39 +273,11 @@ index 67f362b852d0..4bdd2201abc3 100644 make_final_cleanup (finalize_python, NULL); ---- /dev/null 2023-07-16 09:39:45.472000000 +0200 -+++ b/gdb/run-on-main-thread.h 2023-07-30 10:43:06.264134972 +0200 -@@ -0,0 +1,28 @@ -+/* Run a function on the main thread -+ Copyright (C) 2019 Free Software Foundation, Inc. -+ -+ This file is part of GDB. -+ -+ This program is free software; you can redistribute it and/or modify -+ it under the terms of the GNU General Public License as published by -+ the Free Software Foundation; either version 3 of the License, or -+ (at your option) any later version. -+ -+ This program is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ GNU General Public License for more details. -+ -+ You should have received a copy of the GNU General Public License -+ along with this program. If not, see . */ -+ -+#ifndef GDB_RUN_ON_MAIN_THREAD_H -+#define GDB_RUN_ON_MAIN_THREAD_H -+ -+#include -+ -+/* Send a runnable to the main thread. */ -+ -+extern void run_on_main_thread (std::function &&); -+ -+#endif /* GDB_RUN_ON_MAIN_THREAD_H */ ---- /dev/null 2023-07-16 09:39:45.472000000 +0200 -+++ b/gdb/run-on-main-thread.c 2023-07-30 10:43:03.510435316 +0200 +diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c +new file mode 100644 +index 00000000000..86824b5af4a +--- /dev/null ++++ b/gdb/run-on-main-thread.c @@ -0,0 +1,97 @@ +/* Run a function on the main thread + Copyright (C) 2019 Free Software Foundation, Inc. @@ -363,41 +376,67 @@ index 67f362b852d0..4bdd2201abc3 100644 + runnable_event = make_serial_event (); + add_file_handler (serial_event_fd (runnable_event), run_events, nullptr); +} ---- a/gdb/Makefile.in 2023-07-30 10:45:06.611621149 +0200 -+++ b/gdb/Makefile.in 2023-07-30 10:46:04.284435216 +0200 -@@ -1100,6 +1100,7 @@ - remote-fileio.c \ - remote-notif.c \ - reverse.c \ -+ run-on-main-thread.c \ - rust-lang.c \ - sentinel-frame.c \ - ser-event.c \ -@@ -1362,6 +1363,7 @@ - riscv-tdep.h \ - rs6000-aix-tdep.h \ - rs6000-tdep.h \ -+ run-on-main-thread.h \ - s390-linux-tdep.h \ - s390-tdep.h \ - score-tdep.h \ ---- a/gdb/python/lib/gdb/command/prompt.py -+++ b/gdb/python/lib/gdb/command/prompt.py -@@ -45,7 +45,7 @@ def __init__(self): - self.hook_set = False +diff --git a/gdb/run-on-main-thread.h b/gdb/run-on-main-thread.h +new file mode 100644 +index 00000000000..fd1a2c42532 +--- /dev/null ++++ b/gdb/run-on-main-thread.h +@@ -0,0 +1,28 @@ ++/* Run a function on the main thread ++ Copyright (C) 2019 Free Software Foundation, Inc. ++ ++ This file is part of GDB. ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 3 of the License, or ++ (at your option) any later version. ++ ++ This program is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program. If not, see . */ ++ ++#ifndef GDB_RUN_ON_MAIN_THREAD_H ++#define GDB_RUN_ON_MAIN_THREAD_H ++ ++#include ++ ++/* Send a runnable to the main thread. */ ++ ++extern void run_on_main_thread (std::function &&); ++ ++#endif /* GDB_RUN_ON_MAIN_THREAD_H */ +diff --git a/readline/config.h.in b/readline/config.h.in +index c194e761a45..07b04fceb56 100644 +--- a/readline/config.h.in ++++ b/readline/config.h.in +@@ -234,7 +234,11 @@ + /* Definitions pulled in from aclocal.m4. */ + #undef VOID_SIGHANDLER - def get_show_string (self, pvalue): -- if self.value is not '': -+ if self.value: - return "The extended prompt is: " + self.value - else: - return "The extended prompt is not set." -@@ -57,7 +57,7 @@ def get_set_string (self): - return "" ++#if __APPLE__ ++#define GWINSZ_IN_SYS_IOCTL ++#else + #undef GWINSZ_IN_SYS_IOCTL ++#endif + + #undef STRUCT_WINSIZE_IN_SYS_IOCTL + +# Apple Clang 17+ defines TARGET_OS_MAC; do not stub fdopen() on macOS. +diff --git a/zlib/zutil.h b/zlib/zutil.h +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -137,7 +137,7 @@ + # endif + #endif + +-#if defined(MACOS) || defined(TARGET_OS_MAC) ++#if defined(MACOS) || (defined(TARGET_OS_MAC) && !defined(__APPLE__)) + # define OS_CODE 7 + # ifndef Z_SOLO + # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os - def before_prompt_hook(self, current): -- if self.value is not '': -+ if self.value: - return gdb.prompt.substitute_prompt(self.value) - else: - return None diff --git a/scripts/001-binutils-PPU.sh b/scripts/001-binutils-PPU.sh index 4d54e0f85..dfc7c7395 100755 --- a/scripts/001-binutils-PPU.sh +++ b/scripts/001-binutils-PPU.sh @@ -2,7 +2,7 @@ set -eo pipefail # binutils-PPU.sh by Naomi Peori (naomi@peori.ca) -BINUTILS="binutils-2.22" +BINUTILS="binutils-2.42" source ../utils/utils.sh if [ ! -d ${BINUTILS} ]; then @@ -18,7 +18,7 @@ if [ ! -d ${BINUTILS} ]; then extract "../archives/${BINUTILS}.tar.bz2" ## Patch the source code. - cat ../patches/${BINUTILS}-PS3.patch | patch -p1 -d ${BINUTILS} + cat ../patches/${BINUTILS}-PS3-PPU.patch | patch -p1 -d ${BINUTILS} ## Replace config.guess and config.sub cp ../archives/config.guess ../archives/config.sub ${BINUTILS} @@ -36,19 +36,28 @@ fi cd ${BINUTILS}/build-ppu ## Configure the build. +unset LDFLAGS ../configure --prefix="$PS3DEV/ppu" --target="powerpc64-ps3-elf" \ - --disable-nls \ - --disable-shared \ - --disable-debug \ - --disable-dependency-tracking \ - --disable-werror \ - --enable-64-bit-bfd \ - --with-gcc \ - --with-gnu-as \ - --with-gnu-ld + --with-gcc \ + --with-gnu-as \ + --with-gnu-ld \ + --enable-64-bit-bfd \ + --enable-lto \ + --disable-nls \ + --disable-shared \ + --disable-debug \ + --disable-dependency-tracking \ + --disable-werror \ + --disable-gprofng \ + --disable-install-libiberty \ + --with-system-zlib ## Compile and install. +## Do not override libdir: binutils 2.42 installs libdep.la into +## $libdir/bfd-plugins and libtool requires that path to be absolute. PROCS="$(nproc --all 2>&1)" || ret=$? if [ ! -z $ret ]; then PROCS=4; fi ${MAKE:-make} -j $PROCS -${MAKE:-make} libdir=host-libs/lib MULTIOSDIR=. install +${MAKE:-make} install +# Host libiberty can still land under prefix on some configure defaults. +rm -f "$PS3DEV/ppu/lib/libiberty.a" "$PS3DEV/ppu/lib64/libiberty.a" diff --git a/scripts/002-gcc-newlib-PPU.sh b/scripts/002-gcc-newlib-PPU.sh index b6166ec52..5175edef5 100755 --- a/scripts/002-gcc-newlib-PPU.sh +++ b/scripts/002-gcc-newlib-PPU.sh @@ -16,27 +16,23 @@ if [ ! -d ${GCC} ]; then ../config/get-config-scripts.sh ## Unpack the source code. - echo "Unpacking ${GCC}" - extract "../archives/${GCC}.tar.xz" - - if [ ! -d ${NEWLIB} ]; then - - echo "Unpacking ${NEWLIB}" - extract "../archives/${NEWLIB}.tar.gz" - - ## Patch the source code. - cat ../patches/${NEWLIB}-PS3.patch | patch -p1 -d ${NEWLIB} - - ## Replace config.guess and config.sub - cp ../archives/config.guess ../archives/config.sub ${NEWLIB} - - fi + unpack_if_needed "../archives/${GCC}.tar.xz" "${GCC}" + unpack_if_needed "../archives/${NEWLIB}.tar.gz" "${NEWLIB}" ## Patch the source code. - cat ../patches/${GCC}-PS3.patch | patch -p1 -d ${GCC} + apply_patch "../patches/${GCC}-PS3-PPU.patch" "${GCC}" + apply_patch "../patches/${NEWLIB}-PS3.patch" "${NEWLIB}" + + ## Host GCC 16 / libc++ 17+: safe-ctype vs /, libcody char8_t + apply_patch "../patches/${GCC}-PS3-host.patch" "${GCC}" + ## Apple Silicon host_hooks / native aarch64 detect + if [[ $(uname -s) == 'Darwin' && $(uname -m) == 'arm64' ]]; then + apply_patch "../patches/${GCC}-PS3-macos-arm64.patch" "${GCC}" + fi ## Replace config.guess and config.sub cp ../archives/config.guess ../archives/config.sub ${GCC} + cp ../archives/config.guess ../archives/config.sub ${NEWLIB} ## Enter the source code directory. cd ${GCC} @@ -60,6 +56,9 @@ if [ ! -d ${GCC}/build-ppu ]; then fi +## newlib 1.20 config.sub rejects aarch64-apple-darwin (Apple Silicon). +refresh_config_scripts "${NEWLIB}" "${GCC}" + ## Enter the build directory. cd ${GCC}/build-ppu diff --git a/scripts/003-gdb-PPU.sh b/scripts/003-gdb-PPU.sh new file mode 100755 index 000000000..4866d57ce --- /dev/null +++ b/scripts/003-gdb-PPU.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -eo pipefail +# gdb-PPU.sh by Naomi Peori (naomi@peori.ca) + +GDB="gdb-8.3.1" +source ../utils/utils.sh + +if [ ! -d ${GDB} ]; then + + ## Download the source code. + ../download.sh ${GDB}.tar.xz + + ## Fetch config.guess and config.sub, falling back to copies if Savannah is unavailable + ../config/get-config-scripts.sh + + ## Unpack the source code. + unpack_if_needed "../archives/${GDB}.tar.xz" "${GDB}" + + ## Patch the source code. + apply_patch "../patches/${GDB}-PS3.patch" "${GDB}" + + ## Replace config.guess and config.sub + cp ../archives/config.guess ../archives/config.sub ${GDB} + +fi + +if [ ! -d ${GDB}/build-ppu ]; then + + ## Create the build directory. + mkdir ${GDB}/build-ppu + +fi + +## Enter the build directory. +cd ${GDB}/build-ppu + +## Configure the build. +## pyenv ships Python 3.10; gdb 8.3.1 cannot build against that ABI. +## Host GCC 15/16 default to C23; bundled readline expects pre-C23 +## unprototyped signal handlers (VOID_SIGHANDLER). +CFLAGS="${CFLAGS:-} -std=gnu17 -Wno-incompatible-pointer-types -Wno-int-conversion" \ +CXXFLAGS="${CXXFLAGS:-} -std=gnu++17 -Wno-narrowing" \ +../configure --prefix="$PS3DEV/ppu" --target="powerpc64-ps3-elf" \ + --disable-multilib \ + --disable-nls \ + --disable-sim \ + --disable-werror \ + --with-python=no \ + --without-guile + +## Compile and install. +PROCS="$(nproc --all 2>&1)" || ret=$? +if [ ! -z $ret ]; then PROCS=4; fi +${MAKE:-make} -j $PROCS +${MAKE:-make} libdir="$(pwd)/host-libs/lib" install diff --git a/scripts/005-binutils-SPU.sh b/scripts/005-binutils-SPU.sh index b2c2c2186..14b7e41b4 100755 --- a/scripts/005-binutils-SPU.sh +++ b/scripts/005-binutils-SPU.sh @@ -14,11 +14,10 @@ if [ ! -d ${BINUTILS} ]; then ../config/get-config-scripts.sh ## Unpack the source code. - echo "Unpacking ${BINUTILS}" - extract "../archives/${BINUTILS}.tar.bz2" + unpack_if_needed "../archives/${BINUTILS}.tar.bz2" "${BINUTILS}" ## Patch the source code. - cat ../patches/${BINUTILS}-PS3.patch | patch -p1 -d ${BINUTILS} + apply_patch "../patches/${BINUTILS}-PS3-SPU.patch" "${BINUTILS}" ## Replace config.guess and config.sub cp ../archives/config.guess ../archives/config.sub ${BINUTILS} @@ -36,6 +35,8 @@ fi cd ${BINUTILS}/build-spu ## Configure the build. +## Host GCC 15/16 default to C23; binutils 2.22 uses K&R-era C. +CFLAGS="${CFLAGS:-} -std=gnu17 -Wno-incompatible-pointer-types -Wno-int-conversion -Wno-implicit-function-declaration" \ ../configure --prefix="$PS3DEV/spu" --target="spu" \ --disable-nls \ --disable-shared \ @@ -44,7 +45,9 @@ cd ${BINUTILS}/build-spu --disable-werror \ --with-gcc \ --with-gnu-as \ - --with-gnu-ld + --with-gnu-ld \ + --enable-lto \ + --with-system-zlib ## Compile and install. PROCS="$(nproc --all 2>&1)" || ret=$? diff --git a/scripts/006-gcc-newlib-SPU.sh b/scripts/006-gcc-newlib-SPU.sh index 625abf940..da4b4ca6f 100755 --- a/scripts/006-gcc-newlib-SPU.sh +++ b/scripts/006-gcc-newlib-SPU.sh @@ -16,27 +16,24 @@ if [ ! -d ${GCC} ]; then ../config/get-config-scripts.sh ## Unpack the source code. - echo "Unpacking ${GCC}" - extract "../archives/${GCC}.tar.xz" - - if [ ! -d ${NEWLIB} ]; then - - echo "Unpacking ${NEWLIB}" - extract "../archives/${NEWLIB}.tar.gz" - - ## Patch the source code. - cat ../patches/${NEWLIB}-PS3.patch | patch -p1 -d ${NEWLIB} - - ## Replace config.guess and config.sub - cp ../archives/config.guess ../archives/config.sub ${NEWLIB} - + unpack_if_needed "../archives/${GCC}.tar.xz" "${GCC}" + unpack_if_needed "../archives/${NEWLIB}.tar.gz" "${NEWLIB}" + + ## Patch the source code. newlib is shared with the PPU step and + ## must not be unpacked/patched a second time. + apply_patch "../patches/${GCC}-PS3-SPU.patch" "${GCC}" + apply_patch "../patches/${NEWLIB}-PS3.patch" "${NEWLIB}" + + ## Host GCC 16 / libc++ 17+: safe-ctype vs / + apply_patch "../patches/${GCC}-PS3-host.patch" "${GCC}" + ## Apple Silicon host_hooks / native aarch64 detect + if [[ $(uname -s) == 'Darwin' && $(uname -m) == 'arm64' ]]; then + apply_patch "../patches/${GCC}-PS3-macos-arm64.patch" "${GCC}" fi - ## Patch the source code. - cat ../patches/${GCC}-PS3.patch | patch -p1 -d ${GCC} - ## Replace config.guess and config.sub cp ../archives/config.guess ../archives/config.sub ${GCC} + cp ../archives/config.guess ../archives/config.sub ${NEWLIB} ## Enter the source code directory. cd ${GCC} @@ -60,10 +57,14 @@ if [ ! -d ${GCC}/build-spu ]; then fi +## newlib 1.20 config.sub rejects aarch64-apple-darwin (Apple Silicon). +refresh_config_scripts "${NEWLIB}" "${GCC}" + ## Enter the build directory. cd ${GCC}/build-spu ## Configure the build. +unset CFLAGS CXXFLAGS LDFLAGS CFLAGS_FOR_TARGET="-Os -fpic -ffast-math -ftree-vectorize -funroll-loops -fschedule-insns -mdual-nops -mwarn-reloc" \ CFLAGS="-Wno-int-conversion" \ CXXFLAGS="-Wno-int-conversion" \ diff --git a/scripts/007-gdb-SPU.sh b/scripts/007-gdb-SPU.sh new file mode 100755 index 000000000..48d9563d9 --- /dev/null +++ b/scripts/007-gdb-SPU.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -eo pipefail +# gdb-SPU.sh by Naomi Peori (naomi@peori.ca) + +GDB="gdb-8.3.1" +source ../utils/utils.sh + +if [ ! -d ${GDB} ]; then + + ## Download the source code. + ../download.sh ${GDB}.tar.xz + + ## Fetch config.guess and config.sub, falling back to copies if Savannah is unavailable + ../config/get-config-scripts.sh + + ## Unpack the source code. + unpack_if_needed "../archives/${GDB}.tar.xz" "${GDB}" + + ## Patch the source code. + apply_patch "../patches/${GDB}-PS3.patch" "${GDB}" + + ## Replace config.guess and config.sub + cp ../archives/config.guess ../archives/config.sub ${GDB} + +fi + +if [ ! -d ${GDB}/build-spu ]; then + + ## Create the build directory. + mkdir ${GDB}/build-spu + +fi + +## Enter the build directory. +cd ${GDB}/build-spu + +## Configure the build. +## pyenv ships Python 3.10; gdb 8.3.1 cannot build against that ABI. +## Host GCC 15/16 default to C23; bundled readline expects pre-C23 +## unprototyped signal handlers (VOID_SIGHANDLER). +CFLAGS="${CFLAGS:-} -std=gnu17 -Wno-incompatible-pointer-types -Wno-int-conversion" \ +CXXFLAGS="${CXXFLAGS:-} -std=gnu++17 -Wno-narrowing" \ +../configure --prefix="$PS3DEV/spu" --target="spu" \ + --disable-nls \ + --disable-sim \ + --disable-werror \ + --with-python=no \ + --without-guile + +## Compile and install. +PROCS="$(nproc --all 2>&1)" || ret=$? +if [ ! -z $ret ]; then PROCS=4; fi +${MAKE:-make} -j $PROCS +${MAKE:-make} libdir="$(pwd)/host-libs/lib" install diff --git a/scripts/009-ps3libraries.sh b/scripts/009-ps3libraries.sh index 1236e6235..3d899dda1 100755 --- a/scripts/009-ps3libraries.sh +++ b/scripts/009-ps3libraries.sh @@ -10,6 +10,9 @@ fi source ../utils/utils.sh +## Host CC/CXX (common in Docker) makes autotools skip powerpc64-ps3-elf-gcc. +unset CC CXX CPP + ## Download the source code. ../download.sh ps3libraries.tar.gz diff --git a/toolchain.sh b/toolchain.sh index a6b1dc6a9..cdf0d31dd 100755 --- a/toolchain.sh +++ b/toolchain.sh @@ -55,5 +55,5 @@ fi ## Run the build scripts. for SCRIPT in $BUILD_SCRIPTS; do echo ">>> Running: $SCRIPT" - "$SCRIPT" || { echo "$SCRIPT: Failed."; exit 1; } + "$SCRIPT" || { echo "$SCRIPT: Failed (exit $?)."; exit 1; } done diff --git a/utils/utils.sh b/utils/utils.sh index ea1011a90..d37545d40 100755 --- a/utils/utils.sh +++ b/utils/utils.sh @@ -31,4 +31,62 @@ extract() { echo " (pv not found, extracting without progress)" tar "${flag[@]}" -xf "$archive" "$@" fi +} + +# Unpack only if the source directory is not already present. +# Usage: unpack_if_needed +unpack_if_needed() { + local archive="$1" srcdir="$2" + if [ -d "$srcdir" ]; then + echo "Already unpacked: $srcdir" + return 0 + fi + echo "Unpacking $srcdir" + extract "$archive" +} + +# Apply a patch once. Shared trees (newlib) are patched by an earlier +# script; re-applying fails because new files already exist. +# Usage: apply_patch +apply_patch() { + local patchfile="$1" srcdir="$2" + if [ ! -f "$patchfile" ]; then + echo "apply_patch: missing $patchfile" >&2 + return 1 + fi + local stamp="$srcdir/.ps3-patched-$(basename "$patchfile")" + if [ -f "$stamp" ]; then + echo "Already patched: $srcdir ($(basename "$patchfile"))" + return 0 + fi + patch -p1 --batch --forward -d "$srcdir" < "$patchfile" + touch "$stamp" +} + +# Replace GNU config.guess/config.sub so hosts like aarch64-apple-darwin +# are recognized. newlib 1.20 (and other old trees) ship copies that reject +# Apple Silicon. Always refresh, including rebuilds after a failed configure. +# Usage: refresh_config_scripts [srcdir...] +refresh_config_scripts() { + if [ $# -lt 1 ]; then + echo "refresh_config_scripts: missing source directory" >&2 + return 1 + fi + ../config/get-config-scripts.sh + local src_guess="../archives/config.guess" + local src_sub="../archives/config.sub" + if [ ! -f "$src_guess" ] || [ ! -f "$src_sub" ]; then + echo "refresh_config_scripts: missing $src_guess or $src_sub" >&2 + return 1 + fi + local dest + for dest in "$@"; do + if [ ! -d "$dest" ]; then + echo "refresh_config_scripts: not a directory: $dest" >&2 + return 1 + fi + echo "Refreshing config.guess/config.sub in $dest" + find "$dest" -name config.guess -exec cp "$src_guess" {} \; + find "$dest" -name config.sub -exec cp "$src_sub" {} \; + done } \ No newline at end of file