]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
x86: Restore the frame pointer in word_mode
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 20 Apr 2020 12:51:29 +0000 (05:51 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 20 Apr 2020 12:58:25 +0000 (05:58 -0700)
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
gcc/config/i386/i386.c

index 4222eed2d9be9fc44594f2aa604e808e65ec5920..93bd849accace81ec5a4cb9a4e4c7ca3ed91bb0c 100644 (file)
@@ -1,3 +1,12 @@
+2020-04-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       Backport from master
+       2020-04-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+       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  <andrea.corallo@arm.com>
 
        Backport from mainline.
index 3891d44ce8563a19e5d504933410a76dd625f303..efe32f3975e923eef2e2013cc995556fe66d485e 100644 (file)
@@ -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;