From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1571) id ED3A1385781F; Sat, 3 Jun 2023 07:47:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED3A1385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685778467; bh=qm8OKoe9aTYryER4AWAMalaQUPxmxk7KvCfGKXlkhrg=; h=From:To:Subject:Date:From; b=HdWQVnslxzF4rux341V0pam0UPsBbVswq4guh2L7hwrVbJT4nJZ9cd52xGisn1GbA s5s0hPHGAb4bcvSBOZsIkK8xdY49LYWPIMv1qlIbP/sMIMceagcq3CJDhTvp+Uz0kN 7Tvw1oelHO3IowD5+Cqm1w2IdO0JhrRwlkxNFtS0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Thomas Neumann To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1515] fix radix sort on 32bit platforms [PR109670] X-Act-Checkin: gcc X-Git-Author: Thomas Neumann X-Git-Refname: refs/heads/master X-Git-Oldrev: 5cf60b6ba111f4169305c7832b063b000e9ec36a X-Git-Newrev: 38e88d41f50d844f1404172657ef7e8372014ef6 Message-Id: <20230603074747.ED3A1385781F@sourceware.org> Date: Sat, 3 Jun 2023 07:47:47 +0000 (GMT) List-Id: https://gcc.gnu.org/g:38e88d41f50d844f1404172657ef7e8372014ef6 commit r14-1515-g38e88d41f50d844f1404172657ef7e8372014ef6 Author: Thomas Neumann Date: Wed May 10 12:33:49 2023 +0200 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, as 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: PR libgcc/109670 * unwind-dw2-fde.c: Fix radix sort buffer management. Diff: --- 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 32b9e64a1c8..d7c4a467754 100644 --- a/libgcc/unwind-dw2-fde.c +++ b/libgcc/unwind-dw2-fde.c @@ -634,8 +634,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; } @@ -670,9 +668,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