Skip to content

Commit 86ad7b7

Browse files
committed
Implement MachOObjectFile::isSectionData() and MachOObjectFile::isSectionBSS
so that llvm-size will total up all the sections in the Berkeley format. This allows for rough categorizations for Mach-O sections. And allows the total of llvm-size’s Berkeley and System V formats to be the same. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209158 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ca162fa commit 86ad7b7

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

lib/Object/MachOObjectFile.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,21 @@ MachOObjectFile::isSectionText(DataRefImpl Sec, bool &Res) const {
686686
return object_error::success;
687687
}
688688

689-
error_code MachOObjectFile::isSectionData(DataRefImpl DRI, bool &Result) const {
690-
// FIXME: Unimplemented.
691-
Result = false;
689+
error_code MachOObjectFile::isSectionData(DataRefImpl Sec, bool &Result) const {
690+
uint32_t Flags = getSectionFlags(this, Sec);
691+
unsigned SectionType = Flags & MachO::SECTION_TYPE;
692+
Result = !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
693+
!(SectionType == MachO::S_ZEROFILL ||
694+
SectionType == MachO::S_GB_ZEROFILL);
692695
return object_error::success;
693696
}
694697

695-
error_code MachOObjectFile::isSectionBSS(DataRefImpl DRI, bool &Result) const {
696-
// FIXME: Unimplemented.
697-
Result = false;
698+
error_code MachOObjectFile::isSectionBSS(DataRefImpl Sec, bool &Result) const {
699+
uint32_t Flags = getSectionFlags(this, Sec);
700+
unsigned SectionType = Flags & MachO::SECTION_TYPE;
701+
Result = !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
702+
(SectionType == MachO::S_ZEROFILL ||
703+
SectionType == MachO::S_GB_ZEROFILL);
698704
return object_error::success;
699705
}
700706

844 Bytes
Binary file not shown.

test/Object/size-trivial-macho.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
RUN: llvm-size -A %p/Inputs/macho-text-data-bss.macho-x86_64 \
2+
RUN: | FileCheck %s -check-prefix A
3+
RUN: llvm-size -B %p/Inputs/macho-text-data-bss.macho-x86_64 \
4+
RUN: | FileCheck %s -check-prefix B
5+
6+
A: section size addr
7+
A: __text 12 0
8+
A: __data 4 12
9+
A: __bss 4 112
10+
A: __compact_unwind 32 16
11+
A: __eh_frame 64 48
12+
A: Total 116
13+
14+
B: text data bss dec hex filename
15+
B: 12 100 4 116 74

0 commit comments

Comments
 (0)