|
14 | 14 | #include "llvm/ADT/DenseMap.h"
|
15 | 15 | #include "llvm/ADT/STLExtras.h"
|
16 | 16 | #include "llvm/ADT/SmallVector.h"
|
| 17 | +#include "llvm/ADT/Statistic.h" |
17 | 18 | #include "llvm/ADT/StringExtras.h"
|
18 | 19 | #include "llvm/ADT/StringRef.h"
|
19 | 20 | #include "llvm/ADT/Twine.h"
|
|
62 | 63 |
|
63 | 64 | using namespace llvm;
|
64 | 65 |
|
65 |
| -#undef DEBUG_TYPE |
66 |
| -#define DEBUG_TYPE "reloc-info" |
| 66 | +#define DEBUG_TYPE "elf-object-writer" |
67 | 67 |
|
68 | 68 | namespace {
|
| 69 | +namespace stats { |
| 70 | + |
| 71 | +STATISTIC(AllocTextBytes, "Total size of SHF_ALLOC text sections"); |
| 72 | +STATISTIC(AllocROBytes, "Total size of SHF_ALLOC readonly sections"); |
| 73 | +STATISTIC(AllocRWBytes, "Total size of SHF_ALLOC read-write sections"); |
| 74 | +STATISTIC(StrtabBytes, "Total size of SHT_STRTAB sections"); |
| 75 | +STATISTIC(SymtabBytes, "Total size of SHT_SYMTAB sections"); |
| 76 | +STATISTIC(RelocationBytes, "Total size of relocation sections"); |
| 77 | +STATISTIC(DynsymBytes, "Total size of SHT_DYNSYM sections"); |
| 78 | +STATISTIC(DebugBytes, "Total size of debug info sections"); |
| 79 | +STATISTIC(UnwindBytes, "Total size of unwind sections"); |
| 80 | +STATISTIC(OtherBytes, "Total size of uncategorized sections"); |
| 81 | + |
| 82 | +} // namespace stats |
69 | 83 |
|
70 | 84 | struct ELFWriter;
|
71 | 85 |
|
@@ -951,6 +965,44 @@ void ELFWriter::writeSectionHeader(const MCAssembler &Asm) {
|
951 | 965 | else
|
952 | 966 | Size = Offsets.second - Offsets.first;
|
953 | 967 |
|
| 968 | + auto SectionHasFlag = [&](uint64_t Flag) -> bool { |
| 969 | + return Section->getFlags() & Flag; |
| 970 | + }; |
| 971 | + |
| 972 | + if (Section->getName().starts_with(".debug")) { |
| 973 | + stats::DebugBytes += Size; |
| 974 | + } else if (Section->getName().starts_with(".eh_frame")) { |
| 975 | + stats::UnwindBytes += Size; |
| 976 | + } else if (SectionHasFlag(ELF::SHF_ALLOC)) { |
| 977 | + if (SectionHasFlag(ELF::SHF_EXECINSTR)) { |
| 978 | + stats::AllocTextBytes += Size; |
| 979 | + } else if (SectionHasFlag(ELF::SHF_WRITE)) { |
| 980 | + stats::AllocRWBytes += Size; |
| 981 | + } else { |
| 982 | + stats::AllocROBytes += Size; |
| 983 | + } |
| 984 | + } else { |
| 985 | + switch (Section->getType()) { |
| 986 | + case ELF::SHT_STRTAB: |
| 987 | + stats::StrtabBytes += Size; |
| 988 | + break; |
| 989 | + case ELF::SHT_SYMTAB: |
| 990 | + stats::SymtabBytes += Size; |
| 991 | + break; |
| 992 | + case ELF::SHT_DYNSYM: |
| 993 | + stats::DynsymBytes += Size; |
| 994 | + break; |
| 995 | + case ELF::SHT_REL: |
| 996 | + case ELF::SHT_RELA: |
| 997 | + case ELF::SHT_CREL: |
| 998 | + stats::RelocationBytes += Size; |
| 999 | + break; |
| 1000 | + default: |
| 1001 | + stats::OtherBytes += Size; |
| 1002 | + break; |
| 1003 | + } |
| 1004 | + } |
| 1005 | + |
954 | 1006 | writeSection(GroupSymbolIndex, Offsets.first, Size, *Section);
|
955 | 1007 | }
|
956 | 1008 | }
|
|
0 commit comments