MC/Mach-O: Set SOME_INSTRUCTIONS bit for sections.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 2 Feb 2010 21:44:01 +0000 (21:44 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 2 Feb 2010 21:44:01 +0000 (21:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95135 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAssembler.h
lib/MC/MCAssembler.cpp
lib/MC/MCMachOStreamer.cpp
test/MC/MachO/section-flags.s [new file with mode: 0644]

index be017bf0e4c172c76bb92240d8cc1f3bf8c09c77..55696b08fd627702538a1359f0dcaf5747c27486 100644 (file)
@@ -348,7 +348,11 @@ private:
 
   /// Fixups - The list of fixups in this section.
   std::vector<Fixup> Fixups;
-  
+
+  /// HasInstructions - Whether this section has had instructions emitted into
+  /// it.
+  unsigned HasInstructions : 1;
+
   /// @}
 
 public:    
@@ -429,6 +433,9 @@ public:
   }
   void setFileSize(uint64_t Value) { FileSize = Value; }  
 
+  bool hasInstructions() const { return HasInstructions; }
+  void setHasInstructions(bool Value) { HasInstructions = Value; }
+
   /// @}
 };
 
index 08943ebd93e09ea1b3889288ec514e25658fb6f4..c471a02eb78c86fa3c7db0d8086c56dba58d4f7d 100644 (file)
@@ -266,11 +266,15 @@ public:
     Write32(SD.getSize()); // size
     Write32(FileOffset);
 
+    unsigned Flags = Section.getTypeAndAttributes();
+    if (SD.hasInstructions())
+      Flags |= MCSectionMachO::S_ATTR_SOME_INSTRUCTIONS;
+
     assert(isPowerOf2_32(SD.getAlignment()) && "Invalid alignment!");
     Write32(Log2_32(SD.getAlignment()));
     Write32(NumRelocations ? RelocationsStart : 0);
     Write32(NumRelocations);
-    Write32(Section.getTypeAndAttributes());
+    Write32(Flags);
     Write32(0); // reserved1
     Write32(Section.getStubSize()); // reserved2
 
@@ -901,7 +905,8 @@ MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
     Address(~UINT64_C(0)),
     Size(~UINT64_C(0)),
     FileSize(~UINT64_C(0)),
-    LastFixupLookup(~0)
+    LastFixupLookup(~0),
+    HasInstructions(false)
 {
   if (A)
     A->getSectionList().push_back(this);
index 143793cde1022cfb3edb2b8059ee027f56dfcf2f..981eb72d14c9993bf24050d40b8112a9df65b8cb 100644 (file)
@@ -362,8 +362,8 @@ void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
   if (!Emitter)
     llvm_unreachable("no code emitter available!");
 
-  // FIXME: Emitting an instruction should cause S_ATTR_SOME_INSTRUCTIONS to
-  //        be set for the current section.
+  CurSectionData->setHasInstructions(true);
+
   // FIXME: Relocations!
   SmallString<256> Code;
   raw_svector_ostream VecOS(Code);
diff --git a/test/MC/MachO/section-flags.s b/test/MC/MachO/section-flags.s
new file mode 100644 (file)
index 0000000..8ac1bbf
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o - | macho-dump | FileCheck %s
+//
+// CHECK: # Section 0
+// CHECK: 'section_name', '__text
+// CHECK: 'flags', 0x80000000
+// CHECK: # Section 1
+// CHECK: 'section_name', '__data
+// CHECK: 'flags', 0x400
+        
+        .text
+
+        .data
+f0:
+        movl $0, %eax