From: Tim Northover Date: Mon, 17 Dec 2012 17:59:32 +0000 (+0000) Subject: Teach MachO which sections contain code X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5edabc131a091a82b15a8166aa3d4d6c9bd8d85f;p=platform%2Fupstream%2Fllvm.git Teach MachO which sections contain code llvm-svn: 170349 --- diff --git a/llvm/include/llvm/Object/MachOFormat.h b/llvm/include/llvm/Object/MachOFormat.h index c0f700d..a17d58d 100644 --- a/llvm/include/llvm/Object/MachOFormat.h +++ b/llvm/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/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp index 20c949d..7b042df 100644 --- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/llvm/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/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index a38fac7..40f5390 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -559,11 +559,11 @@ error_code MachOObjectFile::isSectionText(DataRefImpl DRI, if (is64BitLoadCommand(MachOObj.get(), DRI)) { InMemoryStruct Sect; getSection64(DRI, Sect); - Result = !strcmp(Sect->Name, "__text"); + Result = Sect->Flags & macho::SF_PureInstructions; } else { InMemoryStruct Sect; getSection(DRI, Sect); - Result = !strcmp(Sect->Name, "__text"); + Result = Sect->Flags & macho::SF_PureInstructions; } return object_error::success; } diff --git a/llvm/test/Object/Inputs/macho-text-sections.macho-x86_64 b/llvm/test/Object/Inputs/macho-text-sections.macho-x86_64 new file mode 100644 index 0000000..cce203b Binary files /dev/null and b/llvm/test/Object/Inputs/macho-text-sections.macho-x86_64 differ diff --git a/llvm/test/Object/X86/macho-text-sections.test b/llvm/test/Object/X86/macho-text-sections.test new file mode 100644 index 0000000..1b697dc --- /dev/null +++ b/llvm/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