llvm.org GIT mirror llvm / a779a98
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50634 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
7 changed file(s) with 36 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
6060 /// Null if this target doesn't support a BSS section.
6161 ///
6262 const char *TLSBSSSection;// Default to ".section .tbss,"awT",@nobits".
63
6364 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
6465 /// section on this target. Null if this target doesn't support zerofill.
6566 const char *ZeroFillDirective; // Default is null.
6667
68 /// NonexecutableStackDirective - Directive for declaring to the
69 /// linker and beyond that the emitted code does not require stack
70 /// memory to be executable.
71 const char *NonexecutableStackDirective; // Default is null.
72
6773 /// NeedsSet - True if target asm treats expressions in data directives
6874 /// as linktime-relocatable. For assembly-time computation, we need to
6975 /// use a .set. Thus:
439445 const char *getZeroFillDirective() const {
440446 return ZeroFillDirective;
441447 }
448 const char *getNonexecutableStackDirective() const {
449 return NonexecutableStackDirective;
450 }
442451 bool needsSet() const {
443452 return NeedsSet;
444453 }
190190 for (CollectorModuleMetadata::iterator I = CMM->end(),
191191 E = CMM->begin(); I != E; )
192192 (*--I)->finishAssembly(O, *this, *TAI);
193
194 // If we don't have any trampolines, then we don't require stack memory
195 // to be executable. Some targets have a directive to declare this.
196 Function* InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
197 if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
198 if (TAI->getNonexecutableStackDirective())
199 O << TAI->getNonexecutableStackDirective() << "\n";
193200
194201 delete Mang; Mang = 0;
195202 return false;
2525 TLSDataSection("\t.section .tdata,\"awT\",@progbits"),
2626 TLSBSSSection("\t.section .tbss,\"awT\",@nobits"),
2727 ZeroFillDirective(0),
28 NonexecutableStackDirective(0),
2829 NeedsSet(false),
2930 MaxInstLength(4),
3031 PCSymbol("$"),
277277 DarwinVers = atoi(&TT[Pos+7]);
278278 else
279279 DarwinVers = 8; // Minimum supported darwin is Tiger.
280 } else if (TT.find("linux") != std::string::npos) {
281 TargetType = isELFLinux;
280282 } else if (TT.find("cygwin") != std::string::npos) {
281283 TargetType = isCygwin;
282284 } else if (TT.find("mingw") != std::string::npos) {
301303
302304 #elif defined(_WIN32) || defined(_WIN64)
303305 TargetType = isWindows;
306 #elif defined(__linux__)
307 // Linux doesn't imply ELF, but we don't currently support anything else.
308 TargetType = isELFLinux;
304309 #endif
305310 }
306311
8383
8484 public:
8585 enum {
86 isELF, isCygwin, isDarwin, isWindows, isMingw
86 isELF, isELFLinux, isCygwin, isDarwin, isWindows, isMingw
8787 } TargetType;
8888
8989 /// This constructor initializes the data members to match that
131131 bool isFlavorIntel() const { return AsmFlavor == Intel; }
132132
133133 bool isTargetDarwin() const { return TargetType == isDarwin; }
134 bool isTargetELF() const { return TargetType == isELF; }
134 bool isTargetELF() const {
135 return TargetType == isELF || TargetType == isELFLinux;
136 }
137 bool isTargetLinux() const {
138 return TargetType == isELFLinux;
139 }
135140 bool isTargetWindows() const { return TargetType == isWindows; }
136141 bool isTargetMingw() const { return TargetType == isMingw; }
137142 bool isTargetCygMing() const { return (TargetType == isMingw ||
127127 break;
128128
129129 case X86Subtarget::isELF:
130 case X86Subtarget::isELFLinux:
130131 ReadOnlySection = "\t.section\t.rodata";
131132 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
132133 EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
228229 SectionEndDirectiveSuffix = "\tends\n";
229230 }
230231
232 // On Linux we must declare when we can use a non-executable stack.
233 if (Subtarget->isTargetLinux())
234 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
235
231236 AssemblerDialect = Subtarget->getAsmFlavor();
232237 }
233238
None ; RUN: llvm-as < %s | llc -march=x86 | grep {not} | count 3
1 ; RUN: llvm-as < %s | llc -march=x86-64 | grep {not} | count 4
0 ; RUN: llvm-as < %s | llc -march=x86 | grep {not\[lwb\]} | count 3
1 ; RUN: llvm-as < %s | llc -march=x86-64 | grep {not\[lwb\]} | count 4
22 define i32 @test(i32 %a, i32 %b) nounwind {
33 entry:
44 %tmp1not = xor i32 %b, -2