From fe2aaea662041494446a66eeaed8252214f44c16 Mon Sep 17 00:00:00 2001 From: Humberto Dias Date: Sat, 10 Oct 2026 17:02:53 -0300 Subject: [PATCH 1/2] Update PPU binutils to 2.42. SPU stays on 2.22. The 2.42 build uses system zlib, skips gprofng, and installs without overriding libdir so bfd-plugins stays an absolute path. --- archives/archives.txt | 1 + patches/binutils-2.42-PS3-PPU.patch | 90 +++++++++++++++++++++++++++++ scripts/001-binutils-PPU.sh | 33 +++++++---- 3 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 patches/binutils-2.42-PS3-PPU.patch diff --git a/archives/archives.txt b/archives/archives.txt index 35fd5be8..9f7dd493 100644 --- a/archives/archives.txt +++ b/archives/archives.txt @@ -1,4 +1,5 @@ 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 diff --git a/patches/binutils-2.42-PS3-PPU.patch b/patches/binutils-2.42-PS3-PPU.patch new file mode 100644 index 00000000..f1aff8f9 --- /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/scripts/001-binutils-PPU.sh b/scripts/001-binutils-PPU.sh index 4d54e0f8..dfc7c739 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" From 84dbc3293122fc3aa068c627ffbb60b587813871 Mon Sep 17 00:00:00 2001 From: Humberto Dias Date: Sun, 11 Oct 2026 12:18:46 -0300 Subject: [PATCH 2/2] Leave host LDFLAGS to toolchain.sh. Clearing them only in the PPU binutils script misses the other build steps. --- scripts/001-binutils-PPU.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/001-binutils-PPU.sh b/scripts/001-binutils-PPU.sh index dfc7c739..cd32519f 100755 --- a/scripts/001-binutils-PPU.sh +++ b/scripts/001-binutils-PPU.sh @@ -36,7 +36,6 @@ fi cd ${BINUTILS}/build-ppu ## Configure the build. -unset LDFLAGS ../configure --prefix="$PS3DEV/ppu" --target="powerpc64-ps3-elf" \ --with-gcc \ --with-gnu-as \