diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-05 01:33:53 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-05 01:33:53 +0000 |
commit | 806f00649090e81ed478441e3edcddaef1176ee0 (patch) | |
tree | d568409a0c21e6b767feb6bdb9a1b27705505c71 /llvm/lib/Object | |
parent | e6c0144208a4352c7c50616508081278c2ee5f88 (diff) | |
download | bcm5719-llvm-806f00649090e81ed478441e3edcddaef1176ee0.tar.gz bcm5719-llvm-806f00649090e81ed478441e3edcddaef1176ee0.zip |
Handle relocations that don't point to symbols.
In ELF (as in MachO), not all relocations point to symbols. Represent this
properly by using a symbol_iterator instead of a SymbolRef. Update llvm-readobj
ELF's dumper to handle relocatios without symbols.
llvm-svn: 183284
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/Object/Object.cpp | 5 |
3 files changed, 8 insertions, 16 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index f5b49ab0618..bc5958d3c47 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -712,13 +712,11 @@ error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel, Res = toRel(Rel)->VirtualAddress; return object_error::success; } -error_code COFFObjectFile::getRelocationSymbol(DataRefImpl Rel, - SymbolRef &Res) const { +symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { const coff_relocation* R = toRel(Rel); DataRefImpl Symb; Symb.p = reinterpret_cast<uintptr_t>(SymbolTable + R->SymbolTableIndex); - Res = SymbolRef(Symb, this); - return object_error::success; + return symbol_iterator(SymbolRef(Symb, this)); } error_code COFFObjectFile::getRelocationType(DataRefImpl Rel, uint64_t &Res) const { diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 654af081f9e..bd5ea57c1f5 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -869,15 +869,13 @@ error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel, return object_error::success; } -error_code -MachOObjectFile::getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const { +symbol_iterator +MachOObjectFile::getRelocationSymbol(DataRefImpl Rel) const { macho::RelocationEntry RE = getRelocation(Rel); uint32_t SymbolIdx = getPlainRelocationSymbolNum(RE); bool isExtern = getPlainRelocationExternal(RE); - if (!isExtern) { - Res = *end_symbols(); - return object_error::success; - } + if (!isExtern) + return end_symbols(); macho::SymtabLoadCommand S = getSymtabLoadCommand(); unsigned SymbolTableEntrySize = is64Bit() ? @@ -886,8 +884,7 @@ MachOObjectFile::getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const { uint64_t Offset = S.SymbolTableOffset + SymbolIdx * SymbolTableEntrySize; DataRefImpl Sym; Sym.p = reinterpret_cast<uintptr_t>(getPtr(this, Offset)); - Res = SymbolRef(Sym, this); - return object_error::success; + return symbol_iterator(SymbolRef(Sym, this)); } error_code MachOObjectFile::getRelocationType(DataRefImpl Rel, diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp index 3e2c78ec47c..6941708dd34 100644 --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -219,10 +219,7 @@ uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) { } LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) { - SymbolRef ret; - if (error_code ec = (*unwrap(RI))->getSymbol(ret)) - report_fatal_error(ec.message()); - + symbol_iterator ret = (*unwrap(RI))->getSymbol(); return wrap(new symbol_iterator(ret)); } |