diff options
author | Hemant Kulkarni <khemant@codeaurora.org> | 2016-02-02 21:41:49 +0000 |
---|---|---|
committer | Hemant Kulkarni <khemant@codeaurora.org> | 2016-02-02 21:41:49 +0000 |
commit | 782edae7d66601cf75d69ff971390cf09af627b4 (patch) | |
tree | 9cb9dbb4bf50d8119d30bcd64262f68013bc0ff4 /llvm/tools/llvm-size/llvm-size.cpp | |
parent | f3eb90743ccb74d23ee2066109beb067c970eb45 (diff) | |
download | bcm5719-llvm-782edae7d66601cf75d69ff971390cf09af627b4.tar.gz bcm5719-llvm-782edae7d66601cf75d69ff971390cf09af627b4.zip |
Correct size calculations for ELF files
llvm-svn: 259578
Diffstat (limited to 'llvm/tools/llvm-size/llvm-size.cpp')
-rw-r--r-- | llvm/tools/llvm-size/llvm-size.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp index e8f95573051..159afcf6c86 100644 --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -15,11 +15,13 @@ #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" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ELF.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" @@ -111,6 +113,20 @@ static const char *getRadixFmt() { return nullptr; } +/// @brief Remove unneeded ELF sections from calculation +static bool ConsiderForSize(ObjectFile *Obj, SectionRef Section) { + if (Obj->isELF()) { + 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; +} /// @brief 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 @@ -285,6 +301,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; @@ -320,6 +338,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; |