summaryrefslogtreecommitdiff
path: root/include/llvm
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-04-03 03:13:33 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-04-03 03:13:33 +0000
commit051c948bbe3f64a7c450120963b28a5959382cb8 (patch)
tree255817868a1b2f2ab59f0901b2f0c859e690f02a /include/llvm
parent35395192231722cdf66b6914f27f465cc0358c68 (diff)
downloadllvm-051c948bbe3f64a7c450120963b28a5959382cb8.tar.gz
llvm-051c948bbe3f64a7c450120963b28a5959382cb8.tar.bz2
llvm-051c948bbe3f64a7c450120963b28a5959382cb8.tar.xz
Implement get getSymbolFileOffset with getSymbolAddress.
This has the following advantages: * Less code. * The old ELF implementation was wrong for non-relocatable objects. * The old ELF implementation (and I think MachO) was wrong for thumb. No current testcase since this is only used from MCJIT and it only uses relocatable objects and I don't think it supports thumb yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205508 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r--include/llvm/Object/COFF.h2
-rw-r--r--include/llvm/Object/ELFObjectFile.h35
-rw-r--r--include/llvm/Object/MachO.h2
-rw-r--r--include/llvm/Object/ObjectFile.h26
4 files changed, 24 insertions, 41 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index 6ece1b4cd5..6e05c2d006 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -363,8 +363,6 @@ protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const override;
error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const override;
- error_code getSymbolFileOffset(DataRefImpl Symb,
- uint64_t &Res) const override;
error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
error_code getSymbolType(DataRefImpl Symb,
diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h
index bbb09f6328..2958067a29 100644
--- a/include/llvm/Object/ELFObjectFile.h
+++ b/include/llvm/Object/ELFObjectFile.h
@@ -58,8 +58,6 @@ protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const override;
- error_code getSymbolFileOffset(DataRefImpl Symb,
- uint64_t &Res) const override;
error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const override;
error_code getSymbolAlignment(DataRefImpl Symb, uint32_t &Res) const override;
error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override;
@@ -239,39 +237,6 @@ error_code ELFObjectFile<ELFT>::getSymbolVersion(SymbolRef SymRef,
}
template <class ELFT>
-error_code ELFObjectFile<ELFT>::getSymbolFileOffset(DataRefImpl Symb,
- uint64_t &Result) const {
- const Elf_Sym *ESym = getSymbol(Symb);
- const Elf_Shdr *ESec;
- switch (EF.getSymbolTableIndex(ESym)) {
- case ELF::SHN_COMMON:
- // Unintialized symbols have no offset in the object file
- case ELF::SHN_UNDEF:
- Result = UnknownAddressOrSize;
- return object_error::success;
- case ELF::SHN_ABS:
- Result = ESym->st_value;
- return object_error::success;
- default:
- ESec = EF.getSection(ESym);
- }
-
- switch (ESym->getType()) {
- case ELF::STT_SECTION:
- Result = ESec ? ESec->sh_offset : UnknownAddressOrSize;
- return object_error::success;
- case ELF::STT_FUNC:
- case ELF::STT_OBJECT:
- case ELF::STT_NOTYPE:
- Result = ESym->st_value + (ESec ? ESec->sh_offset : 0);
- return object_error::success;
- default:
- Result = UnknownAddressOrSize;
- return object_error::success;
- }
-}
-
-template <class ELFT>
error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
uint64_t &Result) const {
const Elf_Sym *ESym = getSymbol(Symb);
diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h
index 1a957d6951..f2426111a0 100644
--- a/include/llvm/Object/MachO.h
+++ b/include/llvm/Object/MachO.h
@@ -62,8 +62,6 @@ public:
void moveSymbolNext(DataRefImpl &Symb) const override;
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const override;
error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const override;
- error_code getSymbolFileOffset(DataRefImpl Symb,
- uint64_t &Res) const override;
error_code getSymbolAlignment(DataRefImpl Symb, uint32_t &Res) const override;
error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override;
error_code getSymbolType(DataRefImpl Symb,
diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h
index 87c1763a25..fa21417027 100644
--- a/include/llvm/Object/ObjectFile.h
+++ b/include/llvm/Object/ObjectFile.h
@@ -228,7 +228,6 @@ protected:
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
error_code printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override;
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const = 0;
- virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res)const=0;
virtual error_code getSymbolAlignment(DataRefImpl Symb, uint32_t &Res) const;
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const = 0;
virtual error_code getSymbolType(DataRefImpl Symb,
@@ -352,7 +351,30 @@ inline error_code SymbolRef::getAddress(uint64_t &Result) const {
}
inline error_code SymbolRef::getFileOffset(uint64_t &Result) const {
- return getObject()->getSymbolFileOffset(getRawDataRefImpl(), Result);
+ uint64_t Address;
+ if (error_code EC = getAddress(Address))
+ return EC;
+
+ const ObjectFile *Obj = getObject();
+ section_iterator SecI(Obj->section_begin());
+ if (error_code EC = getSection(SecI))
+ return EC;
+
+ uint64_t SectionAddress;
+ if (error_code EC = SecI->getAddress(SectionAddress))
+ return EC;
+
+ uint64_t OffsetInSection = Address - SectionAddress;
+
+ StringRef SecContents;
+ if (error_code EC = SecI->getContents(SecContents))
+ return EC;
+
+ // FIXME: this is a hack.
+ uint64_t SectionOffset = (uint64_t)SecContents.data() - (uint64_t)Obj->base();
+
+ Result = SectionOffset + OffsetInSection;
+ return object_error::success;
}
inline error_code SymbolRef::getAlignment(uint32_t &Result) const {