i386: Fix ICE with -mforce-indirect-call and -fsplit-stack [PR89316]
commit2f3f8952ff1736dd6a087ddb4106077db3502bb9
authorUros Bizjak <ubizjak@gmail.com>
Thu, 23 Nov 2023 14:45:59 +0000 (23 15:45 +0100)
committerUros Bizjak <ubizjak@gmail.com>
Thu, 23 Nov 2023 15:08:50 +0000 (23 16:08 +0100)
tree0ea84ceedbcefe1b0dfa7b73fc51c8b64030b327
parent8674d70ce37ca3249a641fb418c6849d4f95f348
i386: Fix ICE with -mforce-indirect-call and -fsplit-stack [PR89316]

With the above two options, use a temporary register regno (as returned
from split_stack_prologue_scratch_regno) as an indirect call scratch
register to hold __morestack function address.  On 64-bit targets, two
temporary registers are always available, so load the function addres in
%r11 and call __morestack_large_model with its one-argument-register value
rn %r10.  On 32-bit targets, bail out with a "sorry" if the temporary
register can not be obtained.

On 32-bit targets, also emit PIC sequence that re-uses the obtained indirect
call scratch register before moving the function address to it.  We can
not set up %ebx PIC register in this case, but __morestack is prepared
for this situation and sets it up by itself.

PR target/89316

gcc/ChangeLog:

* config/i386/i386.cc (ix86_expand_split_stack_prologue): Obtain
scratch regno when flag_force_indirect_call is set.  On 64-bit
targets, call __morestack_large_model when  flag_force_indirect_call
is set and on 32-bit targets with -fpic, manually expand PIC sequence
to call __morestack.  Move the function address to an indirect
call scratch register.

gcc/testsuite/ChangeLog:

* g++.target/i386/pr89316.C: New test.
* gcc.target/i386/pr112605-1.c: New test.
* gcc.target/i386/pr112605-2.c: New test.
* gcc.target/i386/pr112605.c: New test.
gcc/config/i386/i386.cc
gcc/testsuite/g++.target/i386/pr89316.C [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr112605-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr112605-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr112605.c [new file with mode: 0644]