Object: Fix Mach-O relocation printing.

There were two problems that made llvm-objdump -r crash:
- for non-scattered relocations, the symbol/section index is actually in the
  (aptly named) symbolnum field.
- sections are 1-indexed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181843 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ahmed Bougacha
2013-05-14 22:41:29 +00:00
parent 101a36117c
commit ebb9f17240
2 changed files with 38 additions and 2 deletions

View File

@ -339,7 +339,7 @@ static void printRelocationTargetName(const MachOObjectFile *O,
StringRef S;
bool isExtern = O->getPlainRelocationExternal(RE);
uint64_t Val = O->getAnyRelocationAddress(RE);
uint64_t Val = O->getPlainRelocationSymbolNum(RE);
if (isExtern) {
symbol_iterator SI = O->begin_symbols();
@ -347,7 +347,8 @@ static void printRelocationTargetName(const MachOObjectFile *O,
SI->getName(S);
} else {
section_iterator SI = O->begin_sections();
advanceTo(SI, Val);
// Adjust for the fact that sections are 1-indexed.
advanceTo(SI, Val - 1);
SI->getName(S);
}