[llvm] [llvm][ELF] Add ELF header/section header table size statistics (PR #109345)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 12:09:40 PDT 2024
https://github.com/aeubanks updated https://github.com/llvm/llvm-project/pull/109345
>From 09cb9ffe07c3b6dd886d3f571906314becf0fa43 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Thu, 19 Sep 2024 22:40:46 +0000
Subject: [PATCH 1/2] [llvm][ELF] Add ELF header/section header table size
statistics
Followup to #102363. This makes the `elf-object-writer.*Bytes` stats sum up to `assembler.ObjectBytes`.
---
llvm/lib/MC/ELFObjectWriter.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 8127091ad37627..94c7697d250dac 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -68,6 +68,8 @@ using namespace llvm;
namespace {
namespace stats {
+STATISTIC(ELFHeaderBytes, "Total size of ELF headers");
+STATISTIC(SectionHeaderBytes, "Total size of section headers table");
STATISTIC(AllocTextBytes, "Total size of SHF_ALLOC text sections");
STATISTIC(AllocROBytes, "Total size of SHF_ALLOC readonly sections");
STATISTIC(AllocRWBytes, "Total size of SHF_ALLOC read-write sections");
@@ -945,6 +947,7 @@ void ELFWriter::writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t Offset,
}
void ELFWriter::writeSectionHeaders(const MCAssembler &Asm) {
+ uint64_t Start = W.OS.tell();
const unsigned NumSections = SectionTable.size();
// Null section first.
@@ -1008,6 +1011,8 @@ void ELFWriter::writeSectionHeaders(const MCAssembler &Asm) {
writeSectionHeader(GroupSymbolIndex, Offsets.first, Size, *Section);
}
+
+ stats::SectionHeaderBytes += W.OS.tell() - Start;
}
uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
@@ -1023,6 +1028,8 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
// Write out the ELF header ...
writeHeader(Asm);
+ stats::ELFHeaderBytes += W.OS.tell() - StartOffset;
+
// ... then the sections ...
SmallVector<std::pair<MCSectionELF *, SmallVector<unsigned>>, 0> Groups;
// Map from group section index to group
>From 3e4fd3101dc00e83055aaba12bdad27cb7e748ff Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Fri, 20 Sep 2024 19:09:27 +0000
Subject: [PATCH 2/2] add test
---
llvm/test/CodeGen/X86/section-stats.ll | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/test/CodeGen/X86/section-stats.ll b/llvm/test/CodeGen/X86/section-stats.ll
index 94d0a965ac59ee..2cab7d18dec069 100644
--- a/llvm/test/CodeGen/X86/section-stats.ll
+++ b/llvm/test/CodeGen/X86/section-stats.ll
@@ -3,6 +3,8 @@
; CHECK-DAG: 1 elf-object-writer - Total size of SHF_ALLOC text sections
; CHECK-DAG: 1 elf-object-writer - Total size of SHF_ALLOC read-write sections
+; CHECK-DAG: 512 elf-object-writer - Total size of section headers table
+; CHECK-DAG: 64 elf-object-writer - Total size of ELF headers
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list