This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Fix operands of `Int_eh_sjlj_longjmp`
Needs ReviewPublic

Authored by xtkoba on Sep 1 2021, 9:28 PM.

Details

Reviewers
efriedma
Summary

On Linux, it was made possible by https://reviews.llvm.org/D38253 that __builtin_longjmp can jump between ARM mode and Thumb mode. This was done by restoring the saved frame address to each of r7 and r11, the frame pointer register on Linux in Thumb mode and ARM mode, respectively.

However, there has been revealed a case that __builtin_longjmp from ARM mode does not work. In that case, __builtin_longjmp chooses r7 for the scratch register, trying to branch to the address contained in it, which has already been overwritten by the saved frame address.

This seems to be not easily worked around on user's side. For example, the compiler option -fno-omit-frame-pointer will not prevent r7 from being used as the scratch register, because it is not the frame pointer register in ARM mode.

In the proposed change, Int_eh_sjlj_longjmp is made to use the new register class GPRnofp which excludes the potential frame pointer registers r7 and r11.

Diff Detail

Event Timeline

xtkoba created this revision.Sep 1 2021, 9:28 PM
xtkoba requested review of this revision.Sep 1 2021, 9:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2021, 9:28 PM
mstorsjo added a subscriber: mstorsjo.
xtkoba updated this revision to Diff 370715.Sep 4 2021, 2:00 AM

Diff context extended

xtkoba updated this revision to Diff 370724.Sep 4 2021, 3:14 AM

Test revised

xtkoba updated this revision to Diff 370730.Sep 4 2021, 4:44 AM

Test revised^2

@efriedma Can you have a look at this?

The general approach here seems fine.

llvm/lib/Target/ARM/ARMInstrInfo.td
5910

I think this addresses the FIXME. Add a comment noting that we're intentionally not defining separate versions of this instruction based on the frame pointer register.

llvm/lib/Target/ARM/ARMRegisterInfo.td
258

Maybe (sub GPR, R7, R11, PC)? Probably doesn't have any practical effect, but just in case.

llvm/test/CodeGen/Thumb/high-reg-clobber.mir
47

Please fix the number "1048585" to actually refer to the intended register class: hGPR.