Skip to content

Commit e44ecf7

Browse files
authored
[llvm][ELF] Add ELF header/section header table size statistics (#109345)
Followup to #102363. This makes the `elf-object-writer.*Bytes` stats sum up to `assembler.ObjectBytes`.
1 parent 954ab83 commit e44ecf7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ using namespace llvm;
6868
namespace {
6969
namespace stats {
7070

71+
STATISTIC(ELFHeaderBytes, "Total size of ELF headers");
72+
STATISTIC(SectionHeaderBytes, "Total size of section headers table");
7173
STATISTIC(AllocTextBytes, "Total size of SHF_ALLOC text sections");
7274
STATISTIC(AllocROBytes, "Total size of SHF_ALLOC readonly sections");
7375
STATISTIC(AllocRWBytes, "Total size of SHF_ALLOC read-write sections");
@@ -945,6 +947,7 @@ void ELFWriter::writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t Offset,
945947
}
946948

947949
void ELFWriter::writeSectionHeaders(const MCAssembler &Asm) {
950+
uint64_t Start = W.OS.tell();
948951
const unsigned NumSections = SectionTable.size();
949952

950953
// Null section first.
@@ -1008,6 +1011,8 @@ void ELFWriter::writeSectionHeaders(const MCAssembler &Asm) {
10081011

10091012
writeSectionHeader(GroupSymbolIndex, Offsets.first, Size, *Section);
10101013
}
1014+
1015+
stats::SectionHeaderBytes += W.OS.tell() - Start;
10111016
}
10121017

10131018
uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
@@ -1023,6 +1028,8 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
10231028
// Write out the ELF header ...
10241029
writeHeader(Asm);
10251030

1031+
stats::ELFHeaderBytes += W.OS.tell() - StartOffset;
1032+
10261033
// ... then the sections ...
10271034
SmallVector<std::pair<MCSectionELF *, SmallVector<unsigned>>, 0> Groups;
10281035
// Map from group section index to group

llvm/test/CodeGen/X86/section-stats.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
; CHECK-DAG: 1 elf-object-writer - Total size of SHF_ALLOC text sections
55
; CHECK-DAG: 1 elf-object-writer - Total size of SHF_ALLOC read-write sections
6+
; CHECK-DAG: 512 elf-object-writer - Total size of section headers table
7+
; CHECK-DAG: 64 elf-object-writer - Total size of ELF headers
68

79
target triple = "x86_64-unknown-linux-gnu"
810

0 commit comments

Comments
 (0)