summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-10-17 23:53:56 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-10-17 23:53:56 +0000
commit0e752cb4b4eb5676aace4d9f3d7c2e2334c13777 (patch)
tree10f92903ce3a52dfb93ae0e56b11411fa031a637
parentab6bcf35aefe823894d349773ebd53f465f122b7 (diff)
downloadllvm-0e752cb4b4eb5676aace4d9f3d7c2e2334c13777.tar.gz
llvm-0e752cb4b4eb5676aace4d9f3d7c2e2334c13777.tar.bz2
llvm-0e752cb4b4eb5676aace4d9f3d7c2e2334c13777.tar.xz
Object/COFF: Expose more data in the public API.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142315 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/COFF.h25
-rw-r--r--lib/Object/COFFObjectFile.cpp42
2 files changed, 47 insertions, 20 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index 1dd8f983ec..321bceee64 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -73,6 +73,16 @@ struct coff_relocation {
support::ulittle16_t Type;
};
+struct coff_aux_section_definition {
+ support::ulittle32_t Length;
+ support::ulittle16_t NumberOfRelocations;
+ support::ulittle16_t NumberOfLinenumbers;
+ support::ulittle32_t CheckSum;
+ support::ulittle16_t Number;
+ support::ulittle8_t Selection;
+ char Unused[3];
+};
+
class COFFObjectFile : public ObjectFile {
private:
const coff_file_header *Header;
@@ -81,11 +91,7 @@ private:
const char *StringTable;
uint32_t StringTableSize;
- error_code getSection(int32_t index,
- const coff_section *&Res) const;
error_code getString(uint32_t offset, StringRef &Res) const;
- error_code getSymbol(uint32_t index,
- const coff_symbol *&Res) const;
const coff_symbol *toSymb(DataRefImpl Symb) const;
const coff_section *toSec(DataRefImpl Sec) const;
@@ -142,6 +148,17 @@ public:
virtual StringRef getFileFormatName() const;
virtual unsigned getArch() const;
+ error_code getHeader(const coff_file_header *&Res) const;
+ error_code getSection(int32_t index, const coff_section *&Res) const;
+ error_code getSymbol(uint32_t index, const coff_symbol *&Res) const;
+ template <typename T>
+ error_code getAuxSymbol(uint32_t index, const T *&Res) const {
+ const coff_symbol *s;
+ error_code ec = getSymbol(index, s);
+ Res = reinterpret_cast<const T*>(s);
+ return ec;
+ }
+ error_code getSymbolName(const coff_symbol *symbol, StringRef &Res) const;
static inline bool classof(const Binary *v) {
return v->getType() == isCOFF;
diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp
index 8e038a2a85..6fdb263d8e 100644
--- a/lib/Object/COFFObjectFile.cpp
+++ b/lib/Object/COFFObjectFile.cpp
@@ -98,21 +98,7 @@ error_code COFFObjectFile::getSymbolNext(DataRefImpl Symb,
error_code COFFObjectFile::getSymbolName(DataRefImpl Symb,
StringRef &Result) const {
const coff_symbol *symb = toSymb(Symb);
- // Check for string table entry. First 4 bytes are 0.
- if (symb->Name.Offset.Zeroes == 0) {
- uint32_t Offset = symb->Name.Offset.Offset;
- if (error_code ec = getString(Offset, Result))
- return ec;
- return object_error::success;
- }
-
- if (symb->Name.ShortName[7] == 0)
- // Null terminated, let ::strlen figure out the length.
- Result = StringRef(symb->Name.ShortName);
- else
- // Not null terminated, use all 8 bytes.
- Result = StringRef(symb->Name.ShortName, 8);
- return object_error::success;
+ return getSymbolName(symb, Result);
}
error_code COFFObjectFile::getSymbolOffset(DataRefImpl Symb,
@@ -525,6 +511,11 @@ unsigned COFFObjectFile::getArch() const {
}
}
+error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const {
+ Res = Header;
+ return object_error::success;
+}
+
error_code COFFObjectFile::getSection(int32_t index,
const coff_section *&Result) const {
// Check for special index values.
@@ -553,13 +544,32 @@ error_code COFFObjectFile::getString(uint32_t offset,
error_code COFFObjectFile::getSymbol(uint32_t index,
const coff_symbol *&Result) const {
- if (index > 0 && index < Header->NumberOfSymbols)
+ if (index >= 0 && index < Header->NumberOfSymbols)
Result = SymbolTable + index;
else
return object_error::parse_failed;
return object_error::success;
}
+error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol,
+ StringRef &Res) const {
+ // Check for string table entry. First 4 bytes are 0.
+ if (symbol->Name.Offset.Zeroes == 0) {
+ uint32_t Offset = symbol->Name.Offset.Offset;
+ if (error_code ec = getString(Offset, Res))
+ return ec;
+ return object_error::success;
+ }
+
+ if (symbol->Name.ShortName[7] == 0)
+ // Null terminated, let ::strlen figure out the length.
+ Res = StringRef(symbol->Name.ShortName);
+ else
+ // Not null terminated, use all 8 bytes.
+ Res = StringRef(symbol->Name.ShortName, 8);
+ return object_error::success;
+}
+
const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
return reinterpret_cast<const coff_relocation*>(Rel.p);
}