This is an archive of the discontinued LLVM Phabricator instance.

[Assembler] Make fatal assembler errors non-fatal
ClosedPublic

Authored by olista01 on Nov 16 2015, 11:04 AM.

Details

Summary

Currently, if the assembler encounters an error after parsing (such as an out-of-range fixup), it reports this as a fatal error, and so stops after the first error. However, for most of these there is an obvious way to recover after emitting the error, such as emitting the fixup with a value of zero. This means that we can report on all of the errors in a file, not just the first one. MCContext::reportError records the fact that an error was encountered, so we won't actually emit an object file with the incorrect contents.

Diff Detail

Repository
rL LLVM

Event Timeline

olista01 updated this revision to Diff 40314.Nov 16 2015, 11:04 AM
olista01 retitled this revision from to [Assembler] Make fatal assembler errors non-fatal.
olista01 updated this object.
olista01 added a reviewer: rengolin.
olista01 set the repository for this revision to rL LLVM.
olista01 added a subscriber: llvm-commits.
t.p.northover accepted this revision.Nov 16 2015, 12:58 PM
t.p.northover added a reviewer: t.p.northover.
t.p.northover added a subscriber: t.p.northover.

Looks like a good idea to me! Writing multiple files worth of tests for diagnostics was a pain in the neck, and I expect the testing has suffered as a result.

Tim.

This revision is now accepted and ready to land.Nov 16 2015, 12:58 PM
This revision was automatically updated to reflect the committed changes.

This is totally reasonable.

Longer term, I'd love to see a more holistic plan for diagnostics in the assembler. Right now they're in broadly two categories "(mostly) syntax related problems we detect directly in the parser" and "everything else, thrown in wherever we would otherwise have crashed." The former case could use a bit of cleanup but is generally fine. The latter is completely haphazard, however.

I'd love to have a moral equivalent to a Sema pass or two that we could run over the collected state of things for the assembler. I'm (totally hand waving) thinking one right after parsing that just wants a more global view of the whole file so it can find things like unresolved forward references to local labels. Then one after layout which can find things like out of range fix-ups, "there's not legal relocations for this thing," et. al..

With something like that, the post-parser diagnostics all move into there. All the places we current do error checking in the AsmBackend and related can now assume good input, as they've had the input validated earlier, so the diagnostics there become assert() calls. The Sema passes get used by the assembler, but not the compiler (unless there's inline assembler, in which case we still need them). That way we split out the currently merged functionality of catching compiler backend bugs and catching user error in assembly files. By doing so, we get both a cleaner layering and a faster compiler backend as it will be able to do a bit less work.

llvm/trunk/test/MC/MachO/ARM/bad-darwin-ARM-reloc.s