summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-07-03 18:19:00 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-07-03 18:19:00 +0000
commited067c45d4b668db740fbb1728200fc51f4b9b51 (patch)
treecc50ae3d78954ad1e634cbd4278eec6095a50bdb /llvm/include
parente2df87f24b0af7fa80789e8da15c9cef9e6996f7 (diff)
downloadbcm5719-llvm-ed067c45d4b668db740fbb1728200fc51f4b9b51.tar.gz
bcm5719-llvm-ed067c45d4b668db740fbb1728200fc51f4b9b51.zip
Return ErrorOr from getSymbolAddress.
It can fail trying to get the section on ELF and COFF. This makes sure the error is handled. llvm-svn: 241366
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/Object/COFF.h3
-rw-r--r--llvm/include/llvm/Object/ELFObjectFile.h13
-rw-r--r--llvm/include/llvm/Object/MachO.h3
-rw-r--r--llvm/include/llvm/Object/ObjectFile.h9
4 files changed, 12 insertions, 16 deletions
diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index fc605826a8b..89f4d1c1ae4 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -648,8 +648,7 @@ public:
protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
- std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const override;
+ ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 5b9b113a2f0..05698fc6675 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -196,8 +196,7 @@ protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
- std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const override;
+ ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
@@ -400,15 +399,15 @@ uint64_t ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb) const {
}
template <class ELFT>
-std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
- uint64_t &Result) const {
- Result = getSymbolValue(Symb);
+ErrorOr<uint64_t>
+ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb) const {
+ uint64_t Result = getSymbolValue(Symb);
const Elf_Sym *ESym = getSymbol(Symb);
switch (ESym->st_shndx) {
case ELF::SHN_COMMON:
case ELF::SHN_UNDEF:
case ELF::SHN_ABS:
- return std::error_code();
+ return Result;
}
const Elf_Ehdr *Header = EF.getHeader();
@@ -422,7 +421,7 @@ std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
Result += Section->sh_addr;
}
- return std::error_code();
+ return Result;
}
template <class ELFT>
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index f4edfd05730..7ec5f0756e9 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -205,8 +205,7 @@ public:
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
unsigned getSectionType(SectionRef Sec) const;
- std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const override;
+ ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
diff --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h
index 62eab1066be..ee67d857189 100644
--- a/llvm/include/llvm/Object/ObjectFile.h
+++ b/llvm/include/llvm/Object/ObjectFile.h
@@ -135,7 +135,7 @@ public:
ErrorOr<StringRef> getName() const;
/// Returns the symbol virtual address (i.e. address at which it will be
/// mapped).
- std::error_code getAddress(uint64_t &Result) const;
+ ErrorOr<uint64_t> getAddress() const;
/// Return the value of the symbol depending on the object this can be an
/// offset or a virtual address.
@@ -198,8 +198,7 @@ protected:
virtual ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
std::error_code printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const override;
- virtual std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const = 0;
+ virtual ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
virtual uint64_t getSymbolValue(DataRefImpl Symb) const = 0;
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
@@ -308,8 +307,8 @@ inline ErrorOr<StringRef> SymbolRef::getName() const {
return getObject()->getSymbolName(getRawDataRefImpl());
}
-inline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
- return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
+inline ErrorOr<uint64_t> SymbolRef::getAddress() const {
+ return getObject()->getSymbolAddress(getRawDataRefImpl());
}
inline uint64_t SymbolRef::getValue() const {
OpenPOWER on IntegriCloud