This is an archive of the discontinued LLVM Phabricator instance.

[libunwind] Fix ARM EHABI unwinding instruction calculation
AbandonedPublic

Authored by smeenai on Apr 17 2020, 4:44 PM.

Details

Reviewers
compnerd
danalbert
rprichard
srhines
Group Reviewers
Restricted Project
Summary

Section 9.3 of the ARM EHABI [1] states that the 01xxxxxx instruction
should be interpreted as follows:

vsp = vsp - (xxxxxx << 2) - 4

However, libunwind is adding 4 instead of subtracting 4. libgcc's
unwinder follows the spec here, so I'm inclined to believe this is a bug
in libunwind. (Perhaps the intent was to have parentheses around the
expression, such that it was a - (b + 4) instead of a - b + 4, but
it's hard to say at this point.) Interestingly, this appears to go all
the way back to the initial commit of ARM EHABI unwinding, back in June
2014: https://github.com/llvm/llvm-project/commit/97080e0c5eb4.

[1] https://developer.arm.com/docs/ihi0038/c/exception-handling-abi-for-the-arm-architecture-abi-2018q4-documentation#ehabi32-section9-3

Diff Detail

Event Timeline

smeenai created this revision.Apr 17 2020, 4:44 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 17 2020, 4:44 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

I think libunwind is already correct. It's doing:

vsp -= (xxxxxx << 2) + 4

The addition has higher precedence than the compound assignment, so it's equivalent to:

vsp = vsp - ((xxxxxx << 2) + 4)

i.e.

vsp = vsp - (xxxxxx << 2) - 4
smeenai abandoned this revision.EditedApr 17 2020, 5:26 PM

Ah, you're right. I mis-parsed that. Whoops.