Page MenuHomePhabricator

ELF: Rename error -> fatal and redefine error as a non-noreturn function.
ClosedPublic

Authored by ruiu on Jan 27 2016, 11:12 AM.

Details

Reviewers
rafael
Summary

In many situations, we don't want to exit at the first error even in the
process model. For example, it is better to report all undefined symbols
rather than reporting the first one that the linker picked up randomly.

In order to handle such errors, we don't need to wrap everything with
ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we
can set a flag to record the fact that we found an error and keep it
going until it reaches a reasonable checkpoint.

This idea should be applicable to other places. For example, we can
ignore broken relocations and check for errors after visiting all relocs.

In this patch, I rename error to fatal, and introduce another version of
error which do not call exit. That function instead set HasError to true.
Once HasError becomes true, it stays true, so that we know that there
was an error if it is true.

I think introducing a non-noreturn error reporting function is by itself
a good idea, and it looks to me that this also provides a gradual path
towards lld-as-a-library (or at least embed-lld-to-your-program) without
sacrificing code readability with lots of ErrorOr's.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 46158.Jan 27 2016, 11:12 AM
ruiu retitled this revision from to ELF: Rename error -> fatal and redefine error as a non-noreturn function..
ruiu updated this object.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
ruiu updated this revision to Diff 46159.Jan 27 2016, 11:15 AM
  • Remove an unrelated file.

Eventually I think it'll probably be good/necessary to have a "linking
context" (for things like "HasError", and more likely a blob of diagnostic
info and/or a callback for reporting diagnostics) rather than global (or
even TLS) variables. But for sure this seems like one of many good
incremental steps, many of them orthogonal (indeed a global context could
be introduced in parallel with this patch for other reasons, etc, then the
flag moved over later)

Great to see small/incremental pieces like this when tackling such a large
problem!

  • Dave
ruiu updated this revision to Diff 46164.Jan 27 2016, 12:00 PM
  • Don't do s/error/fatal/ in comments.
emaste added a subscriber: emaste.Jan 27 2016, 12:02 PM
silvas added a subscriber: silvas.Jan 27 2016, 8:13 PM

Just wanted to echo dblaikie's comment that this is a great incremental step! (and all your other patches in this vein too)

rafael accepted this revision.Jan 28 2016, 9:17 AM
rafael edited edge metadata.

LGTM with nits.

ELF/Driver.h
24

Document the bool (is true error or success?).

ELF/Error.h
18

This is our first thread_local. There is not much point in having it until we make a push to support multiple uses from concurrent threads, so I would leave this out for now.

This revision is now accepted and ready to land.Jan 28 2016, 9:17 AM
ruiu closed this revision.Jan 28 2016, 10:44 AM
ruiu marked 2 inline comments as done.