resolve a fixme: the "nonexecutable stack directive" is actually
authorChris Lattner <sabre@nondot.org>
Sat, 23 Jan 2010 07:21:06 +0000 (07:21 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 23 Jan 2010 07:21:06 +0000 (07:21 +0000)
a .section.  Switch to it with SwitchSection.

However, I think that this directive should be safe on any ELF target.
If so, we should hoist it up out of the X86 and SystemZ targets.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94298 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmInfo.h
include/llvm/MC/MCSectionELF.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/MC/MCAsmInfo.cpp
lib/MC/MCAsmInfoDarwin.cpp
lib/Target/SystemZ/SystemZMCAsmInfo.cpp
lib/Target/SystemZ/SystemZMCAsmInfo.h
lib/Target/X86/X86MCAsmInfo.cpp
lib/Target/X86/X86MCAsmInfo.h

index 1a93d75201bf3ef6bc0355f9713cfa8185f58f91..22939b52cf4f5944c34c63a0d6d92c87ad9acb38 100644 (file)
@@ -20,6 +20,9 @@
 #include <cassert>
 
 namespace llvm {
+  class MCSection;
+  class MCContext;
+  
   /// MCAsmInfo - This class is intended to be used as a base class for asm
   /// properties and features specific to the target.
   namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; }
@@ -30,11 +33,10 @@ namespace llvm {
     // Properties to be set by the target writer, used to configure asm printer.
     //
 
-    /// NonexecutableStackDirective - Directive for declaring to the
-    /// linker and beyond that the emitted code does not require stack
-    /// memory to be executable.
-    const char *NonexecutableStackDirective; // Default is null.
-
+    /// HasSubsectionsViaSymbols - True if this target has the MachO
+    /// .subsections_via_symbols directive.
+    bool HasSubsectionsViaSymbols;           // Default is false.
+    
     /// HasMachoZeroFillDirective - True if this is a MachO target that supports
     /// the macho-specific .zerofill directive for emitting BSS Symbols.
     bool HasMachoZeroFillDirective;               // Default is false.
@@ -288,14 +290,12 @@ namespace llvm {
     explicit MCAsmInfo();
     virtual ~MCAsmInfo();
 
-    /// getSLEB128Size - Compute the number of bytes required for a signed
-    /// leb128 value.
+    // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
     static unsigned getSLEB128Size(int Value);
-
-    /// getULEB128Size - Compute the number of bytes required for an unsigned
-    /// leb128 value.
     static unsigned getULEB128Size(unsigned Value);
 
+    bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
+    
     // Data directive accessors.
     //
     const char *getData8bitsDirective(unsigned AS = 0) const {
@@ -311,6 +311,12 @@ namespace llvm {
       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
     }
 
+    /// getNonexecutableStackSection - Targets can implement this method to
+    /// specify a section to switch to if the translation unit doesn't have any
+    /// trampolines that require an executable stack.
+    virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
+      return 0;
+    }
     
     bool usesSunStyleELFSectionSwitchSyntax() const {
       return SunStyleELFSectionSwitchSyntax;
@@ -326,9 +332,6 @@ namespace llvm {
     bool hasStaticCtorDtorReferenceInStaticMode() const {
       return HasStaticCtorDtorReferenceInStaticMode;
     }
-    const char *getNonexecutableStackDirective() const {
-      return NonexecutableStackDirective;
-    }
     bool needsSet() const {
       return NeedsSet;
     }
index c48ff03e6d79873baf019e59a952e5e4726d5019..2dccf5c57286473c10d5f7ce96de1d22b1137e42 100644 (file)
@@ -31,7 +31,7 @@ class MCSectionELF : public MCSection {
   unsigned Flags;
 
   /// IsExplicit - Indicates that this section comes from globals with an
-  /// explicit section specfied.
+  /// explicit section specified.
   bool IsExplicit;
   
 protected:
index 7238a52f0392ed63dbb989f0580e1ee111b03fbe..fc2c5a00dae85393c13d8b34419e5e1fceeadbd9 100644 (file)
@@ -345,11 +345,8 @@ bool AsmPrinter::doFinalization(Module &M) {
   // to be executable. Some targets have a directive to declare this.
   Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
   if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
-    // FIXME: This is actually a section switch on linux/x86 and systemz, use
-    // switch section.
-    if (MAI->getNonexecutableStackDirective())
-      O << MAI->getNonexecutableStackDirective() << '\n';
-
+    if (MCSection *S = MAI->getNonexecutableStackSection(OutContext))
+      OutStreamer.SwitchSection(S);
   
   // Allow the target to emit any magic that it wants at the end of the file,
   // after everything else has gone out.
index debccaf4b16bf589291d72a53786da903db3ebdc..b96b4e9156f5a0316ee2ff162bf59fc532b15509 100644 (file)
@@ -19,9 +19,9 @@
 using namespace llvm;
 
 MCAsmInfo::MCAsmInfo() {
+  HasSubsectionsViaSymbols = false;
   HasMachoZeroFillDirective = false;
   HasStaticCtorDtorReferenceInStaticMode = false;
-  NonexecutableStackDirective = 0;
   NeedsSet = false;
   MaxInstLength = 4;
   PCSymbol = "$";
index 8495aa44eca59e4cecd4a0354997b6c8ec323f52..9902f501e47cd42ff50a463e76e64099231f7ea2 100644 (file)
@@ -24,6 +24,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
   NeedsSet = true;
   AllowQuotesInName = true;
   HasSingleParameterDotFile = false;
+  HasSubsectionsViaSymbols = true;
 
   AlignmentIsInBytes = false;
   InlineAsmStart = " InlineAsm Start";
index 8ea11c95b27da54c755d17689253ff5ac72f21c7..ba392bb4d558df2c8ae74408d0a7712685d8ba01 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "SystemZMCAsmInfo.h"
+#include "llvm/MC/MCSectionELF.h"
 using namespace llvm;
 
 SystemZMCAsmInfo::SystemZMCAsmInfo(const Target &T, const StringRef &TT) {
@@ -21,6 +22,9 @@ SystemZMCAsmInfo::SystemZMCAsmInfo(const Target &T, const StringRef &TT) {
   WeakRefDirective = "\t.weak\t";
   SetDirective = "\t.set\t";
   PCSymbol = ".";
+}
 
-  NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
+MCSection *SystemZMCAsmInfo::getNonexecutableStackSection(MCContext &Ctx) const{
+  return MCSectionELF::Create(".note.GNU-stack", MCSectionELF::SHT_PROGBITS,
+                              0, SectionKind::getMetadata(), false, Ctx);
 }
index 3bebcb74e37c49b839e21d4d227891d378c5ac82..00cb99b34c0532d44278f65fb5a51d6dac012cef 100644 (file)
@@ -22,8 +22,9 @@ namespace llvm {
 
   struct SystemZMCAsmInfo : public MCAsmInfo {
     explicit SystemZMCAsmInfo(const Target &T, const StringRef &TT);
+    virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const;
   };
-
+  
 } // namespace llvm
 
 #endif
index 001ce8072863010aff155e1363a7b58193f287f0..1738d495842169e41ceab252d694a140ef21bd37 100644 (file)
@@ -14,6 +14,7 @@
 #include "X86MCAsmInfo.h"
 #include "X86TargetMachine.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/MC/MCSectionELF.h"
 #include "llvm/Support/CommandLine.h"
 using namespace llvm;
 
@@ -87,10 +88,11 @@ X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &Triple) {
   // Exceptions handling
   ExceptionsType = ExceptionHandling::Dwarf;
   AbsoluteEHSectionOffsets = false;
+}
 
-  // On Linux we must declare when we can use a non-executable stack.
-  if (Triple.getOS() == Triple::Linux)
-    NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
+MCSection *X86ELFMCAsmInfo::getNonexecutableStackSection(MCContext &Ctx) const {
+  return MCSectionELF::Create(".note.GNU-stack", MCSectionELF::SHT_PROGBITS,
+                              0, SectionKind::getMetadata(), false, Ctx);
 }
 
 X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {
index 18e2bdbcba916266edf80a57a7b2dd27c081db2f..ca227b7a0baa48ee8aaaf5cd3f564eeeb1fe055d 100644 (file)
@@ -27,6 +27,7 @@ namespace llvm {
 
   struct X86ELFMCAsmInfo : public MCAsmInfo {
     explicit X86ELFMCAsmInfo(const Triple &Triple);
+    virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const;
   };
 
   struct X86MCAsmInfoCOFF : public MCAsmInfoCOFF {