diff --git a/llvm/lib/MC/MCAsmInfoELF.cpp b/llvm/lib/MC/MCAsmInfoELF.cpp --- a/llvm/lib/MC/MCAsmInfoELF.cpp +++ b/llvm/lib/MC/MCAsmInfoELF.cpp @@ -21,6 +21,10 @@ void MCAsmInfoELF::anchor() {} MCSection *MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const { + // Solaris doesn't know/doesn't care about .note.GNU-stack sections, so + // don't emit them. + if (Ctx.getTargetTriple().isOSSolaris()) + return nullptr; return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, 0); } diff --git a/llvm/test/CodeGen/X86/execstack.ll b/llvm/test/CodeGen/X86/execstack.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/execstack.ll @@ -0,0 +1,9 @@ +;; Check that .note.GNU-stack sections are emitted on Linux, but not on Solaris. + +; RUN: llc < %s -mtriple=i686-linux | FileCheck %s -check-prefix=CHECK-GNUSTACK +; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s -check-prefix=CHECK-GNUSTACK +; RUN: llc < %s -mtriple=i386-solaris | FileCheck %s -check-prefix=CHECK-NOGNUSTACK +; RUN: llc < %s -mtriple=amd64-solaris | FileCheck %s -check-prefix=CHECK-NOGNUSTACK + +; CHECK-GNUSTACK: .section ".note.GNU-stack","",@progbits +; CHECK-NOGNUSTACK-NOT: .section ".note.GNU-stack","",@progbits