From 97e7de7d7bc267e6d3d244c8a7e21d17c1ae7bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=85=D9=87=D8=AF=D9=8A=20=D8=B4=D9=8A=D9=86=D9=88=D9=86?= =?UTF-8?q?=20=28Mehdi=20Chinoune=29?= Date: Sun, 14 May 2023 15:53:57 +0100 Subject: [PATCH] gcc: Fix exception handling on mingw32 --- ...22-fix-radix-sort-on-32bit-platforms.patch | 55 +++++++++++++++++++ mingw-w64-gcc/PKGBUILD | 12 ++-- 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 mingw-w64-gcc/0022-fix-radix-sort-on-32bit-platforms.patch diff --git a/mingw-w64-gcc/0022-fix-radix-sort-on-32bit-platforms.patch b/mingw-w64-gcc/0022-fix-radix-sort-on-32bit-platforms.patch new file mode 100644 index 0000000000..43648adbd1 --- /dev/null +++ b/mingw-w64-gcc/0022-fix-radix-sort-on-32bit-platforms.patch @@ -0,0 +1,55 @@ +From c7c22c10118d9f738ce60c97675def01c5e2d33d Mon Sep 17 00:00:00 2001 +From: Thomas Neumann +Date: Wed, 10 May 2023 12:33:49 +0200 +Subject: [PATCH] fix radix sort on 32bit platforms [PR109670] + +The radix sort uses two buffers, a1 for input and a2 for output. +After every digit the role of the two buffers is swapped. +When terminating the sort early the code made sure the output +was in a2. However, when we run out of bits, as can happen on +32bit platforms, the sorted result was in a1, was we had just +swapped a1 and a2. +This patch fixes the problem by unconditionally having a1 as +output after every loop iteration. + +This bug manifested itself only on 32bit platforms and even then +only in some circumstances, as it needs frames where a swap +is required due to differences in the top-most byte, which is +affected by ASLR. The new logic was validated by exhaustive +search over 32bit input values. + +libgcc/ChangeLog: + * unwind-dw2-fde.c: Fix radix sort buffer management. +--- + libgcc/unwind-dw2-fde.c | 8 +++----- + 1 file changed, 3 insertions(+), 5 deletions(-) + +diff --git a/libgcc/unwind-dw2-fde.c b/libgcc/unwind-dw2-fde.c +index 7b74c391ced..31a3834156b 100644 +--- a/libgcc/unwind-dw2-fde.c ++++ b/libgcc/unwind-dw2-fde.c +@@ -624,8 +624,6 @@ fde_radixsort (struct object *ob, fde_extractor_t fde_extractor, + // Stop if we are already sorted. + if (!violations) + { +- // The sorted data is in a1 now. +- a2 = a1; + break; + } + +@@ -660,9 +658,9 @@ fde_radixsort (struct object *ob, fde_extractor_t fde_extractor, + #undef FANOUT + #undef FANOUTBITS + +- // The data is in a2 now, move in place if needed. +- if (a2 != v1->array) +- memcpy (v1->array, a2, sizeof (const fde *) * n); ++ // The data is in a1 now, move in place if needed. ++ if (a1 != v1->array) ++ memcpy (v1->array, a1, sizeof (const fde *) * n); + } + + static inline void +-- +2.39.2 + diff --git a/mingw-w64-gcc/PKGBUILD b/mingw-w64-gcc/PKGBUILD index 6912efbc96..73a5bccaa1 100644 --- a/mingw-w64-gcc/PKGBUILD +++ b/mingw-w64-gcc/PKGBUILD @@ -26,7 +26,7 @@ pkgver=13.1.0 #_majorver=${pkgver:0:1} #_sourcedir=${_realname}-${_majorver}-${_snapshot} _sourcedir=${_realname}-${pkgver} -pkgrel=5 +pkgrel=6 pkgdesc="GCC for the MinGW-w64" arch=('any') mingw_arch=('mingw32' 'mingw64' 'ucrt64') @@ -64,10 +64,10 @@ source=("https://ftp.gnu.org/gnu/gcc/${_realname}-${pkgver%%+*}/${_realname}-${p 0014-gcc-9-branch-clone_function_name_1-Retain-any-stdcall-suffix.patch 0020-libgomp-Don-t-hard-code-MS-printf-attributes.patch 0021-PR14940-Allow-a-PCH-to-be-mapped-to-a-different-addr.patch + 0022-fix-radix-sort-on-32bit-platforms.patch 0140-gcc-diagnostic-color.patch 0200-add-m-no-align-vector-insn-option-for-i386.patch 0300-override-builtin-printf-format.patch - https://github.com/gcc-mirror/gcc/commit/1c118c9970600117700cc12284587e0238de6bbe.patch 2000-enable-rust.patch 2001-fix-building-rust-on-mingw-w64.patch) sha256sums=('61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86' @@ -84,10 +84,10 @@ sha256sums=('61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86' 'fd9bdecb2bbc4796bbc9f00b708dac42ef9e3464a06d6d27e5475cee117de5be' 'ad1f7b5e7afaaec008b7cbd14feea13a10989fa91bda7003af72d457619bb199' '6c272078340a27b3f147e497115b0a6e9fc0da720a2602f12b086524522caa59' + '45950ed7a6a14436bde40e717eef07160671bfbbf41c2251f95a3f8c660bef6b' 'e0a5b470f49a29f20215cc9f9d04c1cb9969dff6f0e546542799d3a693ef1c84' 'c34f9e71b5a092be1987ad4c65891742c74c9eb8ef6560100e751cd31375f579' 'f73c8d1701762fed7d8102d17d8e4416a4cc5e600e297a89c2e1fe09cd743a1c' - 'aecce97a914cead59a1bbb90fba2f7645dfa5d8bb7dbf9eedb94cade2270a1c2' '693a91a863a706b3526af01c9de5ce8295c59ef0f56f009bcfbf79a93cba2728' 'e78d51c908cd4e5c905c62e8350db1c609479bb95333c67f706b56974226fd94') validpgpkeys=(F3691687D867B81B51CE07D9BBE43771487328A9 # bpiotrowski@archlinux.org @@ -158,9 +158,9 @@ prepare() { apply_patch_with_msg \ 2001-fix-building-rust-on-mingw-w64.patch - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109670#c7 - # https://github.com/gcc-mirror/gcc/commit/1c118c9970600117700cc12284587e0238de6bbe - patch -R -Nbp1 -i "${srcdir}/1c118c9970600117700cc12284587e0238de6bbe.patch" + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109670#c12 + apply_patch_with_msg \ + 0022-fix-radix-sort-on-32bit-platforms.patch # do not expect ${prefix}/mingw symlink - this should be superceded by # 0005-Windows-Don-t-ignore-native-system-header-dir.patch .. but isn't!