This is an archive of the discontinued LLVM Phabricator instance.

[lld] [mach-o] implement minimal __unwind_info support
ClosedPublic

Authored by t.p.northover on Sep 9 2014, 4:47 AM.

Details

Reviewers
kledzik
shankarke
Summary

Hi,

I've finally had some time to work on generating __unwind_info sections. The attached patch is fairly limited, but seemed like a minimally useful implementation:

  • It's x86_64 only.
  • It will fail if more than 3 personality functions are used.
  • It will fail if there is a function without a __compact_unwind entry.
  • It only produces normal pages, rather than compressed.

I intend to fix those, and I think most of them should be fairly small additions in the current scheme, but I'd like to get any major design problems hammered out before I start.

So, any suggestions? Is it OK to commit?

Cheers.

Tim.

Diff Detail

Event Timeline

t.p.northover retitled this revision from to [lld] [mach-o] implement minimal __unwind_info support.
t.p.northover updated this object.
t.p.northover edited the test plan for this revision. (Show Details)
t.p.northover added a reviewer: kledzik.
t.p.northover added a subscriber: Unknown Object (MLST).
kledzik edited edge metadata.Sep 9 2014, 1:34 PM

A few nits, but over all a great start.

lib/ReaderWriter/MachO/CompactUnwindPass.cpp
101–103

This style (ulittle32_t) won't scale if we ever have a big endian architecture. That is why I use the style elsewhere of:

write32(headerEntries[0], _swap, 1);
230–235

These ivars need a leading underscore.

lib/ReaderWriter/MachO/CompactUnwindPass.hpp
1–31 ↗(On Diff #13450)

Why does this file exist?

lib/ReaderWriter/MachO/MachOLinkingContext.cpp
284–291

The should also be true for MH_DYLIB and MH_BUNDLE. It should also call archHandler. needsCompactUnwind().

lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
449

_imageBase should be initialized in the constructor from a new method MachOLinkingContext::baseAddress().

Then in assignAddressesToSections(), the FIXME for the initial value for "address" can be changed to be _imageBase.

test/mach-o/unwind-info-simple.yaml
1 ↗(On Diff #13450)

Should name this test case with x86_64 in the name, since will need similar test case for other arches

68–71 ↗(On Diff #13450)

You can add %p/Inputs/libSystem.yaml to the link line, then you don't need to define dyld_stub_binder

Hi Nick,

Thanks for the comments. The writeN one makes me sad, it's a fairly clunky interface, but they all seem sensible. I'll work on an updated patch.

Cheers.

Tim.

lib/ReaderWriter/MachO/CompactUnwindPass.cpp
230–235

That's a really dodgy convention, by the way. As soon as you want a member that starts with a capital (say from an acronym or proper name) you get undefined behaviour. There are already multiple instances of this in the lld source.

But it makes no sense to change it piecemeal, I meant to go back and do that actually, but forgot.

lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
449

Certainly, but I think that's a completely separate issue to __unwind_info (it's basically implementing "-image_base"). I'll do that today; I should be able to get a commit in before this one lands and make use of the infrastructure.

t.p.northover edited edge metadata.

I think this fixes everything Nick mentioned (including the ulittle32_t thing, we can sort out a better solution later if needed). How does it look now?

Cheers.

Tim.

shankarke accepted this revision.Sep 10 2014, 8:46 AM
shankarke added a reviewer: shankarke.
This revision is now accepted and ready to land.Sep 10 2014, 8:46 AM
ruiu added a subscriber: ruiu.Sep 10 2014, 10:08 AM

Could you run clang-format on the new code?

lib/ReaderWriter/MachO/CompactUnwindPass.cpp
10

Needs a brief description about what this file is for.

kledzik accepted this revision.Sep 11 2014, 10:50 AM
kledzik edited edge metadata.

LGTM

t.p.northover closed this revision.Sep 30 2014, 2:43 PM

Thanks for the reviews. I've committed it as r218703 and r218704 (I ran clang-format for the first one, but forgot the file-level comment).

I'll work on filling in the gaps now that the basic pass is in place.

Cheers.

Tim.