summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2012-03-19 20:27:37 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2012-03-19 20:27:37 +0000
commit9da9e6937f6931ae410b5b66f094b906d4dcf1d1 (patch)
treef5c3918ead5535bcc0e4915a97b529a55b48722f /llvm
parent53c2d5477adca4f6ed991ec9e4cbc26445c58a7b (diff)
downloadbcm5719-llvm-9da9e6937f6931ae410b5b66f094b906d4dcf1d1.tar.gz
bcm5719-llvm-9da9e6937f6931ae410b5b66f094b906d4dcf1d1.zip
[Object/COFF]: Expose getSectionContents.
llvm-svn: 153051
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Object/COFF.h5
-rw-r--r--llvm/lib/Object/COFFObjectFile.cpp29
2 files changed, 24 insertions, 10 deletions
diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index f19ce6f19e8..91971bb01bb 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -19,6 +19,9 @@
#include "llvm/Support/Endian.h"
namespace llvm {
+ template <typename T>
+ class ArrayRef;
+
namespace object {
struct coff_file_header {
@@ -178,6 +181,8 @@ public:
}
error_code getSymbolName(const coff_symbol *symbol, StringRef &Res) const;
error_code getSectionName(const coff_section *Sec, StringRef &Res) const;
+ error_code getSectionContents(const coff_section *Sec,
+ ArrayRef<uint8_t> &Res) const;
static inline bool classof(const Binary *v) {
return v->isCOFF();
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index afe9e737f0e..b8ba90535ea 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Object/COFF.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
@@ -320,16 +321,10 @@ error_code COFFObjectFile::getSectionSize(DataRefImpl Sec,
error_code COFFObjectFile::getSectionContents(DataRefImpl Sec,
StringRef &Result) const {
const coff_section *sec = toSec(Sec);
- // The only thing that we need to verify is that the contents is contained
- // within the file bounds. We don't need to make sure it doesn't cover other
- // data, as there's nothing that says that is not allowed.
- uintptr_t con_start = uintptr_t(base()) + sec->PointerToRawData;
- uintptr_t con_end = con_start + sec->SizeOfRawData;
- if (con_end > uintptr_t(Data->getBufferEnd()))
- return object_error::parse_failed;
- Result = StringRef(reinterpret_cast<const char*>(con_start),
- sec->SizeOfRawData);
- return object_error::success;
+ ArrayRef<uint8_t> Res;
+ error_code EC = getSectionContents(sec, Res);
+ Result = StringRef(reinterpret_cast<const char*>(Res.data()), Res.size());
+ return EC;
}
error_code COFFObjectFile::getSectionAlignment(DataRefImpl Sec,
@@ -636,6 +631,20 @@ error_code COFFObjectFile::getSectionName(const coff_section *Sec,
return object_error::success;
}
+error_code COFFObjectFile::getSectionContents(const coff_section *Sec,
+ ArrayRef<uint8_t> &Res) const {
+ // The only thing that we need to verify is that the contents is contained
+ // within the file bounds. We don't need to make sure it doesn't cover other
+ // data, as there's nothing that says that is not allowed.
+ uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;
+ uintptr_t ConEnd = ConStart + Sec->SizeOfRawData;
+ if (ConEnd > uintptr_t(Data->getBufferEnd()))
+ return object_error::parse_failed;
+ Res = ArrayRef<uint8_t>(reinterpret_cast<const unsigned char*>(ConStart),
+ Sec->SizeOfRawData);
+ return object_error::success;
+}
+
const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
return reinterpret_cast<const coff_relocation*>(Rel.p);
}
OpenPOWER on IntegriCloud