From ae21002cb591ca88b214ac0b837dac9cb6dbd081 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Tue, 1 Aug 2023 17:14:43 +0200 Subject: [PATCH] Toolchain+Ports: Update GCC to 13.2.0 This is a minor bugfix release, which to my knowledge contains nothing of importance to us. However, there is one QoL change to our patches. We no longer force `-fpic` in the compiler driver, and instead use the `--enable-default-pie` configure option to generate position-independent code suitable for executables. For building shared libraries, the `-fpic` flag must be specified explicitly. --- CMakeLists.txt | 2 +- Ports/AvailablePorts.md | 2 +- Ports/gcc/package.sh | 4 +-- Toolchain/BuildGNU.sh | 4 +-- ...0001-Add-a-gcc-driver-for-SerenityOS.patch | 19 +++++------- .../0003-libgcc-Build-for-SerenityOS.patch | 8 ++--- ...86-Disable-math-errno-for-SerenityOS.patch | 2 +- .../gcc/0006-libstdc-Support-SerenityOS.patch | 14 ++++----- ...bstdc-Build-static-library-with-fPIC.patch | 29 +++++++++++++++++++ Toolchain/Patches/gcc/ReadMe.md | 10 +++++++ 10 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 Toolchain/Patches/gcc/0007-libstdc-Build-static-library-with-fPIC.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 000122f35e5..09570e7dd17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "SerenityOS") endif() # Check for toolchain mismatch, user might need to rebuild toolchain -set(GCC_VERSION "13.1.0") +set(GCC_VERSION "13.2.0") set(LLVM_VERSION "16.0.6") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(EXPECTED_COMPILER_VERSION "${GCC_VERSION}") diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md index 1cd245baa44..a6356afa3d4 100644 --- a/Ports/AvailablePorts.md +++ b/Ports/AvailablePorts.md @@ -87,7 +87,7 @@ This list is also available at [ports.serenityos.net](https://ports.serenityos.n | [`freetype`](freetype/) | FreeType | 2.13.0 | https://www.freetype.org/ | | [`frotz`](frotz/) | Frotz | 2.54 | https://gitlab.com/DavidGriffith/frotz | | [`gawk`](gawk/) | GNU awk | 5.2.1 | https://www.gnu.org/software/gawk/ | -| [`gcc`](gcc/) | GNU Compiler Collection | 13.1.0 | https://gcc.gnu.org/ | +| [`gcc`](gcc/) | GNU Compiler Collection | 13.2.0 | https://gcc.gnu.org/ | | [`gdb`](gdb/) | GNU Project Debugger | 11.2 | https://sourceware.org/gdb | | [`gemrb`](gemrb/) | GemRB | 0.9.1 | https://gemrb.org/ | | [`genemu`](genemu/) | Genesis / MegaDrive Emulator | e39f690 | https://github.com/rasky/genemu | diff --git a/Ports/gcc/package.sh b/Ports/gcc/package.sh index f7281dbf557..1be6bd35764 100755 --- a/Ports/gcc/package.sh +++ b/Ports/gcc/package.sh @@ -1,10 +1,10 @@ #!/usr/bin/env -S bash ../.port_include.sh port=gcc -version=13.1.0 +version=13.2.0 useconfigure=true configopts=("--target=${SERENITY_ARCH}-pc-serenity" "--with-sysroot=/" "--with-build-sysroot=${SERENITY_INSTALL_ROOT}" "--enable-languages=c,c++" "--disable-lto" "--disable-nls" "--enable-shared" "--enable-default-pie" "--enable-host-shared" "--enable-threads=posix" "--enable-initfini-array" "--with-linker-hash-style=gnu") files=( - "https://ftpmirror.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz#61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86" + "https://ftpmirror.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz#e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da" ) makeopts=("all-gcc" "all-target-libgcc" "all-target-libstdc++-v3" "-j$(nproc)") installopts=("DESTDIR=${SERENITY_INSTALL_ROOT}" "install-gcc" "install-target-libgcc" "install-target-libstdc++-v3") diff --git a/Toolchain/BuildGNU.sh b/Toolchain/BuildGNU.sh index 95655d0666f..05ae78c6f74 100755 --- a/Toolchain/BuildGNU.sh +++ b/Toolchain/BuildGNU.sh @@ -82,8 +82,8 @@ BINUTILS_BASE_URL="https://ftpmirror.gnu.org/gnu/binutils" # Note: If you bump the gcc version, you also have to update the matching # GCC_VERSION variable in the project's root CMakeLists.txt -GCC_VERSION="13.1.0" -GCC_MD5SUM="43e4de77f2218c83ca675257ea1af9ef" +GCC_VERSION="13.2.0" +GCC_MD5SUM="e0e48554cc6e4f261d55ddee9ab69075" GCC_NAME="gcc-$GCC_VERSION" GCC_PKG="${GCC_NAME}.tar.xz" GCC_BASE_URL="https://ftpmirror.gnu.org/gnu/gcc" diff --git a/Toolchain/Patches/gcc/0001-Add-a-gcc-driver-for-SerenityOS.patch b/Toolchain/Patches/gcc/0001-Add-a-gcc-driver-for-SerenityOS.patch index 92edb0d2796..3ed58955bd7 100644 --- a/Toolchain/Patches/gcc/0001-Add-a-gcc-driver-for-SerenityOS.patch +++ b/Toolchain/Patches/gcc/0001-Add-a-gcc-driver-for-SerenityOS.patch @@ -19,17 +19,17 @@ Co-Authored-By: Brian Gianforcaro Co-Authored-By: Philip Herron Co-Authored-By: Shannon Booth --- - gcc/config.gcc | 23 +++++++++++++++++ + gcc/config.gcc | 23 ++++++++++++++++++ gcc/config/i386/serenity.h | 7 ++++++ - gcc/config/serenity.h | 51 ++++++++++++++++++++++++++++++++++++++ - gcc/config/serenity.opt | 35 ++++++++++++++++++++++++++ - 4 files changed, 116 insertions(+) + gcc/config/serenity.h | 48 ++++++++++++++++++++++++++++++++++++++ + gcc/config/serenity.opt | 35 +++++++++++++++++++++++++++ + 4 files changed, 113 insertions(+) create mode 100644 gcc/config/i386/serenity.h create mode 100644 gcc/config/serenity.h create mode 100644 gcc/config/serenity.opt diff --git a/gcc/config.gcc b/gcc/config.gcc -index 6fd1594480a1d2054f499573b498781dfafd1d93..6f4fc0f34f4c19c7371d5431aad86f9b0652342b 100644 +index 648b3dc21103e43a315b676c827ff9e6d2923e11..e8a7ea2f50bf908c30b14479bb695cd645261f9e 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -690,6 +690,18 @@ x86_cpus="generic intel" @@ -84,10 +84,10 @@ index 0000000000000000000000000000000000000000..53a4b8e93b74b4808a4bfed91c4d5558 +#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int") diff --git a/gcc/config/serenity.h b/gcc/config/serenity.h new file mode 100644 -index 0000000000000000000000000000000000000000..b1fc4bb63facc9514bf300a84edbaefe56fee324 +index 0000000000000000000000000000000000000000..10c6f16fbe13eab36bab8f6896f8e2a6ae48df02 --- /dev/null +++ b/gcc/config/serenity.h -@@ -0,0 +1,51 @@ +@@ -0,0 +1,48 @@ +/* Useful if you wish to make target-specific GCC changes. */ +#undef TARGET_SERENITY +#define TARGET_SERENITY 1 @@ -114,10 +114,7 @@ index 0000000000000000000000000000000000000000..b1fc4bb63facc9514bf300a84edbaefe +#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!static: %{rdynamic:-export-dynamic} -dynamic-linker /usr/lib/Loader.so}" + +#undef CC1_SPEC -+#define CC1_SPEC "-ftls-model=initial-exec %{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}} -fno-semantic-interposition" -+ -+#undef CC1PLUS_SPEC -+#define CC1PLUS_SPEC "-ftls-model=initial-exec" ++#define CC1_SPEC "-fno-semantic-interposition" + +#undef CPP_SPEC +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" diff --git a/Toolchain/Patches/gcc/0003-libgcc-Build-for-SerenityOS.patch b/Toolchain/Patches/gcc/0003-libgcc-Build-for-SerenityOS.patch index e273eb3d39e..81515ca5b14 100644 --- a/Toolchain/Patches/gcc/0003-libgcc-Build-for-SerenityOS.patch +++ b/Toolchain/Patches/gcc/0003-libgcc-Build-for-SerenityOS.patch @@ -34,10 +34,10 @@ index c7b26d1927de62d7b3a49ea9ac0a998979659cf2..5fcfaa3cfff30d2e8d1cdf3f62bf2125 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then diff --git a/libgcc/config.host b/libgcc/config.host -index b9975de902357576003cf391850fef2dc336aee1..d6cbaae46be819b6b17932d28327dd2658d3f2ad 100644 +index 9d7212028d063648206b521705601ad2b50620c5..9f3c857a1e0cade7171b371c4e823487a5e3b2f2 100644 --- a/libgcc/config.host +++ b/libgcc/config.host -@@ -1294,6 +1294,11 @@ riscv*-*-freebsd*) +@@ -1312,6 +1312,11 @@ riscv*-*-freebsd*) tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address} t-slibgcc-libgcc" extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o" ;; @@ -49,7 +49,7 @@ index b9975de902357576003cf391850fef2dc336aee1..d6cbaae46be819b6b17932d28327dd26 riscv*-*-*) tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}" extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o" -@@ -1507,6 +1512,22 @@ nvptx-*) +@@ -1525,6 +1530,22 @@ nvptx-*) tmake_file="$tmake_file nvptx/t-nvptx" extra_parts="crt0.o" ;; @@ -73,7 +73,7 @@ index b9975de902357576003cf391850fef2dc336aee1..d6cbaae46be819b6b17932d28327dd26 echo "*** Configuration ${host} not supported" 1>&2 exit 1 diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c -index 6223f5f18a23038c30654f191c63b9ae8baca26a..87813e9b249e7add5915ca310c86443a712caa05 100644 +index 28ea0e64e0e8d8c1faf52194a78cfc98398eceb8..2b139330c045ee01651bececc4d882f09f380cce 100644 --- a/libgcc/unwind-dw2-fde-dip.c +++ b/libgcc/unwind-dw2-fde-dip.c @@ -57,6 +57,12 @@ diff --git a/Toolchain/Patches/gcc/0005-i386-Disable-math-errno-for-SerenityOS.patch b/Toolchain/Patches/gcc/0005-i386-Disable-math-errno-for-SerenityOS.patch index 3dbe89128a0..869c7addbbe 100644 --- a/Toolchain/Patches/gcc/0005-i386-Disable-math-errno-for-SerenityOS.patch +++ b/Toolchain/Patches/gcc/0005-i386-Disable-math-errno-for-SerenityOS.patch @@ -11,7 +11,7 @@ has the effect of setting -fno-math-errno by default. 1 file changed, 4 insertions(+) diff --git a/gcc/common/config/i386/i386-common.cc b/gcc/common/config/i386/i386-common.cc -index d90c558311bb4fab0821faaf07c27d21c5a7ec64..defb2e650250441b22664065dceb80c6cb8bbb9b 100644 +index c72644cb7db37b18cb22cf1ff02a972a18509d01..cce666b274cd6129796efc81870428dc17a6f229 100644 --- a/gcc/common/config/i386/i386-common.cc +++ b/gcc/common/config/i386/i386-common.cc @@ -1854,6 +1854,10 @@ ix86_option_init_struct (struct gcc_options *opts) diff --git a/Toolchain/Patches/gcc/0006-libstdc-Support-SerenityOS.patch b/Toolchain/Patches/gcc/0006-libstdc-Support-SerenityOS.patch index 6917c8a983e..35bee384099 100644 --- a/Toolchain/Patches/gcc/0006-libstdc-Support-SerenityOS.patch +++ b/Toolchain/Patches/gcc/0006-libstdc-Support-SerenityOS.patch @@ -27,10 +27,10 @@ Co-Authored-By: Shannon Booth 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 -index 5136c0571e8cb14fd7fd37ac0301a28f32289cc7..6dec4849fb3d86891818b1abac495cf729af64c5 100644 +index 49cb0623e4f04665645b7ef2f0132bced452a892..52b0b2ef38457d5a02e1f21a3e65927402296d90 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 -@@ -1381,7 +1381,7 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ +@@ -1397,7 +1397,7 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ ac_has_nanosleep=yes ac_has_sched_yield=yes ;; @@ -39,7 +39,7 @@ index 5136c0571e8cb14fd7fd37ac0301a28f32289cc7..6dec4849fb3d86891818b1abac495cf7 ac_has_clock_monotonic=yes ac_has_clock_realtime=yes ac_has_nanosleep=yes -@@ -2418,7 +2418,7 @@ AC_DEFUN([GLIBCXX_ENABLE_CLOCALE], [ +@@ -2434,7 +2434,7 @@ AC_DEFUN([GLIBCXX_ENABLE_CLOCALE], [ dragonfly* | freebsd*) enable_clocale_flag=dragonfly ;; @@ -49,7 +49,7 @@ index 5136c0571e8cb14fd7fd37ac0301a28f32289cc7..6dec4849fb3d86891818b1abac495cf7 ;; *) diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure -index 68ee94c9e28e4b2f5390cc9b4bd76b0a84f8f7c7..6c3fd42ddf43baa5e2ca5ccca515c306169afe53 100755 +index 9b6027775456469940da9c515dad5c0160d3cd3d..bd6c4ed05cb9621f855ed15d8e0825e5fc4d2d8c 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -11910,6 +11910,11 @@ else @@ -73,7 +73,7 @@ index 68ee94c9e28e4b2f5390cc9b4bd76b0a84f8f7c7..6c3fd42ddf43baa5e2ca5ccca515c306 enable_clocale_flag=newlib ;; *) -@@ -20609,7 +20614,7 @@ fi +@@ -20675,7 +20680,7 @@ fi ac_has_nanosleep=yes ac_has_sched_yield=yes ;; @@ -82,7 +82,7 @@ index 68ee94c9e28e4b2f5390cc9b4bd76b0a84f8f7c7..6c3fd42ddf43baa5e2ca5ccca515c306 ac_has_clock_monotonic=yes ac_has_clock_realtime=yes ac_has_nanosleep=yes -@@ -29295,7 +29300,7 @@ case "${host}" in +@@ -29361,7 +29366,7 @@ case "${host}" in # This is a freestanding configuration; there is nothing to do here. ;; @@ -92,7 +92,7 @@ index 68ee94c9e28e4b2f5390cc9b4bd76b0a84f8f7c7..6c3fd42ddf43baa5e2ca5ccca515c306 $as_echo "#define HAVE_ASINF 1" >>confdefs.h diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host -index ec32980aa0db898623804980af65dad588e4d9f5..e060300f3777fbd38795954ca75e9c4809cfc4e3 100644 +index 9e7c7f02dfd1cce8ec663b3bd337a2ed4d736aad..609c641ff5e9b4f44db9a6909adb876b5e65349e 100644 --- a/libstdc++-v3/configure.host +++ b/libstdc++-v3/configure.host @@ -297,6 +297,9 @@ case "${host_os}" in diff --git a/Toolchain/Patches/gcc/0007-libstdc-Build-static-library-with-fPIC.patch b/Toolchain/Patches/gcc/0007-libstdc-Build-static-library-with-fPIC.patch new file mode 100644 index 00000000000..cb229821dd4 --- /dev/null +++ b/Toolchain/Patches/gcc/0007-libstdc-Build-static-library-with-fPIC.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Bertalan +Date: Mon, 11 Sep 2023 16:37:27 +0200 +Subject: [PATCH] libstdc++: Build static library with -fPIC + +We want the libstdc++.a library to contain -fPIC code in order to link +it statically into LibC/our shared objects. However, the build system +forces no-pic/pie instead. + +This hack is from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58638 +--- + libstdc++-v3/configure | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure +index bd6c4ed05cb9621f855ed15d8e0825e5fc4d2d8c..de0adb98973432cd6ee8e42adeaf5efa74546484 100755 +--- a/libstdc++-v3/configure ++++ b/libstdc++-v3/configure +@@ -15624,8 +15624,8 @@ if test "$enable_shared" = yes; then + glibcxx_compiler_shared_flag="-D_GLIBCXX_SHARED" + + else +- glibcxx_lt_pic_flag= +- glibcxx_compiler_pic_flag= ++ glibcxx_lt_pic_flag="-prefer-pic" ++ glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX" + glibcxx_compiler_shared_flag= + fi + diff --git a/Toolchain/Patches/gcc/ReadMe.md b/Toolchain/Patches/gcc/ReadMe.md index 0347faaea48..45aa6eb0419 100644 --- a/Toolchain/Patches/gcc/ReadMe.md +++ b/Toolchain/Patches/gcc/ReadMe.md @@ -55,3 +55,13 @@ we have to manually tell libstdc++ about what our LibC supports. In most places, we take the Newlib code paths. +## `0007-libstdc-Build-static-library-with-fPIC.patch` + +libstdc++: Build static library with -fPIC + +We want the libstdc++.a library to contain -fPIC code in order to link +it statically into LibC/our shared objects. However, the build system +forces no-pic/pie instead. + +This hack is from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58638 +