From 86ad7b70cb994a9ebde84053026e560a37061ce9 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Mon, 19 May 2014 20:36:02 +0000 Subject: [PATCH] =?UTF-8?q?Implement=20MachOObjectFile::isSectionData()=20?= =?UTF-8?q?and=20MachOObjectFile::isSectionBSS=20so=20that=20llvm-size=20w?= =?UTF-8?q?ill=20total=20up=20all=20the=20sections=20in=20the=20Berkeley?= =?UTF-8?q?=20format.=20=20This=20allows=20for=20rough=20categorizations?= =?UTF-8?q?=20for=20Mach-O=20sections.=20=20And=20allows=20the=20total=20o?= =?UTF-8?q?f=20llvm-size=E2=80=99s=20Berkeley=20and=20System=20V=20formats?= =?UTF-8?q?=20to=20be=20the=20same.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209158 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 18 ++++++++++++------ .../Inputs/macho-text-data-bss.macho-x86_64 | Bin 0 -> 844 bytes test/Object/size-trivial-macho.test | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/Object/Inputs/macho-text-data-bss.macho-x86_64 create mode 100644 test/Object/size-trivial-macho.test diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index fa95eca669f..0951460ccbb 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -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 index 0000000000000000000000000000000000000000..b7628c83799af95603040ac1e2179d89469fd257 GIT binary patch literal 844 zcmb7Cu}Z^W5Wdvf3bsuK2L*)=&eBI{v4so{A`x8VOq)mqTZ4^QoSX!4>7)1#K7fuL zT^xM@2lcz;e)+`!#G zZLtWHPUhisYQ@TY=3RzQQf_2`y<;ABj_Kb8tb|~lFPEe-wPa1NquH-*