public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Neumann <tneumann@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-7411] fix radix sort on 32bit platforms [PR109670]
Date: Sat,  3 Jun 2023 07:57:08 +0000 (GMT)	[thread overview]
Message-ID: <20230603075709.0088B3858284@sourceware.org> (raw)

https://gcc.gnu.org/g:7b21a74b41b30cd070f69523edf9583d1e287249

commit r13-7411-g7b21a74b41b30cd070f69523edf9583d1e287249
Author: Thomas Neumann <tneumann@users.sourceforge.net>
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

                 reply	other threads:[~2023-06-03  7:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230603075709.0088B3858284@sourceware.org \
    --to=tneumann@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).