diff options
author | Tim Northover <Tim.Northover@arm.com> | 2012-12-17 17:59:32 +0000 |
---|---|---|
committer | Tim Northover <Tim.Northover@arm.com> | 2012-12-17 17:59:32 +0000 |
commit | 1c2b2f9c56c01aa1c317da4fd0234eaa1fe6e739 (patch) | |
tree | c9a50c3e1d261072b9a81cb9efb07b20f45b281c | |
parent | 2dfa3eb56679fcb0ac36d2956924e59acf4fc19e (diff) | |
download | external_llvm-1c2b2f9c56c01aa1c317da4fd0234eaa1fe6e739.zip external_llvm-1c2b2f9c56c01aa1c317da4fd0234eaa1fe6e739.tar.gz external_llvm-1c2b2f9c56c01aa1c317da4fd0234eaa1fe6e739.tar.bz2 |
Teach MachO which sections contain code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170349 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Object/MachOFormat.h | 4 | ||||
-rw-r--r-- | lib/MC/MCParser/DarwinAsmParser.cpp | 2 | ||||
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 4 | ||||
-rw-r--r-- | test/Object/Inputs/macho-text-sections.macho-x86_64 | bin | 0 -> 268 bytes | |||
-rw-r--r-- | test/Object/X86/macho-text-sections.test | 3 |
5 files changed, 10 insertions, 3 deletions
diff --git a/include/llvm/Object/MachOFormat.h b/include/llvm/Object/MachOFormat.h index c0f700d..a17d58d 100644 --- a/include/llvm/Object/MachOFormat.h +++ b/include/llvm/Object/MachOFormat.h @@ -237,6 +237,10 @@ namespace macho { /// @name Section Data /// @{ + enum SectionFlags { + SF_PureInstructions = 0x80000000 + }; + struct Section { char Name[16]; char SegmentName[16]; diff --git a/lib/MC/MCParser/DarwinAsmParser.cpp b/lib/MC/MCParser/DarwinAsmParser.cpp index 20c949d..7b042df 100644 --- a/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/lib/MC/MCParser/DarwinAsmParser.cpp @@ -314,7 +314,7 @@ bool DarwinAsmParser::ParseSectionSwitch(const char *Segment, Lex(); // FIXME: Arch specific. - bool isText = StringRef(Segment) == "__TEXT"; // FIXME: Hack. + bool isText = TAA & MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS; getStreamer().SwitchSection(getContext().getMachOSection( Segment, Section, TAA, StubSize, isText ? SectionKind::getText() diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index a38fac7..40f5390 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -559,11 +559,11 @@ error_code MachOObjectFile::isSectionText(DataRefImpl DRI, if (is64BitLoadCommand(MachOObj.get(), DRI)) { InMemoryStruct<macho::Section64> Sect; getSection64(DRI, Sect); - Result = !strcmp(Sect->Name, "__text"); + Result = Sect->Flags & macho::SF_PureInstructions; } else { InMemoryStruct<macho::Section> Sect; getSection(DRI, Sect); - Result = !strcmp(Sect->Name, "__text"); + Result = Sect->Flags & macho::SF_PureInstructions; } return object_error::success; } diff --git a/test/Object/Inputs/macho-text-sections.macho-x86_64 b/test/Object/Inputs/macho-text-sections.macho-x86_64 Binary files differnew file mode 100644 index 0000000..cce203b --- /dev/null +++ b/test/Object/Inputs/macho-text-sections.macho-x86_64 diff --git a/test/Object/X86/macho-text-sections.test b/test/Object/X86/macho-text-sections.test new file mode 100644 index 0000000..1b697dc --- /dev/null +++ b/test/Object/X86/macho-text-sections.test @@ -0,0 +1,3 @@ +RUN: llvm-objdump -disassemble %p/../Inputs/macho-text-sections.macho-x86_64 | FileCheck %s + +CHECK: Disassembly of section __notext,__notext |