[llvm] r260293 - This brings back commit r259578.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 13:39:49 PST 2016


Author: rafael
Date: Tue Feb  9 15:39:49 2016
New Revision: 260293

URL: http://llvm.org/viewvc/llvm-project?rev=260293&view=rev
Log:
This brings back commit r259578.

But now it follows the llvm style, uses an early return and doesn't
include a file named 1.o.

Added:
    llvm/trunk/test/tools/llvm-size/X86/
    llvm/trunk/test/tools/llvm-size/X86/ignore-sections.s
    llvm/trunk/test/tools/llvm-size/X86/lit.local.cfg
Modified:
    llvm/trunk/tools/llvm-size/llvm-size.cpp

Added: llvm/trunk/test/tools/llvm-size/X86/ignore-sections.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-size/X86/ignore-sections.s?rev=260293&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-size/X86/ignore-sections.s (added)
+++ llvm/trunk/test/tools/llvm-size/X86/ignore-sections.s Tue Feb  9 15:39:49 2016
@@ -0,0 +1,28 @@
+// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
+// RUN: llvm-size -A %t.o | FileCheck --check-prefix="SYSV" %s
+// RUN: llvm-size -B %t.o| FileCheck --check-prefix="BSD" %s
+
+        .text
+        .zero 4
+        .data
+        .long foo
+        .bss
+        .zero 4
+        .ident "foo"
+        .section foo
+        .long 42
+        .cfi_startproc
+        .cfi_endproc
+
+// SYSV:    {{[ -\(\)_A-Za-z0-9.\\/:]+}}  :
+// SYSV-NEXT:    section             size   addr
+// SYSV-NEXT:    .text                  4      0
+// SYSV-NEXT:    .data                  4      0
+// SYSV-NEXT:    .bss                   4      0
+// SYSV-NEXT:    .comment               5      0
+// SYSV-NEXT:    foo                    4      0
+// SYSV-NEXT:    .eh_frame             48      0
+// SYSV-NEXT:    Total                 69
+
+// BSD:        text    data     bss     dec     hex filename
+// BSD-NEXT:      4       4       4      12       c {{[ -\(\)_A-Za-z0-9.\\/:]+}}

Added: llvm/trunk/test/tools/llvm-size/X86/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-size/X86/lit.local.cfg?rev=260293&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-size/X86/lit.local.cfg (added)
+++ llvm/trunk/test/tools/llvm-size/X86/lit.local.cfg Tue Feb  9 15:39:49 2016
@@ -0,0 +1,2 @@
+if not 'X86' in config.root.targets:
+    config.unsupported = True

Modified: llvm/trunk/tools/llvm-size/llvm-size.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-size/llvm-size.cpp?rev=260293&r1=260292&r2=260293&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-size/llvm-size.cpp (original)
+++ llvm/trunk/tools/llvm-size/llvm-size.cpp Tue Feb  9 15:39:49 2016
@@ -15,6 +15,7 @@
 
 #include "llvm/ADT/APInt.h"
 #include "llvm/Object/Archive.h"
+#include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Object/MachOUniversal.h"
 #include "llvm/Object/ObjectFile.h"
@@ -111,6 +112,21 @@ static const char *getRadixFmt() {
   return nullptr;
 }
 
+/// Remove unneeded ELF sections from calculation
+static bool considerForSize(ObjectFile *Obj, SectionRef Section) {
+  if (!Obj->isELF())
+    return true;
+  switch (static_cast<ELFSectionRef>(Section).getType()) {
+  case ELF::SHT_NULL:
+  case ELF::SHT_SYMTAB:
+  case ELF::SHT_STRTAB:
+  case ELF::SHT_REL:
+  case ELF::SHT_RELA:
+    return false;
+  }
+  return true;
+}
+
 /// Print the size of each Mach-O segment and section in @p MachO.
 ///
 /// This is when used when @c OutputFormat is darwin and produces the same
@@ -287,6 +303,8 @@ static void printObjectSectionSizes(Obje
     std::size_t max_size_len = strlen("size");
     std::size_t max_addr_len = strlen("addr");
     for (const SectionRef &Section : Obj->sections()) {
+      if (!considerForSize(Obj, Section))
+        continue;
       uint64_t size = Section.getSize();
       total += size;
 
@@ -322,6 +340,8 @@ static void printObjectSectionSizes(Obje
 
     // Print each section.
     for (const SectionRef &Section : Obj->sections()) {
+      if (!considerForSize(Obj, Section))
+        continue;
       StringRef name;
       if (error(Section.getName(name)))
         return;




More information about the llvm-commits mailing list