Fix a formatting problems with llvm-size and the -m option.
authorKevin Enderby <enderby@apple.com>
Tue, 9 Feb 2016 18:33:15 +0000 (18:33 +0000)
committerKevin Enderby <enderby@apple.com>
Tue, 9 Feb 2016 18:33:15 +0000 (18:33 +0000)
It was using format() with a string for 64-bit types but was
passed a 32-bit type in places when printing values for
32-bit Mach-O files.

rdar://24542509

llvm-svn: 260243

llvm/test/tools/llvm-size/Inputs/darwin-m.o [new file with mode: 0644]
llvm/test/tools/llvm-size/darwin-m.test [new file with mode: 0644]
llvm/tools/llvm-size/llvm-size.cpp

diff --git a/llvm/test/tools/llvm-size/Inputs/darwin-m.o b/llvm/test/tools/llvm-size/Inputs/darwin-m.o
new file mode 100644 (file)
index 0000000..9672df5
Binary files /dev/null and b/llvm/test/tools/llvm-size/Inputs/darwin-m.o differ
diff --git a/llvm/test/tools/llvm-size/darwin-m.test b/llvm/test/tools/llvm-size/darwin-m.test
new file mode 100644 (file)
index 0000000..23d636b
--- /dev/null
@@ -0,0 +1,7 @@
+RUN: llvm-size -m %p/Inputs/darwin-m.o | FileCheck --check-prefix="DARWIN" %s
+
+DARWIN: Segment : 8
+DARWIN-NEXT:   Section (__TEXT, __text): 4
+DARWIN-NEXT:   Section (__DATA, __data): 4
+DARWIN-NEXT:   total 8
+DARWIN-NEXT: total 8
index 159afcf..5addbb3 100644 (file)
@@ -171,10 +171,11 @@ static void PrintDarwinSectionSizes(MachOObjectFile *MachO) {
         outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
     } else if (Load.C.cmd == MachO::LC_SEGMENT) {
       MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
+      uint64_t Seg_vmsize = Seg.vmsize;
       outs() << "Segment " << Seg.segname << ": "
-             << format(fmt.str().c_str(), Seg.vmsize);
+             << format(fmt.str().c_str(), Seg_vmsize);
       if (DarwinLongFormat)
-        outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) << " fileoff "
+        outs() << " (vmaddr 0x" << format("%" PRIx32, Seg.vmaddr) << " fileoff "
                << Seg.fileoff << ")";
       outs() << "\n";
       total += Seg.vmsize;
@@ -186,9 +187,10 @@ static void PrintDarwinSectionSizes(MachOObjectFile *MachO) {
                  << format("%.16s", &Sec.sectname) << "): ";
         else
           outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
-        outs() << format(fmt.str().c_str(), Sec.size);
+        uint64_t Sec_size = Sec.size;
+        outs() << format(fmt.str().c_str(), Sec_size);
         if (DarwinLongFormat)
-          outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) << " offset "
+          outs() << " (addr 0x" << format("%" PRIx32, Sec.addr) << " offset "
                  << Sec.offset << ")";
         outs() << "\n";
         sec_total += Sec.size;