[PATCH] D13041: [llvm-readobj/MachO] Ensure we always have a valid reference to SegmentName
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 17:41:29 PDT 2015
davide created this revision.
davide added reviewers: rafael, echristo, grosbach.
davide added a subscriber: llvm-commits.
This way we don't end up printing garbage. Found while testing lld-macho.
http://reviews.llvm.org/D13041
Files:
llvm-readobj/MachODumper.cpp
Index: llvm-readobj/MachODumper.cpp
===================================================================
--- llvm-readobj/MachODumper.cpp
+++ llvm-readobj/MachODumper.cpp
@@ -268,7 +268,6 @@
struct MachOSegment {
StringRef CmdName;
- StringRef SegName;
uint64_t cmdsize;
uint64_t vmaddr;
uint64_t vmsize;
@@ -336,7 +335,6 @@
if (!Obj->is64Bit()) {
MachO::segment_command SC = Obj->getSegmentLoadCommand(L);
Segment.CmdName = "LC_SEGMENT";
- Segment.SegName = SC.segname;
Segment.cmdsize = SC.cmdsize;
Segment.vmaddr = SC.vmaddr;
Segment.vmsize = SC.vmsize;
@@ -350,7 +348,6 @@
}
MachO::segment_command_64 SC = Obj->getSegment64LoadCommand(L);
Segment.CmdName = "LC_SEGMENT_64";
- Segment.SegName = SC.segname;
Segment.cmdsize = SC.cmdsize;
Segment.vmaddr = SC.vmaddr;
Segment.vmsize = SC.vmsize;
@@ -760,10 +757,19 @@
for (const auto &Load : Obj->load_commands()) {
if (Load.C.cmd == MachO::LC_SEGMENT || Load.C.cmd == MachO::LC_SEGMENT_64) {
MachOSegment MOSegment;
+ StringRef SegName;
getSegment(Obj, Load, MOSegment);
+ if (!Obj->is64Bit()) {
+ MachO::segment_command SC = Obj->getSegmentLoadCommand(Load);
+ SegName = SC.segname;
+ }
+ else {
+ MachO::segment_command_64 SC = Obj->getSegment64LoadCommand(Load);
+ SegName = SC.segname;
+ }
DictScope Group(W, "Segment");
W.printString("Cmd", MOSegment.CmdName);
- W.printString("Name", MOSegment.SegName);
+ W.printString("Name", SegName);
W.printNumber("Size", MOSegment.cmdsize);
W.printHex("vmaddr", MOSegment.vmaddr);
W.printHex("vmsize", MOSegment.vmsize);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13041.35331.patch
Type: text/x-patch
Size: 1714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150922/00ecc6c4/attachment.bin>
More information about the llvm-commits
mailing list