This is an archive of the discontinued LLVM Phabricator instance.

[MachO] Add UnknownValueErrors and ability to ignore them.
Needs ReviewPublic

Authored by beanz on Nov 28 2016, 6:06 PM.

Details

Reviewers
enderby
lhames
Summary

This patch is a first step toward using the llvm::Error mechanism to surface non-fatal errors in object file handling. This patch adds a new error for unrecognized load command IDs, as an UnknownValueError.

It also adds the ability to ignore UnknownValueErrors since an object file with unknown values may still be structurally valid. This is particularly important for tools that need to operate correctly on binary files produced with newer compilers than the tool itself came from. For example, running an old LLDB on a binary compiled with a newer Clang would need to be able to ignore unknown load commands because we might have added new commands.

We will want to take this one step further by surfacing the object and errors through an "ErrorAnd" construct and allowing the recipient to determine how to handle each error. Since this patch is sufficiently large as-is, and feeding that through all the libObject common APIs is also a large change I'd like to do that in a separate patch.

Doing the larger cleanup will remove the "IgnoreValueErrors" parameter from the common APIs, but will require touching ELF and COFF as well as MachO.

Event Timeline

beanz updated this revision to Diff 79490.Nov 28 2016, 6:06 PM
beanz retitled this revision from to [MachO] Add UnknownValueErrors and ability to ignore them..
beanz updated this object.
beanz added reviewers: lhames, enderby.
beanz added a subscriber: llvm-commits.
enderby added inline comments.Nov 28 2016, 6:38 PM
lib/Object/MachOObjectFile.cpp
1465–1466

Seems like this bit of added logic will cause the loop over load commands to continue past all errors (even if the errors were not value errors) if IgnoreValueErrs is set and will not stop on the first error. If that what you intended? If so I'm not sure this code was written to be robust enough to handle this and not crash. And I doubt there are single file cases with multiple errors that are tested. Maybe you only wanted multiple value errors and not all multiple types of errors?

beanz updated this revision to Diff 79510.Nov 28 2016, 10:22 PM

Kevin pointed out in his feedback some problems with the aproach I was taking in the Mach-O code. As I thought through it more, my aproach was really not the right way to go.

This patch simplifies the Mach-O code by keeping the malformedErrors and unknownValue errors separately, then joining them after the constructor exits. This approach minimizes the invasiveness of building error lists, and eliminates the unintended behavioral differences that my initial patch introduced.

Thanks for the feedback Kevin!

enderby edited edge metadata.Nov 29 2016, 10:53 AM

Do you plan to add any test cases at this time where IgnoreValueErrs is true? Or is that to be left to be done later in a future step?

beanz added a comment.Nov 29 2016, 1:09 PM

There is actually already a test case that tests IgnoreValueErrs=true. That is covered in the (poorly named) obj2yaml test bogus_load_command.yaml.