Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm][ELF] Add ELF header/section header table size statistics #109345

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aeubanks
Copy link
Contributor

Followup to #102363. This makes the elf-object-writer.*Bytes stats sum up to assembler.ObjectBytes.

Followup to llvm#102363. This makes the `elf-object-writer.*Bytes` stats sum up to `assembler.ObjectBytes`.
@llvmbot llvmbot added the mc Machine (object) code label Sep 19, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 19, 2024

@llvm/pr-subscribers-mc

Author: Arthur Eubanks (aeubanks)

Changes

Followup to #102363. This makes the elf-object-writer.*Bytes stats sum up to assembler.ObjectBytes.


Full diff: https://github.com/llvm/llvm-project/pull/109345.diff

1 Files Affected:

  • (modified) llvm/lib/MC/ELFObjectWriter.cpp (+7)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants