This is an archive of the discontinued LLVM Phabricator instance.

RegisterContextLLDB: Push CFA value on DWARF stack when evaluating register expressions
ClosedPublic

Authored by labath on Apr 23 2019, 7:15 AM.

Details

Summary

This behavior is specified in the Section 6.4.2.3 (Register Rule
instructions) of the DWARF4 spec. We were not doing that, which meant
that any register rule which was relying on the cfa value being there
was not evaluated correctly (it was aborted due to "out of bounds"
access).

I'm not sure how come this wasn't noticed before, but I guess this has
something to do with the fact that dwarf unwind expressions are not used
very often, and when they are, the situation is so complicated that the
CFA is of no use. I noticed this when I started emitting dwarf
expressions for the unwind information present in breakpad symbol files.

Event Timeline

labath created this revision.Apr 23 2019, 7:15 AM
clayborg added a comment.EditedApr 23 2019, 7:41 AM

Got errors trying to compile this .s file on mac:

$ ~/Documents/src/lldb/svn/lldb/llvm-build/Release+Asserts/x86_64/bin/clang foo.s -o foo.o
foo.s:3:9: error: unknown directive
        .type bar, @function
        ^
foo.s:11:9: error: unknown directive
        .size bar, .-bar
        ^
foo.s:13:9: error: unknown directive
        .type foo, @function
        ^
foo.s:25:9: error: unknown directive
        .size foo, .-foo
        ^
foo.s:27:9: error: unknown directive
        .type main, @function
        ^
foo.s:49:9: error: unknown directive
        .size main, .-main

Got errors trying to compile this .s file on mac:

$ ~/Documents/src/lldb/svn/lldb/llvm-build/Release+Asserts/x86_64/bin/clang foo.s -o foo.o
foo.s:3:9: error: unknown directive
        .type bar, @function
        ^
foo.s:11:9: error: unknown directive
        .size bar, .-bar
        ^
foo.s:13:9: error: unknown directive
        .type foo, @function
        ^
foo.s:25:9: error: unknown directive
        .size foo, .-foo
        ^
foo.s:27:9: error: unknown directive
        .type main, @function
        ^
foo.s:49:9: error: unknown directive
        .size main, .-main

Yeah, that test is linux-only (technically, other elf platforms may work too). I am not aware of any way to generate eh_frame entries with this kind of content except by hand-written assembly, and assembly is not really cross-platform.

If you just want to look at the resulting binary, you can add -target x86_64-pc-linux -c to the clang invocation, but that of course still won't run on a mac.

Actually, it seems it may be possible to tweak this asm so that it can run on a mac too (windows support unlikely). I'll try to post an updated version soon.

labath updated this revision to Diff 196253.Apr 23 2019, 8:14 AM

This is the version that should at least compile on a mac (it turns out asm is more portable than I expected). I am still building lldb to see if the test will pass.

Indeed the test passes on a mac with just a single linker warning saying it could not create compact unwind info because the %rip save address is weird, but that is not surprising.

labath added a comment.May 3 2019, 4:02 AM

Jason, could you take a quick look at this. I don't expect this to be too contentious...

clayborg accepted this revision.May 6 2019, 9:50 AM
This revision is now accepted and ready to land.May 6 2019, 9:50 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2019, 8:25 AM