[PATCH] D82479: [llvm-size] Output REL, RELA and STRTAB sections in some cases
Owen Reynolds via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 24 10:15:32 PDT 2020
gbreynoo created this revision.
gbreynoo added reviewers: MaskRay, grimar.
Herald added subscribers: llvm-commits, rupprecht.
Herald added a reviewer: jhenderson.
Herald added a project: LLVM.
gnu size has a number of special cases regarding REL, RELA and STRTAB sections being considered in size output. To avoid unnecessary complexity this commit makes llvm size outputs these sections in cases they have the SHF_ALLOC flag. See related bugzilla:
https://bugs.llvm.org/show_bug.cgi?id=42934
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D82479
Files:
llvm/test/tools/llvm-size/output-alloc.test
llvm/tools/llvm-size/llvm-size.cpp
Index: llvm/tools/llvm-size/llvm-size.cpp
===================================================================
--- llvm/tools/llvm-size/llvm-size.cpp
+++ llvm/tools/llvm-size/llvm-size.cpp
@@ -180,6 +180,30 @@
return nullptr;
}
+static uint64_t getShstrndx(ObjectFile *Obj) {
+ if (const auto *ELFObj = dyn_cast<object::ELF32LEObjectFile>(Obj))
+ return ELFObj->getELFFile()->getHeader()->e_shstrndx;
+
+ if (const auto *ELFObj = dyn_cast<object::ELF32BEObjectFile>(Obj))
+ return ELFObj->getELFFile()->getHeader()->e_shstrndx;
+
+ if (const auto *ELFObj = dyn_cast<object::ELF64LEObjectFile>(Obj))
+ return ELFObj->getELFFile()->getHeader()->e_shstrndx;
+
+ const auto *ELFObj = dyn_cast<object::ELF64BEObjectFile>(Obj);
+ return ELFObj->getELFFile()->getHeader()->e_shstrndx;
+}
+
+static bool isAllocatable(ObjectFile *Obj, SectionRef Section) {
+ if (Section.getIndex() == getShstrndx(Obj))
+ return false;
+
+ ELFSectionRef ElfSection = static_cast<ELFSectionRef>(Section);
+ if (ElfSection.getFlags() & ELF::SHF_ALLOC)
+ return true;
+ return false;
+}
+
/// Remove unneeded ELF sections from calculation
static bool considerForSize(ObjectFile *Obj, SectionRef Section) {
if (!Obj->isELF())
@@ -187,10 +211,11 @@
switch (static_cast<ELFSectionRef>(Section).getType()) {
case ELF::SHT_NULL:
case ELF::SHT_SYMTAB:
+ return false;
case ELF::SHT_STRTAB:
case ELF::SHT_REL:
case ELF::SHT_RELA:
- return false;
+ return isAllocatable(Obj, Section);
}
return true;
}
Index: llvm/test/tools/llvm-size/output-alloc.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-size/output-alloc.test
@@ -0,0 +1,38 @@
+## gnu size has a number of special cases regarding REL, RELA and STRTAB sections being considered in size output.
+## To avoid unnecessary complexity llvm size outputs these sections in cases they have the SHF_ALLOC flag.
+
+# RUN: yaml2obj %s -o %t1
+# RUN: llvm-size --format=sysv %t1 | FileCheck %s
+
+# CHECK: section size addr
+# CHECK-NEXT: .rela.alloc
+# CHECK-NEXT: .rel.alloc
+# CHECK-NEXT: .strtab.alloc
+# CHECK-NEXT: Total
+# CHECK-EMPTY:
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .rela.alloc
+ Type: SHT_RELA
+ Flags: [ SHF_ALLOC ]
+ - Name: .rel.alloc
+ Type: SHT_REL
+ Flags: [ SHF_ALLOC ]
+ - Name: .strtab.alloc
+ Type: SHT_STRTAB
+ Flags: [ SHF_ALLOC ]
+ - Name: .rela
+ Type: SHT_RELA
+ Flags: []
+ - Name: .rel
+ Type: SHT_REL
+ Flags: []
+ - Name: .strtab
+ Type: SHT_STRTAB
+ Flags: []
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82479.273067.patch
Type: text/x-patch
Size: 2700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200624/981f4ed7/attachment.bin>
More information about the llvm-commits
mailing list