[llvm-commits] [llvm] r50634 - in /llvm/trunk: include/llvm/Target/TargetAsmInfo.h lib/CodeGen/AsmPrinter.cpp lib/Target/TargetAsmInfo.cpp lib/Target/X86/X86Subtarget.cpp lib/Target/X86/X86Subtarget.h lib/Target/X86/X86TargetAsmInfo.cpp test/CodeGen/X86/xor_not.ll
Dan Gohman
gohman at apple.com
Sun May 4 17:28:39 PDT 2008
Author: djg
Date: Sun May 4 19:28:39 2008
New Revision: 50634
URL: http://llvm.org/viewvc/llvm-project?rev=50634&view=rev
Log:
Add AsmPrinter support for emitting a directive to declare that
the code being generated does not require an executable stack.
Also, add target-specific code to make use of this on Linux
on x86.
Modified:
llvm/trunk/include/llvm/Target/TargetAsmInfo.h
llvm/trunk/lib/CodeGen/AsmPrinter.cpp
llvm/trunk/lib/Target/TargetAsmInfo.cpp
llvm/trunk/lib/Target/X86/X86Subtarget.cpp
llvm/trunk/lib/Target/X86/X86Subtarget.h
llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
llvm/trunk/test/CodeGen/X86/xor_not.ll
Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=50634&r1=50633&r2=50634&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sun May 4 19:28:39 2008
@@ -61,10 +61,16 @@
/// Null if this target doesn't support a BSS section.
///
const char *TLSBSSSection;// Default to ".section .tbss,"awT", at nobits".
+
/// ZeroFillDirective - Directive for emitting a global to the ZeroFill
/// section on this target. Null if this target doesn't support zerofill.
const char *ZeroFillDirective; // Default is null.
+ /// 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.
+
/// NeedsSet - True if target asm treats expressions in data directives
/// as linktime-relocatable. For assembly-time computation, we need to
/// use a .set. Thus:
@@ -440,6 +446,9 @@
const char *getZeroFillDirective() const {
return ZeroFillDirective;
}
+ const char *getNonexecutableStackDirective() const {
+ return NonexecutableStackDirective;
+ }
bool needsSet() const {
return NeedsSet;
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter.cpp?rev=50634&r1=50633&r2=50634&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter.cpp Sun May 4 19:28:39 2008
@@ -192,6 +192,13 @@
E = CMM->begin(); I != E; )
(*--I)->finishAssembly(O, *this, *TAI);
+ // If we don't have any trampolines, then we don't require stack memory
+ // to be executable. Some targets have a directive to declare this.
+ Function* InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
+ if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
+ if (TAI->getNonexecutableStackDirective())
+ O << TAI->getNonexecutableStackDirective() << "\n";
+
delete Mang; Mang = 0;
return false;
}
Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=50634&r1=50633&r2=50634&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sun May 4 19:28:39 2008
@@ -26,6 +26,7 @@
TLSDataSection("\t.section .tdata,\"awT\", at progbits"),
TLSBSSSection("\t.section .tbss,\"awT\", at nobits"),
ZeroFillDirective(0),
+ NonexecutableStackDirective(0),
NeedsSet(false),
MaxInstLength(4),
PCSymbol("$"),
Modified: llvm/trunk/lib/Target/X86/X86Subtarget.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Subtarget.cpp?rev=50634&r1=50633&r2=50634&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86Subtarget.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86Subtarget.cpp Sun May 4 19:28:39 2008
@@ -278,6 +278,8 @@
DarwinVers = atoi(&TT[Pos+7]);
else
DarwinVers = 8; // Minimum supported darwin is Tiger.
+ } else if (TT.find("linux") != std::string::npos) {
+ TargetType = isELFLinux;
} else if (TT.find("cygwin") != std::string::npos) {
TargetType = isCygwin;
} else if (TT.find("mingw") != std::string::npos) {
@@ -302,6 +304,9 @@
#elif defined(_WIN32) || defined(_WIN64)
TargetType = isWindows;
+#elif defined(__linux__)
+ // Linux doesn't imply ELF, but we don't currently support anything else.
+ TargetType = isELFLinux;
#endif
}
Modified: llvm/trunk/lib/Target/X86/X86Subtarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Subtarget.h?rev=50634&r1=50633&r2=50634&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86Subtarget.h (original)
+++ llvm/trunk/lib/Target/X86/X86Subtarget.h Sun May 4 19:28:39 2008
@@ -84,7 +84,7 @@
public:
enum {
- isELF, isCygwin, isDarwin, isWindows, isMingw
+ isELF, isELFLinux, isCygwin, isDarwin, isWindows, isMingw
} TargetType;
/// This constructor initializes the data members to match that
@@ -132,7 +132,12 @@
bool isFlavorIntel() const { return AsmFlavor == Intel; }
bool isTargetDarwin() const { return TargetType == isDarwin; }
- bool isTargetELF() const { return TargetType == isELF; }
+ bool isTargetELF() const {
+ return TargetType == isELF || TargetType == isELFLinux;
+ }
+ bool isTargetLinux() const {
+ return TargetType == isELFLinux;
+ }
bool isTargetWindows() const { return TargetType == isWindows; }
bool isTargetMingw() const { return TargetType == isMingw; }
bool isTargetCygMing() const { return (TargetType == isMingw ||
Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp?rev=50634&r1=50633&r2=50634&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Sun May 4 19:28:39 2008
@@ -128,6 +128,7 @@
break;
case X86Subtarget::isELF:
+ case X86Subtarget::isELFLinux:
ReadOnlySection = "\t.section\t.rodata";
FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\", at progbits,4";
EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\", at progbits,8";
@@ -229,6 +230,10 @@
SectionEndDirectiveSuffix = "\tends\n";
}
+ // On Linux we must declare when we can use a non-executable stack.
+ if (Subtarget->isTargetLinux())
+ NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\", at progbits";
+
AssemblerDialect = Subtarget->getAsmFlavor();
}
Modified: llvm/trunk/test/CodeGen/X86/xor_not.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xor_not.ll?rev=50634&r1=50633&r2=50634&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xor_not.ll (original)
+++ llvm/trunk/test/CodeGen/X86/xor_not.ll Sun May 4 19:28:39 2008
@@ -1,5 +1,5 @@
-; RUN: llvm-as < %s | llc -march=x86 | grep {not} | count 3
-; RUN: llvm-as < %s | llc -march=x86-64 | grep {not} | count 4
+; RUN: llvm-as < %s | llc -march=x86 | grep {not\[lwb\]} | count 3
+; RUN: llvm-as < %s | llc -march=x86-64 | grep {not\[lwb\]} | count 4
define i32 @test(i32 %a, i32 %b) nounwind {
entry:
%tmp1not = xor i32 %b, -2
More information about the llvm-commits
mailing list