From 47ea8616d4f5fee875e0849e393575e00def5894 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 20 Apr 2020 05:51:29 -0700 Subject: [PATCH] x86: Restore the frame pointer in word_mode We must restore the frame pointer in word_mode for eh_return epilogues since the upper 32 bits of RBP register can have any values. Tested on Linux/x32 and Linux/x86-64. Backport from master PR target/94556 * config/i386/i386.c (ix86_expand_epilogue): Restore the frame pointer in word_mode for eh_return epilogues. (cherry picked from commit efc1f3577f38bb213b313661c025ac965baee953) --- gcc/ChangeLog | 9 +++++++++ gcc/config/i386/i386.c | 11 ++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4222eed2d9be..93bd849accac 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2020-04-20 H.J. Lu + + Backport from master + 2020-04-13 H.J. Lu + + PR target/94556 + * config/i386/i386.c (ix86_expand_epilogue): Restore the frame + pointer in word_mode for eh_return epilogues. + 2020-04-20 Andrea Corallo Backport from mainline. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 3891d44ce856..efe32f3975e9 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -14352,8 +14352,13 @@ ix86_expand_epilogue (int style) t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD); emit_insn (gen_rtx_SET (sa, t)); - t = gen_frame_mem (Pmode, hard_frame_pointer_rtx); - insn = emit_move_insn (hard_frame_pointer_rtx, t); + /* NB: eh_return epilogues must restore the frame pointer + in word_mode since the upper 32 bits of RBP register + can have any values. */ + t = gen_frame_mem (word_mode, hard_frame_pointer_rtx); + rtx frame_reg = gen_rtx_REG (word_mode, + HARD_FRAME_POINTER_REGNUM); + insn = emit_move_insn (frame_reg, t); /* Note that we use SA as a temporary CFA, as the return address is at the proper place relative to it. We @@ -14368,7 +14373,7 @@ ix86_expand_epilogue (int style) add_reg_note (insn, REG_CFA_DEF_CFA, plus_constant (Pmode, sa, UNITS_PER_WORD)); ix86_add_queued_cfa_restore_notes (insn); - add_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx); + add_reg_note (insn, REG_CFA_RESTORE, frame_reg); RTX_FRAME_RELATED_P (insn) = 1; m->fs.cfa_reg = sa; -- 2.47.3