Implement MachOObjectFile::isSectionData() and MachOObjectFile::isSectionBSS
authorKevin Enderby <enderby@apple.com>
Mon, 19 May 2014 20:36:02 +0000 (20:36 +0000)
committerKevin Enderby <enderby@apple.com>
Mon, 19 May 2014 20:36:02 +0000 (20:36 +0000)
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

lib/Object/MachOObjectFile.cpp
test/Object/Inputs/macho-text-data-bss.macho-x86_64 [new file with mode: 0644]
test/Object/size-trivial-macho.test [new file with mode: 0644]

index fa95eca669f11a4769e692353a1dd48942430c81..0951460ccbb26c4f815ae378898e104a04d27e24 100644 (file)
@@ -686,15 +686,21 @@ MachOObjectFile::isSectionText(DataRefImpl Sec, bool &Res) const {
   return object_error::success;
 }
 
-error_code MachOObjectFile::isSectionData(DataRefImpl DRI, bool &Result) const {
-  // FIXME: Unimplemented.
-  Result = false;
+error_code MachOObjectFile::isSectionData(DataRefImpl Sec, bool &Result) const {
+  uint32_t Flags = getSectionFlags(this, Sec);
+  unsigned SectionType = Flags & MachO::SECTION_TYPE;
+  Result = !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
+           !(SectionType == MachO::S_ZEROFILL ||
+             SectionType == MachO::S_GB_ZEROFILL);
   return object_error::success;
 }
 
-error_code MachOObjectFile::isSectionBSS(DataRefImpl DRI, bool &Result) const {
-  // FIXME: Unimplemented.
-  Result = false;
+error_code MachOObjectFile::isSectionBSS(DataRefImpl Sec, bool &Result) const {
+  uint32_t Flags = getSectionFlags(this, Sec);
+  unsigned SectionType = Flags & MachO::SECTION_TYPE;
+  Result = !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
+           (SectionType == MachO::S_ZEROFILL ||
+            SectionType == MachO::S_GB_ZEROFILL);
   return object_error::success;
 }
 
diff --git a/test/Object/Inputs/macho-text-data-bss.macho-x86_64 b/test/Object/Inputs/macho-text-data-bss.macho-x86_64
new file mode 100644 (file)
index 0000000..b7628c8
Binary files /dev/null and b/test/Object/Inputs/macho-text-data-bss.macho-x86_64 differ
diff --git a/test/Object/size-trivial-macho.test b/test/Object/size-trivial-macho.test
new file mode 100644 (file)
index 0000000..6ecdf5c
--- /dev/null
@@ -0,0 +1,15 @@
+RUN: llvm-size -A %p/Inputs/macho-text-data-bss.macho-x86_64 \
+RUN:         | FileCheck %s -check-prefix A
+RUN: llvm-size -B %p/Inputs/macho-text-data-bss.macho-x86_64 \
+RUN:         | FileCheck %s -check-prefix B
+
+A: section              size   addr
+A: __text                 12      0
+A: __data                  4     12
+A: __bss                   4    112
+A: __compact_unwind       32     16
+A: __eh_frame             64     48
+A: Total                 116
+
+B:   text    data     bss     dec     hex filename
+B:     12     100       4     116      74