This is an archive of the discontinued LLVM Phabricator instance.

[llvm-dsymutil] Add support for __swift_ast MachO DWARF section
ClosedPublic

Authored by fjricci on Oct 3 2017, 7:14 AM.

Details

Summary

Xcode's dsymutil emits a __swift_ast DWARF section, which is required for debugging,
and which contains a byte-for-byte dump of the swiftmodule file.
Add this feature to llvm-dsymutil.

Tested with gobjdump --dwarf=info -s, by verifying that the contents of
__DWARF.__swift_ast match between Xcode's dsymutil and llvm-dsymutil
(Xcode's dwarfdump and llvm-dwarfdump don't currently recognize the
__swift_ast section).

Diff Detail

Repository
rL LLVM

Event Timeline

fjricci created this revision.Oct 3 2017, 7:14 AM

This LGTM. We should probably also have a test for this. Committing a swift binary upstream might not be the best idea but I don't see an alternative.

tools/dsymutil/DwarfLinker.cpp
716 ↗(On Diff #117521)

I think you can also simplify this to MS->SwitchSection

718 ↗(On Diff #117521)

And MS->EmitBytes

aprantl edited edge metadata.Oct 3 2017, 12:42 PM

Perhaps it's possible to do assembler or LLVM IR instead of a binary?

Presumably, at least the swiftmodule would need to be pre-generated, since it's swift AST

That's true, though for testing dsymutil, we could just have a bogus section with some recognizable string in it, since all it does is copy the section data.

I have a test case working with an IR file, but it looks like most of the existing dsymutil tests just use an object file - should I do that here as well? (I don't think we get much value from using an IR file over an object file)

Looks like they check in binaries as well. I'll upload a version with a binary for now, and I can swap it out if we decide we want to.

fjricci updated this revision to Diff 117728.Oct 4 2017, 1:20 PM

Asm->OutStreamer -> MS

aprantl added inline comments.Oct 4 2017, 1:29 PM
lib/MC/MCObjectFileInfo.cpp
217 ↗(On Diff #117728)

this comment doesn't really add anything. I would either explain what that section is or remove it.

tools/dsymutil/DwarfLinker.cpp
3491 ↗(On Diff #117728)

. at the end, llvm coding guides always want full setences.

fjricci updated this revision to Diff 117731.Oct 4 2017, 1:32 PM

Clean up comments

fjricci updated this revision to Diff 117733.Oct 4 2017, 1:44 PM

Fix -no-output mode

JDevlieghere added inline comments.Oct 4 2017, 1:54 PM
test/tools/dsymutil/swift-ast.test
1 ↗(On Diff #117733)

Why is this necessary?

2 ↗(On Diff #117733)

You can use %T for a temporary directory unique to your test.

9 ↗(On Diff #117733)

For consistency with the other tests, please include the actual compile command. (i.e. Compile with:)

tools/dsymutil/DwarfLinker.cpp
716 ↗(On Diff #117728)

The swift AST section must be 32-bit aligned. Our internal code has Section->setAlignment(1 << 5);. though I think the operand is in bytes (rather than bits). Maybe I'm wrong or maybe this is because LLDB has stricter requirements. Either way we'd want to do the same here.

717 ↗(On Diff #117728)

No {} around single line if/for.

fjricci updated this revision to Diff 117817.Oct 5 2017, 7:35 AM

Address comments

JDevlieghere accepted this revision.Oct 5 2017, 10:05 AM

Thanks Francis, LGTM!

This revision is now accepted and ready to land.Oct 5 2017, 10:05 AM
This revision was automatically updated to reflect the committed changes.
fjricci reopened this revision.Oct 5 2017, 12:52 PM

The test fails on non apple-x86_64 builders, reverted the patch for now

This revision is now accepted and ready to land.Oct 5 2017, 12:52 PM

I think that postfixing the binary name with ".macho.x86_64" will work, that seems to be what the other tests do, although I can't seem to find a lit config relating to that.

This revision was automatically updated to reflect the committed changes.
fjricci reopened this revision.Oct 5 2017, 4:16 PM

Weirdly, appending .macho.x86_64 fixed the armv7/thumbv7 buildbots, but not aarch64. Will try to diagnose.

This revision is now accepted and ready to land.Oct 5 2017, 4:16 PM

They fail with:
while processing dwarf streamer init
error: : error: unable to get target for 'x86_64-apple-darwin', see --version and --triple.

Moving your test to the X86 subfolder will solve this. They are automatically disabled (see lit.local.cfg) when there's no X86 backend, which is what's causing some bots to fail.

This revision was automatically updated to reflect the committed changes.