diff options
-rw-r--r-- | lld/ELF/Writer.cpp | 12 | ||||
-rw-r--r-- | lld/test/ELF/gnustack.s | 40 |
2 files changed, 31 insertions, 21 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 51253f14f55..d7278cd6110 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1334,9 +1334,15 @@ template <class ELFT> std::vector<PhdrEntry> Writer<ELFT>::createPhdrs() { AddHdr(PT_OPENBSD_RANDOMIZE, Sec->getPhdrFlags())->add(Sec); // PT_GNU_STACK is a special section to tell the loader to make the - // pages for the stack non-executable. - if (!Config->ZExecstack) - AddHdr(PT_GNU_STACK, PF_R | PF_W)->p_memsz = Config->ZStackSize; + // pages for the stack non-executable. If you really want an executable + // stack, you can pass -z execstack, but that's not recommended for + // security reasons. + unsigned Perm; + if (Config->ZExecstack) + Perm = PF_R | PF_W | PF_X; + else + Perm = PF_R | PF_W; + AddHdr(PT_GNU_STACK, Perm)->p_memsz = Config->ZStackSize; // PT_OPENBSD_WXNEEDED is a OpenBSD-specific header to mark the executable // is expected to perform W^X violations, such as calling mprotect(2) or diff --git a/lld/test/ELF/gnustack.s b/lld/test/ELF/gnustack.s index 6fc937354e6..c506fb807c6 100644 --- a/lld/test/ELF/gnustack.s +++ b/lld/test/ELF/gnustack.s @@ -5,26 +5,30 @@ # RUN: ld.lld %t1 -o %t # RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RW %s -# RW: Sections [ -# RW-NOT: Name: .note.GNU-stack -# RW: ProgramHeaders [ -# RW: ProgramHeader { -# RW: Type: PT_GNU_STACK -# RW-NEXT: Offset: 0x0 -# RW-NEXT: VirtualAddress: 0x0 -# RW-NEXT: PhysicalAddress: 0x0 -# RW-NEXT: FileSize: 0 -# RW-NEXT: MemSize: 0 -# RW-NEXT: Flags [ -# RW-NEXT: PF_R -# RW-NEXT: PF_W -# RW-NEXT: ] -# RW-NEXT: Alignment: 0 -# RW-NEXT: } +# RW: Type: PT_GNU_STACK +# RW-NEXT: Offset: 0x0 +# RW-NEXT: VirtualAddress: 0x0 +# RW-NEXT: PhysicalAddress: 0x0 +# RW-NEXT: FileSize: 0 +# RW-NEXT: MemSize: 0 +# RW-NEXT: Flags [ +# RW-NEXT: PF_R +# RW-NEXT: PF_W # RW-NEXT: ] +# RW-NEXT: Alignment: 0 -# RWX-NOT: Name: .note.GNU-stack -# RWX-NOT: Type: PT_GNU_STACK +# RWX: Type: PT_GNU_STACK +# RWX-NEXT: Offset: 0x0 +# RWX-NEXT: VirtualAddress: 0x0 +# RWX-NEXT: PhysicalAddress: 0x0 +# RWX-NEXT: FileSize: 0 +# RWX-NEXT: MemSize: 0 +# RWX-NEXT: Flags [ +# RWX-NEXT: PF_R +# RWX-NEXT: PF_W +# RWX-NEXT: PF_X +# RWX-NEXT: ] +# RWX-NEXT: Alignment: 0 .globl _start _start: |