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)
commit7edd010739a9f7951444e6c7151547a12af319f4
tree9b1dad95d695877b4a55e72e174987781227bcc1
parentec435357665e2991f30e1b65d9d3e95700aa5365
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240176 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Object/ELFObjectFile.h
include/llvm/Object/RelocVisitor.h
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp
test/Object/Inputs/invalid-bad-rel-type.elf [new file with mode: 0644]
test/Object/invalid.test [new file with mode: 0644]