* [PATCH] libgcc: Fix a broken call/return address prediction
@ 2022-01-06 18:05 Zhiyao Ma
0 siblings, 0 replies; only message in thread
From: Zhiyao Ma @ 2022-01-06 18:05 UTC (permalink / raw)
To: gcc-patches
This patch fixed a broken call/return address prediction in
segmented stack implementation on x86_64 by leveraging the
red-zone under the stack pointer.
2022-01-06 Zhiyao Ma <zhiyao.ma@yale.edu>
libgcc/ChangeLog:
* config/i386/morestack.S: Modified instructions.
---
libgcc/config/i386/morestack.S | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/libgcc/config/i386/morestack.S b/libgcc/config/i386/morestack.S
index f1cf32dec9f..61c91ce4a35 100644
--- a/libgcc/config/i386/morestack.S
+++ b/libgcc/config/i386/morestack.S
@@ -213,14 +213,19 @@ __morestack_non_split:
cmpl $0x185d8d4c,(%rax)
je 2f
- # This breaks call/return prediction, as described above.
- incq 8(%rsp) # Increment the return address.
+ movq %rax,-8(%rsp) # Save the incremented return
+ # address to the red-zone below
+ # the stack pointer. It is
+ # guaranteed not to be corrupted.
popq %rax # Restore register.
.cfi_adjust_cfa_offset -8 # Adjust for popped register.
- ret # Return to caller.
+ callq *-16(%rsp) # Call into the caller's
+ # function body.
+
+ ret # Return to caller's prologue.
2:
popq %rax # Restore register.
--
2.25.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-01-06 18:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 18:05 [PATCH] libgcc: Fix a broken call/return address prediction Zhiyao Ma
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).