llvm-mirror/tools/llvm-objdump
Kevin Enderby 96b6ebab4e Actually add error handling to unpacking the dyld compact bind and
other tables.  Providing a helpful error message to what the error is and
where the error occurred based on which opcode it was associated with.

There have been handful of bug fixes dealing with bad bind info in
object files, r294021 and r249845, which only put a band aid on the
problem after a bad bind table was created after unpacking from
its compact info.  In these cases a bind table should have never been
created and an error should have simply been generated.

This change puts in place the plumbing to allow checking and returning
of an error when the compact info is unpacked.  This follows the model
of iterators that can fail that Lang Hanes designed when fixing the problem
for bad archives r275316 (or r275361).

This change uses one of the existing test cases that now causes an
error instead of printing <<bad library ordinal>> after a bad bind table
is created.  The error uses the offset into the opcode table as shown with
the macOS dyldinfo(1) tool to indicate where the error is and which
opcode and which parameter is in error.

For example the exiting test case has this lazy binding opcode table:

% dyldinfo -opcodes test/tools/llvm-objdump/Inputs/bad-ordinal.macho-x86_64 
…
lazy binding opcodes:
0x0000 BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB(0x02, 0x00000010)
0x0002 BIND_OPCODE_SET_DYLIB_ORDINAL_IMM(2)

In the test case the binary only has one library so setting the library 
ordinal to the value of 2 in the BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
opcode at 0x0002 above is an error.  This now produces this error message:

% llvm-objdump -lazy-bind bad-ordinal.macho-x86_64 
…
llvm-objdump: 'bad-ordinal.macho-x86_64': truncated or malformed object (for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad library ordinal: 2 (max 1) for opcode at: 0x2)

This change provides the plumbing for the error handling and one example
of an error message.  Other error checks and test cases will be added in follow
on commits.

llvm-svn: 296527
2017-02-28 21:47:07 +00:00
..
CMakeLists.txt [WebAssembly] Add llvm-objdump support for wasm file format 2016-11-30 16:49:11 +00:00
COFFDump.cpp [llvm-objdump] Switch to a range loop. NFCI. 2016-09-30 23:22:42 +00:00
ELFDump.cpp [llvm-objdump] Dump PT_NOTE as part of -p. 2017-01-16 23:13:46 +00:00
llvm-objdump.cpp llvm-objdump: make NoLeadingAddr work on more than just MachO 2017-02-08 18:11:31 +00:00
llvm-objdump.h llvm-objdump: make NoLeadingAddr work on more than just MachO 2017-02-08 18:11:31 +00:00
LLVMBuild.txt Add an c++ itanium demangler to llvm. 2016-09-06 19:16:48 +00:00
MachODump.cpp Actually add error handling to unpacking the dyld compact bind and 2017-02-28 21:47:07 +00:00
WasmDump.cpp [WebAssembly] Add llvm-objdump support for wasm file format 2016-11-30 16:49:11 +00:00