resolve a fixme: the "nonexecutable stack directive" is actually

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
This commit is contained in:
Chris Lattner 2010-01-23 07:21:06 +00:00
parent 74670b26fc
commit f9f93e4388
9 changed files with 35 additions and 26 deletions

View File

@ -20,6 +20,9 @@
#include <cassert> #include <cassert>
namespace llvm { namespace llvm {
class MCSection;
class MCContext;
/// MCAsmInfo - This class is intended to be used as a base class for asm /// MCAsmInfo - This class is intended to be used as a base class for asm
/// properties and features specific to the target. /// properties and features specific to the target.
namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; } namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; }
@ -30,10 +33,9 @@ namespace llvm {
// Properties to be set by the target writer, used to configure asm printer. // Properties to be set by the target writer, used to configure asm printer.
// //
/// NonexecutableStackDirective - Directive for declaring to the /// HasSubsectionsViaSymbols - True if this target has the MachO
/// linker and beyond that the emitted code does not require stack /// .subsections_via_symbols directive.
/// memory to be executable. bool HasSubsectionsViaSymbols; // Default is false.
const char *NonexecutableStackDirective; // Default is null.
/// HasMachoZeroFillDirective - True if this is a MachO target that supports /// HasMachoZeroFillDirective - True if this is a MachO target that supports
/// the macho-specific .zerofill directive for emitting BSS Symbols. /// the macho-specific .zerofill directive for emitting BSS Symbols.
@ -288,14 +290,12 @@ namespace llvm {
explicit MCAsmInfo(); explicit MCAsmInfo();
virtual ~MCAsmInfo(); virtual ~MCAsmInfo();
/// getSLEB128Size - Compute the number of bytes required for a signed // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
/// leb128 value.
static unsigned getSLEB128Size(int Value); static unsigned getSLEB128Size(int Value);
/// getULEB128Size - Compute the number of bytes required for an unsigned
/// leb128 value.
static unsigned getULEB128Size(unsigned Value); static unsigned getULEB128Size(unsigned Value);
bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
// Data directive accessors. // Data directive accessors.
// //
const char *getData8bitsDirective(unsigned AS = 0) const { const char *getData8bitsDirective(unsigned AS = 0) const {
@ -311,6 +311,12 @@ namespace llvm {
return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS); 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 { bool usesSunStyleELFSectionSwitchSyntax() const {
return SunStyleELFSectionSwitchSyntax; return SunStyleELFSectionSwitchSyntax;
@ -326,9 +332,6 @@ namespace llvm {
bool hasStaticCtorDtorReferenceInStaticMode() const { bool hasStaticCtorDtorReferenceInStaticMode() const {
return HasStaticCtorDtorReferenceInStaticMode; return HasStaticCtorDtorReferenceInStaticMode;
} }
const char *getNonexecutableStackDirective() const {
return NonexecutableStackDirective;
}
bool needsSet() const { bool needsSet() const {
return NeedsSet; return NeedsSet;
} }

View File

@ -31,7 +31,7 @@ class MCSectionELF : public MCSection {
unsigned Flags; unsigned Flags;
/// IsExplicit - Indicates that this section comes from globals with an /// IsExplicit - Indicates that this section comes from globals with an
/// explicit section specfied. /// explicit section specified.
bool IsExplicit; bool IsExplicit;
protected: protected:

View File

@ -345,11 +345,8 @@ bool AsmPrinter::doFinalization(Module &M) {
// to be executable. Some targets have a directive to declare this. // to be executable. Some targets have a directive to declare this.
Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline"); Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty()) if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
// FIXME: This is actually a section switch on linux/x86 and systemz, use if (MCSection *S = MAI->getNonexecutableStackSection(OutContext))
// switch section. OutStreamer.SwitchSection(S);
if (MAI->getNonexecutableStackDirective())
O << MAI->getNonexecutableStackDirective() << '\n';
// Allow the target to emit any magic that it wants at the end of the file, // Allow the target to emit any magic that it wants at the end of the file,
// after everything else has gone out. // after everything else has gone out.

View File

@ -19,9 +19,9 @@
using namespace llvm; using namespace llvm;
MCAsmInfo::MCAsmInfo() { MCAsmInfo::MCAsmInfo() {
HasSubsectionsViaSymbols = false;
HasMachoZeroFillDirective = false; HasMachoZeroFillDirective = false;
HasStaticCtorDtorReferenceInStaticMode = false; HasStaticCtorDtorReferenceInStaticMode = false;
NonexecutableStackDirective = 0;
NeedsSet = false; NeedsSet = false;
MaxInstLength = 4; MaxInstLength = 4;
PCSymbol = "$"; PCSymbol = "$";

View File

@ -24,6 +24,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
NeedsSet = true; NeedsSet = true;
AllowQuotesInName = true; AllowQuotesInName = true;
HasSingleParameterDotFile = false; HasSingleParameterDotFile = false;
HasSubsectionsViaSymbols = true;
AlignmentIsInBytes = false; AlignmentIsInBytes = false;
InlineAsmStart = " InlineAsm Start"; InlineAsmStart = " InlineAsm Start";

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "SystemZMCAsmInfo.h" #include "SystemZMCAsmInfo.h"
#include "llvm/MC/MCSectionELF.h"
using namespace llvm; using namespace llvm;
SystemZMCAsmInfo::SystemZMCAsmInfo(const Target &T, const StringRef &TT) { SystemZMCAsmInfo::SystemZMCAsmInfo(const Target &T, const StringRef &TT) {
@ -21,6 +22,9 @@ SystemZMCAsmInfo::SystemZMCAsmInfo(const Target &T, const StringRef &TT) {
WeakRefDirective = "\t.weak\t"; WeakRefDirective = "\t.weak\t";
SetDirective = "\t.set\t"; SetDirective = "\t.set\t";
PCSymbol = "."; 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);
} }

View File

@ -22,6 +22,7 @@ namespace llvm {
struct SystemZMCAsmInfo : public MCAsmInfo { struct SystemZMCAsmInfo : public MCAsmInfo {
explicit SystemZMCAsmInfo(const Target &T, const StringRef &TT); explicit SystemZMCAsmInfo(const Target &T, const StringRef &TT);
virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const;
}; };
} // namespace llvm } // namespace llvm

View File

@ -14,6 +14,7 @@
#include "X86MCAsmInfo.h" #include "X86MCAsmInfo.h"
#include "X86TargetMachine.h" #include "X86TargetMachine.h"
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
using namespace llvm; using namespace llvm;
@ -87,10 +88,11 @@ X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &Triple) {
// Exceptions handling // Exceptions handling
ExceptionsType = ExceptionHandling::Dwarf; ExceptionsType = ExceptionHandling::Dwarf;
AbsoluteEHSectionOffsets = false; AbsoluteEHSectionOffsets = false;
}
// On Linux we must declare when we can use a non-executable stack. MCSection *X86ELFMCAsmInfo::getNonexecutableStackSection(MCContext &Ctx) const {
if (Triple.getOS() == Triple::Linux) return MCSectionELF::Create(".note.GNU-stack", MCSectionELF::SHT_PROGBITS,
NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits"; 0, SectionKind::getMetadata(), false, Ctx);
} }
X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) { X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {

View File

@ -27,6 +27,7 @@ namespace llvm {
struct X86ELFMCAsmInfo : public MCAsmInfo { struct X86ELFMCAsmInfo : public MCAsmInfo {
explicit X86ELFMCAsmInfo(const Triple &Triple); explicit X86ELFMCAsmInfo(const Triple &Triple);
virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const;
}; };
struct X86MCAsmInfoCOFF : public MCAsmInfoCOFF { struct X86MCAsmInfoCOFF : public MCAsmInfoCOFF {