Teach MachO which sections contain code
authorTim Northover <Tim.Northover@arm.com>
Mon, 17 Dec 2012 17:59:32 +0000 (17:59 +0000)
committerTim Northover <Tim.Northover@arm.com>
Mon, 17 Dec 2012 17:59:32 +0000 (17:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170349 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/MachOFormat.h
lib/MC/MCParser/DarwinAsmParser.cpp
lib/Object/MachOObjectFile.cpp
test/Object/Inputs/macho-text-sections.macho-x86_64 [new file with mode: 0644]
test/Object/X86/macho-text-sections.test [new file with mode: 0644]

index c0f700d3c870ad0125ea3c6f9bf69518aace28b9..a17d58dae2347ca3b2c38dc3aa7e10f9dc8834cc 100644 (file)
@@ -237,6 +237,10 @@ namespace macho {
   /// @name Section Data
   /// @{
 
+  enum SectionFlags {
+    SF_PureInstructions = 0x80000000
+  };
+
   struct Section {
     char Name[16];
     char SegmentName[16];
index 20c949dbdaaa86cd8002afa3f6add3d65418695e..7b042df292e6ba7af5efb04645ddbc0ee05ba39c 100644 (file)
@@ -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()
index a38fac78aae2fabdff673afdd7dc6ec00769c353..40f5390a96f70761d77da1aedbe496fe6fc92d0b 100644 (file)
@@ -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
new file mode 100644 (file)
index 0000000..cce203b
Binary files /dev/null and b/test/Object/Inputs/macho-text-sections.macho-x86_64 differ
diff --git a/test/Object/X86/macho-text-sections.test b/test/Object/X86/macho-text-sections.test
new file mode 100644 (file)
index 0000000..1b697dc
--- /dev/null
@@ -0,0 +1,3 @@
+RUN: llvm-objdump -disassemble %p/../Inputs/macho-text-sections.macho-x86_64 | FileCheck %s
+
+CHECK: Disassembly of section __notext,__notext