public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Kewen.Lin" <linkw@linux.ibm.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Segher Boessenkool <segher@kernel.crashing.org>,
	David Edelsohn <dje.gcc@gmail.com>, AlanM <amodra@gmail.com>,
	Peter Bergner <bergner@linux.ibm.com>
Subject: [PATCH] rs6000, libgcc: Fix bump size for powerpc64 elfv1 ABI [PR108727]
Date: Mon, 6 Mar 2023 17:27:09 +0800	[thread overview]
Message-ID: <be761ccd-2db7-1b80-a0bb-1d3499847bc7@linux.ibm.com> (raw)

Hi,

As PR108727 shows, when cleanup code called by the stack
unwinder calls function _Unwind_Resume, it goes via plt
stub like:

   function 00000000.plt_call._Unwind_Resume:

=> 0x0000000010003580 <+0>:     std     r2,40(r1)
   0x0000000010003584 <+4>:     ld      r12,-31760(r2)
   0x0000000010003588 <+8>:     mtctr   r12
   0x000000001000358c <+12>:    ld      r2,-31752(r2)
   0x0000000010003590 <+16>:    cmpldi  r2,0
   0x0000000010003594 <+20>:    bnectr+
   0x0000000010003598 <+24>:    b       0x100031a4
                                        <_Unwind_Resume@plt>

It wants to save TOC base (r2) to r1 + 40, but we only
bump the stack segment by 32 bytes as follows:

   stdu %r29,-32(%r3)

It means the access is out of the stack segment allocated
by __generic_morestack, once the touch area isn't writable
like this failure shows, it would cause segment fault.

So fix the bump size with one reasonable value PARAMS.

Bootstrapped and regtested on powerpc64-linux-gnu P{8,9} and
powerpc64le-linux-gnu P{8,9,10}.

Alan ack'ed this in that PR, I'm going to push this soon.

BR,
Kewen
-----
	PR libgcc/108727

libgcc/ChangeLog:

	* config/rs6000/morestack.S (__morestack): Use PARAMS for new stack
	bump size.
---
 libgcc/config/rs6000/morestack.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgcc/config/rs6000/morestack.S b/libgcc/config/rs6000/morestack.S
index 5e7ad133303..f2fea6abb10 100644
--- a/libgcc/config/rs6000/morestack.S
+++ b/libgcc/config/rs6000/morestack.S
@@ -205,12 +205,12 @@ ENTRY0(__morestack)
 	bl JUMP_TARGET(__generic_morestack)

 # Start using new stack
-	stdu %r29,-32(%r3)		# back-chain
+	stdu %r29,-PARAMS(%r3)		# back-chain
 	mr %r1,%r3

 # Set __private_ss stack guard for the new stack.
 	ld %r12,NEWSTACKSIZE_SAVE(%r29)	# modified size
-	addi %r3,%r3,BACKOFF-32
+	addi %r3,%r3,BACKOFF-PARAMS
 	sub %r3,%r3,%r12
 # Note that a signal frame has $pc pointing at the instruction
 # where the signal occurred.  For something like a timer
--
2.39.2

                 reply	other threads:[~2023-03-06  9:27 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=be761ccd-2db7-1b80-a0bb-1d3499847bc7@linux.ibm.com \
    --to=linkw@linux.ibm.com \
    --cc=amodra@gmail.com \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=segher@kernel.crashing.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).