This is an archive of the discontinued LLVM Phabricator instance.

libunwind: add conventional X86 register numbers for non-Darwin OSes
ClosedPublic

Authored by emaste on Jul 19 2016, 6:04 AM.

Details

Summary

For historical reasons Darwin/i386 has ebp and esp swapped in the eh_frame register numbering. That is:

         Darwin      Other
Reg #    eh_frame    eh_frame    DWARF
=====    ========    ========    =====
  4        ebp         esp        esp
  5        esp         ebp        ebp

Although the UNW_X86_* constants are not intended to be coupled with DWARF / eh_frame numbering they are currently conflated in libunwind, so add the numbering for non-Darwin operating systems.

Diff Detail

Repository
rL LLVM

Event Timeline

emaste updated this revision to Diff 64476.Jul 19 2016, 6:04 AM
emaste retitled this revision from to libunwind: add conventional X86 register numbers for non-Darwin OSes.
emaste updated this object.
emaste added reviewers: compnerd, kledzik.
emaste set the repository for this revision to rL LLVM.
emaste updated this object.
compnerd added inline comments.Aug 7 2016, 9:59 PM
include/libunwind.h
160 ↗(On Diff #64476)

GCC has this behaviour, its not specific to Apple. The .eh_frame should use the "swapped" values. We really should add a comment explaining that this is backwards for historical reasons and we cannot fix this due to this now being fossilized into the ABI :-(.

emaste added inline comments.Aug 30 2016, 6:23 AM
include/libunwind.h
160 ↗(On Diff #64476)

The existing case (EBP = 4, ESP = 5) does not work on FreeBSD.

compnerd requested changes to this revision.Aug 30 2016, 7:45 AM
compnerd edited edge metadata.
compnerd added inline comments.
include/libunwind.h
160 ↗(On Diff #64476)

Well, we could just special case FreeBSD then:

#if defined(__FreeBSD__)
UNW_X86_ESP = 4,
UNW_X86_EBP = 5,
#else
UNW_X86_EBP = 4,
UNW_X86_ESP = 5,
#endif
This revision now requires changes to proceed.Aug 30 2016, 7:45 AM

Well, we could just special case FreeBSD then:

Sure, I can do that for now. Are you aware of a canonical reference for the swapped registers though? I came across this issue when working on lldb as well, but could not find a definitive reference for the swapping.

emaste updated this revision to Diff 69683.Aug 30 2016, 7:59 AM
emaste edited edge metadata.
emaste removed rL LLVM as the repository for this revision.

provide special case for FreeBSD only

compnerd accepted this revision.Aug 30 2016, 8:01 AM
compnerd edited edge metadata.

Interesting. We can change the Linux behavior better after a better understanding of whats going on there. libunwind (GNU Savannah) indicates the behavior as currently specified, although you are showing proof that it behaves differently. However, I think that this would be sufficient for unblocking you.

This revision is now accepted and ready to land.Aug 30 2016, 8:01 AM
This revision was automatically updated to reflect the committed changes.