This is an archive of the discontinued LLVM Phabricator instance.

Correctly decode `UOP_Epilog` opcodes in `llvm-objdump`
ClosedPublic

Authored by Swatinem on Aug 6 2021, 8:57 AM.

Details

Summary

At least ntdll is using the undocumented version 2 unwind info, and opcode 6, which is already defined as UOP_Epilog.
Using llvm-objdump --unwind with ntdll would previously result in unreachable assertions because this code was missing from getNumUsedSlots and getUnwindCodeTypeName.
The slots of these codes comes from https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/coreclr/inc/win64unwind.h#L51-L52 which I would assume is a good authoritative source.

Diff Detail

Event Timeline

Swatinem created this revision.Aug 6 2021, 8:57 AM
Swatinem requested review of this revision.Aug 6 2021, 8:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2021, 8:57 AM

This needs a test. Under /tools/llvm-objdump/COFF, you may use obj2yaml Inputs/win64-unwind.exe.coff-x86_64.exe to convert the precanned binary test file to a yaml test file.
Edit the accompanying .asm file to add new unwind code, and then test it.

Please bear with me a bit, I’m completely new to llvm codebase and test infra.

I’m unsure how converting this to yaml would help me? On the other hand, the asm seems to be the source for the obj/exe fixtures. How would I go about regenerating those from the source?
Also, I’m not quite sure how to actually put an epilog code in there via asm. I found this snippet here: https://searchfox.org/mozilla-central/rev/d3683dbb252506400c71256ef3994cdbdfb71ada/toolkit/crashreporter/test/win64UnwindInfoTests.asm#346-363
But that seems to be a different asm flavor?

Can someone help me unblock this? To be honest, I have way too little experience with the llvm testing infrastructure. It would probably take me ages to figure out all on my own how to conjure up an appropriate COFF file out of thin air.

Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2022, 4:17 AM
Herald added a subscriber: StephenFan. · View Herald Transcript

@MaskRay, could you help with the testing here? Unfortunately, disassembly and COFF are both somewhat outside my realm of expertise, so I can't really help out myself.

MaskRay accepted this revision.Jul 28 2022, 2:36 PM

We have some test gap but that may be fine, as there are a few other unwind opcodes which are untested.
Still be good to add the coverage. You can run obj2yaml llvm/test/tools/llvm-objdump/COFF/Inputs/win64-unwind.exe.coff-x86_64.exe to get a YAML, clean it a bit, and create a # RUN: yaml2obj %s -o %t test.

llvm/tools/llvm-objdump/COFFDump.cpp
197

Add a space after :

This revision is now accepted and ready to land.Jul 28 2022, 2:36 PM
Swatinem updated this revision to Diff 448793.Jul 30 2022, 2:48 AM
Swatinem removed reviewers: Bigcheese, jhenderson.

Rebased the patch and fixed the formatting. I will try to create a testcase with obj2yaml next, lets see how successful that will be ;-)

Swatinem marked an inline comment as done.Sep 1 2022, 12:21 PM

@MaskRay I tried playing with obj2yaml, but it would would require me to mess with the raw byte stream of the unwind ops, which I think would be rather fragile.
So this is good to go from my end.

This revision was landed with ongoing or failed builds.Sep 1 2022, 2:05 PM
This revision was automatically updated to reflect the committed changes.