summaryrefslogtreecommitdiff
path: root/include/llvm/Object
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-06-05 01:33:53 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-06-05 01:33:53 +0000
commit6c1202c459ffa6d693ad92fa84e43902bc780bca (patch)
tree7b105f95ab50dfb164f274ae463085af780e3262 /include/llvm/Object
parentcc5a6cb0a22736e133a17cf4de23e3d76de8058e (diff)
downloadllvm-6c1202c459ffa6d693ad92fa84e43902bc780bca.tar.gz
llvm-6c1202c459ffa6d693ad92fa84e43902bc780bca.tar.bz2
llvm-6c1202c459ffa6d693ad92fa84e43902bc780bca.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Object')
-rw-r--r--include/llvm/Object/COFF.h3
-rw-r--r--include/llvm/Object/ELF.h15
-rw-r--r--include/llvm/Object/MachO.h2
-rw-r--r--include/llvm/Object/ObjectFile.h11
4 files changed, 15 insertions, 16 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index 1127263c99..c0efbbaab1 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -243,8 +243,7 @@ protected:
uint64_t &Res) const;
virtual error_code getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const;
- virtual error_code getRelocationSymbol(DataRefImpl Rel,
- SymbolRef &Res) const;
+ virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const;
virtual error_code getRelocationType(DataRefImpl Rel,
uint64_t &Res) const;
virtual error_code getRelocationTypeName(DataRefImpl Rel,
diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h
index 592dbae39e..a6c545ec9d 100644
--- a/include/llvm/Object/ELF.h
+++ b/include/llvm/Object/ELF.h
@@ -716,8 +716,7 @@ protected:
uint64_t &Res) const;
virtual error_code getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const;
- virtual error_code getRelocationSymbol(DataRefImpl Rel,
- SymbolRef &Res) const;
+ virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const;
virtual error_code getRelocationType(DataRefImpl Rel,
uint64_t &Res) const;
virtual error_code getRelocationTypeName(DataRefImpl Rel,
@@ -1503,9 +1502,9 @@ error_code ELFObjectFile<ELFT>::getRelocationNext(DataRefImpl Rel,
return object_error::success;
}
-template<class ELFT>
-error_code ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel,
- SymbolRef &Result) const {
+template <class ELFT>
+symbol_iterator
+ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const {
uint32_t symbolIdx;
const Elf_Shdr *sec = getRelSection(Rel);
switch (sec->sh_type) {
@@ -1520,6 +1519,9 @@ error_code ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel,
break;
}
}
+ if (!symbolIdx)
+ return end_symbols();
+
DataRefImpl SymbolData;
IndexMap_t::const_iterator it =
SymbolTableSectionsIndexMap.find(sec->sh_link);
@@ -1527,8 +1529,7 @@ error_code ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel,
report_fatal_error("Relocation symbol table not found!");
SymbolData.d.a = symbolIdx;
SymbolData.d.b = it->second;
- Result = SymbolRef(SymbolData, this);
- return object_error::success;
+ return symbol_iterator(SymbolRef(SymbolData, this));
}
template<class ELFT>
diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h
index bedf5c101e..f3ba8ef757 100644
--- a/include/llvm/Object/MachO.h
+++ b/include/llvm/Object/MachO.h
@@ -72,7 +72,7 @@ public:
RelocationRef &Res) const;
virtual error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const;
virtual error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const;
- virtual error_code getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const;
+ virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const;
virtual error_code getRelocationType(DataRefImpl Rel, uint64_t &Res) const;
virtual error_code getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const;
diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h
index ba1bb6945b..f434d63736 100644
--- a/include/llvm/Object/ObjectFile.h
+++ b/include/llvm/Object/ObjectFile.h
@@ -85,6 +85,7 @@ inline bool operator<(const DataRefImpl &a, const DataRefImpl &b) {
}
class SymbolRef;
+typedef content_iterator<SymbolRef> symbol_iterator;
/// RelocationRef - This is a value type class that represents a single
/// relocation in the list of relocations in the object file.
@@ -103,7 +104,7 @@ public:
error_code getAddress(uint64_t &Result) const;
error_code getOffset(uint64_t &Result) const;
- error_code getSymbol(SymbolRef &Result) const;
+ symbol_iterator getSymbol() const;
error_code getType(uint64_t &Result) const;
/// @brief Indicates whether this relocation should hidden when listing
@@ -236,7 +237,6 @@ public:
DataRefImpl getRawDataRefImpl() const;
};
-typedef content_iterator<SymbolRef> symbol_iterator;
/// LibraryRef - This is a value type class that represents a single library in
/// the list of libraries needed by a shared or dynamic object.
@@ -334,8 +334,7 @@ protected:
uint64_t &Res) const =0;
virtual error_code getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const =0;
- virtual error_code getRelocationSymbol(DataRefImpl Rel,
- SymbolRef &Res) const = 0;
+ virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
virtual error_code getRelocationType(DataRefImpl Rel,
uint64_t &Res) const = 0;
virtual error_code getRelocationTypeName(DataRefImpl Rel,
@@ -566,8 +565,8 @@ inline error_code RelocationRef::getOffset(uint64_t &Result) const {
return OwningObject->getRelocationOffset(RelocationPimpl, Result);
}
-inline error_code RelocationRef::getSymbol(SymbolRef &Result) const {
- return OwningObject->getRelocationSymbol(RelocationPimpl, Result);
+inline symbol_iterator RelocationRef::getSymbol() const {
+ return OwningObject->getRelocationSymbol(RelocationPimpl);
}
inline error_code RelocationRef::getType(uint64_t &Result) const {