Improve error handling of getRelocationAddend.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 19 Jun 2015 20:58:43 +0000 (20:58 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 19 Jun 2015 20:58:43 +0000 (20:58 +0000)
commit3dc0d05bf455ef75cd309a46be668966d692f4b5
tree8dd6f3c5d0b23b4f4745e4155751240d3fd5e3a3
parent90b05b52fa52c78aa10ef97359e859f3c2242734
Improve error handling of getRelocationAddend.

This patch changes getRelocationAddend to use ErrorOr and considers it an error
to try to get the addend of a REL section.

If, for example, a x86_64 file has a REL section, that file is corrupted and
we should reject it.

Using ErrorOr is not ideal since we check the section type once per relocation
instead of once per section.

Checking once per section would involve getRelocationAddend just asserting and
callers checking the section before iterating over the relocations.

In any case, this is an improvement and includes a test.

llvm-svn: 240176
llvm/include/llvm/Object/ELFObjectFile.h
llvm/include/llvm/Object/RelocVisitor.h
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
llvm/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp
llvm/test/Object/Inputs/invalid-bad-rel-type.elf [new file with mode: 0644]
llvm/test/Object/invalid.test [new file with mode: 0644]