aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-05 15:15:22 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-05 15:15:22 +0000
commitb0f76a4b753dfe2608b3c4e0b63af4b92cf5312d (patch)
treed796216a2d3650220d4cf20c18bdca3c4c032dab /llvm/lib/Object/MachOObjectFile.cpp
parentf5407e8d8f9c7472ebcf158b64e149099cba284a (diff)
downloadllvm-b0f76a4b753dfe2608b3c4e0b63af4b92cf5312d.zip
llvm-b0f76a4b753dfe2608b3c4e0b63af4b92cf5312d.tar.gz
llvm-b0f76a4b753dfe2608b3c4e0b63af4b92cf5312d.tar.bz2
Don't fetch pointers from a InMemoryStruct.
InMemoryStruct is extremely dangerous as it returns data from an internal buffer when the endiannes doesn't match. This should fix the tests on big endian hosts. llvm-svn: 178875
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 6501df9..9ab3599 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -481,8 +481,7 @@ static StringRef parseSegmentOrSectionName(const char *P) {
return StringRef(P, 16);
}
-error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
- StringRef &Result) const {
+ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl DRI) const {
if (is64BitLoadCommand(MachOObj.get(), DRI)) {
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
unsigned SectionOffset = LCI.Offset + sizeof(macho::Segment64LoadCommand) +
@@ -490,7 +489,7 @@ error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section64));
const macho::Section64 *sec =
reinterpret_cast<const macho::Section64*>(Data.data());
- Result = parseSegmentOrSectionName(sec->Name);
+ return ArrayRef<char>(sec->Name, 16);
} else {
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
unsigned SectionOffset = LCI.Offset + sizeof(macho::SegmentLoadCommand) +
@@ -498,13 +497,19 @@ error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section));
const macho::Section *sec =
reinterpret_cast<const macho::Section*>(Data.data());
- Result = parseSegmentOrSectionName(sec->Name);
+ return ArrayRef<char>(sec->Name, 16);
}
+}
+
+error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
+ StringRef &Result) const {
+ ArrayRef<char> Raw = getSectionRawName(DRI);
+ Result = parseSegmentOrSectionName(Raw.data());
return object_error::success;
}
-error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec,
- StringRef &Res) const {
+ArrayRef<char>
+MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const {
if (is64BitLoadCommand(MachOObj.get(), Sec)) {
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a);
unsigned SectionOffset = LCI.Offset + sizeof(macho::Segment64LoadCommand) +
@@ -512,7 +517,7 @@ error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec,
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section64));
const macho::Section64 *sec =
reinterpret_cast<const macho::Section64*>(Data.data());
- Res = parseSegmentOrSectionName(sec->SegmentName);
+ return ArrayRef<char>(sec->SegmentName, 16);
} else {
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a);
unsigned SectionOffset = LCI.Offset + sizeof(macho::SegmentLoadCommand) +
@@ -520,9 +525,13 @@ error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec,
StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section));
const macho::Section *sec =
reinterpret_cast<const macho::Section*>(Data.data());
- Res = parseSegmentOrSectionName(sec->SegmentName);
+ return ArrayRef<char>(sec->SegmentName);
}
- return object_error::success;
+}
+
+StringRef MachOObjectFile::getSectionFinalSegmentName(DataRefImpl DRI) const {
+ ArrayRef<char> Raw = getSectionRawFinalSegmentName(DRI);
+ return parseSegmentOrSectionName(Raw.data());
}
error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,