summaryrefslogtreecommitdiff
path: root/tools
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
commitf16c2bb320f4d5b33dfaf8df8865f547e6d66005 (patch)
tree551e576e9809d1729da4aaadc72b33fa1d5fb8bb /tools
parent332edeb1dc9e6aed5229091bb56a914e78f177c2 (diff)
downloadllvm-f16c2bb320f4d5b33dfaf8df8865f547e6d66005.tar.gz
llvm-f16c2bb320f4d5b33dfaf8df8865f547e6d66005.tar.bz2
llvm-f16c2bb320f4d5b33dfaf8df8865f547e6d66005.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-objdump/MachODump.cpp5
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp7
-rw-r--r--tools/llvm-readobj/MachODumper.cpp23
3 files changed, 12 insertions, 23 deletions
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp
index c324ff13a6..e9d2b3b1a8 100644
--- a/tools/llvm-objdump/MachODump.cpp
+++ b/tools/llvm-objdump/MachODump.cpp
@@ -337,10 +337,9 @@ void llvm::DisassembleInputMachO(StringRef Filename) {
SectName != "__text")
continue; // Skip non-text sections
- StringRef SegmentName;
DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
- if (MachOOF->getSectionFinalSegmentName(DR, SegmentName) ||
- SegmentName != "__TEXT")
+ StringRef SegmentName = MachOOF->getSectionFinalSegmentName(DR);
+ if (SegmentName != "__TEXT")
continue;
// Insert the functions from the function starts segment into our map.
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 7832cf0dff..9a36e8253d 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -257,8 +257,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
StringRef SegmentName = "";
if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj)) {
DataRefImpl DR = i->getRawDataRefImpl();
- if (error(MachO->getSectionFinalSegmentName(DR, SegmentName)))
- break;
+ SegmentName = MachO->getSectionFinalSegmentName(DR);
}
StringRef name;
if (error(i->getName(name))) break;
@@ -593,10 +592,8 @@ static void PrintSymbolTable(const ObjectFile *o) {
outs() << "*UND*";
else {
if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(o)) {
- StringRef SegmentName;
DataRefImpl DR = Section->getRawDataRefImpl();
- if (error(MachO->getSectionFinalSegmentName(DR, SegmentName)))
- SegmentName = "";
+ StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
outs() << SegmentName << ",";
}
StringRef SectionName;
diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp
index 798c941772..0354e767ba 100644
--- a/tools/llvm-readobj/MachODumper.cpp
+++ b/tools/llvm-readobj/MachODumper.cpp
@@ -157,14 +157,6 @@ namespace {
};
}
-static StringRef parseSegmentOrSectionName(ArrayRef<char> P) {
- if (P[15] == 0)
- // Null terminated.
- return StringRef(P.data());
- // Not null terminated, so this is a 16 char string.
- return StringRef(P.data(), 16);
-}
-
static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) {
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
if (LCI.Command.Type == macho::LCT_Segment64)
@@ -181,8 +173,6 @@ static void getSection(const MachOObject *MachOObj,
InMemoryStruct<macho::Section64> Sect;
MachOObj->ReadSection64(LCI, DRI.d.b, Sect);
- Section.Name = ArrayRef<char>(Sect->Name);
- Section.SegmentName = ArrayRef<char>(Sect->SegmentName);
Section.Address = Sect->Address;
Section.Size = Sect->Size;
Section.Offset = Sect->Offset;
@@ -196,8 +186,6 @@ static void getSection(const MachOObject *MachOObj,
InMemoryStruct<macho::Section> Sect;
MachOObj->ReadSection(LCI, DRI.d.b, Sect);
- Section.Name = Sect->Name;
- Section.SegmentName = Sect->SegmentName;
Section.Address = Sect->Address;
Section.Size = Sect->Size;
Section.Offset = Sect->Offset;
@@ -270,15 +258,20 @@ void MachODumper::printSections() {
MachOSection Section;
getSection(MachO, SecI->getRawDataRefImpl(), Section);
+ DataRefImpl DR = SecI->getRawDataRefImpl();
+
StringRef Name;
if (error(SecI->getName(Name)))
Name = "";
+ ArrayRef<char> RawName = Obj->getSectionRawName(DR);
+ StringRef SegmentName = Obj->getSectionFinalSegmentName(DR);
+ ArrayRef<char> RawSegmentName = Obj->getSectionRawFinalSegmentName(DR);
+
DictScope SectionD(W, "Section");
W.printNumber("Index", SectionIndex);
- W.printBinary("Name", Name, Section.Name);
- W.printBinary("Segment", parseSegmentOrSectionName(Section.SegmentName),
- Section.SegmentName);
+ W.printBinary("Name", Name, RawName);
+ W.printBinary("Segment", SegmentName, RawSegmentName);
W.printHex ("Address", Section.Address);
W.printHex ("Size", Section.Size);
W.printNumber("Offset", Section.Offset);