summaryrefslogtreecommitdiff
path: root/tools/llvm-size/llvm-size.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-02-09 21:39:49 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-02-09 21:39:49 +0000
commit1cacc098fe2e8bf36a147626d2651de2f4a57bc9 (patch)
tree34cb9f7408cfb9f72c85d15d0f76d7fbe08796cf /tools/llvm-size/llvm-size.cpp
parentac799e67b602fedb89bbd37bda7533b924d5129e (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260293 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-size/llvm-size.cpp')
-rw-r--r--tools/llvm-size/llvm-size.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp
index 7b1b9c6f93a..aacbe9e25b9 100644
--- a/tools/llvm-size/llvm-size.cpp
+++ b/tools/llvm-size/llvm-size.cpp
@@ -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(ObjectFile *Obj) {
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(ObjectFile *Obj) {
// Print each section.
for (const SectionRef &Section : Obj->sections()) {
+ if (!considerForSize(Obj, Section))
+ continue;
StringRef name;
if (error(Section.getName(name)))
return;