llvm-project/llvm/lib/Object
Kevin Enderby feb63b9391 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
..
Archive.cpp Make the Error class constructor protected 2016-11-11 04:28:40 +00:00
ArchiveWriter.cpp Move llvm_unreachable out of switch. 2017-02-22 19:42:14 +00:00
Binary.cpp [WebAssembly] Add llvm-objdump support for wasm file format 2016-11-30 16:49:11 +00:00
CMakeLists.txt [lib/Object] - Introduce Decompressor class. 2017-01-11 15:26:41 +00:00
COFFObjectFile.cpp Object: Make SymbolicFile::symbol_{begin,end}() virtual and remove unnecessary wrappers. 2016-11-22 03:38:40 +00:00
Decompressor.cpp Recommit r292214 "[Support/Compression] - Change zlib API to return Error instead of custom status" 2017-01-17 15:45:07 +00:00
ELF.cpp [RISCV] Add RISC-V ELF defines 2016-11-01 16:59:37 +00:00
ELFObjectFile.cpp [ARM] Create SubtargetFeatures from build attrs 2017-01-18 15:52:11 +00:00
Error.cpp Make the Error class constructor protected 2016-11-11 04:28:40 +00:00
IRObjectFile.cpp [ThinLTO] Import composite types as declarations 2016-12-16 21:25:01 +00:00
LLVMBuild.txt
MachOObjectFile.cpp Actually add error handling to unpacking the dyld compact bind and 2017-02-28 21:47:07 +00:00
MachOUniversal.cpp Fix a bugs with using some Mach-O command line flags like "-arch armv7m". 2016-12-16 22:54:02 +00:00
ModuleSummaryIndexObjectFile.cpp [ThinLTO] Optionally ignore empty index file 2017-01-06 23:37:17 +00:00
ModuleSymbolTable.cpp Object: Set SF_Indirect in ModuleSymbolTable. 2016-12-01 07:00:35 +00:00
Object.cpp Thread Expected<...> up from libObject’s getSymbolAddress() for symbols to allow 2016-06-24 18:24:42 +00:00
ObjectFile.cpp [WebAssembly] Add llvm-objdump support for wasm file format 2016-11-30 16:49:11 +00:00
RecordStreamer.cpp Move some error handling down to MCStreamer. 2017-02-10 15:13:12 +00:00
RecordStreamer.h Move some error handling down to MCStreamer. 2017-02-10 15:13:12 +00:00
SymbolSize.cpp Fix llvm-symbolizer to correctly sort a symbol array and calculate symbol sizes 2016-11-15 21:07:03 +00:00
SymbolicFile.cpp [WebAssembly] Add llvm-objdump support for wasm file format 2016-11-30 16:49:11 +00:00
WasmObjectFile.cpp [MC] Fix some Clang-tidy modernize and Include What You Use warnings in SubtargetFeature; other minor fixes (NFC). 2017-02-09 01:09:54 +00:00