Make -z stack-size compatible with ld.bfd.

ld.bfd doesn't handle `-z stack-size=0` as a special case.
We shouldn't do that too.

llvm-svn: 293849
This commit is contained in:
Rui Ueyama 2017-02-02 01:12:45 +00:00
parent 8236b73dee
commit 9255b91a2b
3 changed files with 28 additions and 18 deletions

View File

@ -575,7 +575,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->ZNow = hasZOption(Args, "now");
Config->ZOrigin = hasZOption(Args, "origin");
Config->ZRelro = !hasZOption(Args, "norelro");
Config->ZStackSize = getZOptionValue(Args, "stack-size", -1);
Config->ZStackSize = getZOptionValue(Args, "stack-size", 0);
Config->ZWxneeded = hasZOption(Args, "wxneeded");
Config->OFormatBinary = isOutputFormatBinary(Args);

View File

@ -1257,11 +1257,8 @@ template <class ELFT> std::vector<PhdrEntry> Writer<ELFT>::createPhdrs() {
// PT_GNU_STACK is a special section to tell the loader to make the
// pages for the stack non-executable.
if (!Config->ZExecstack) {
PhdrEntry *Hdr = AddHdr(PT_GNU_STACK, PF_R | PF_W);
if (Config->ZStackSize != uint64_t(-1))
Hdr->p_memsz = Config->ZStackSize;
}
if (!Config->ZExecstack)
AddHdr(PT_GNU_STACK, PF_R | PF_W)->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

View File

@ -1,20 +1,33 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld -z stack-size=0x1000 %t -o %t1
# RUN: llvm-readobj -program-headers %t1 | FileCheck %s
# RUN: llvm-readobj -program-headers %t1 | FileCheck %s -check-prefix=CHECK1
# RUN: ld.lld -z stack-size=0 %t -o %t2
# RUN: llvm-readobj -program-headers %t2 | FileCheck %s -check-prefix=CHECK2
.global _start
_start:
nop
# CHECK: Type: PT_GNU_STACK (0x6474E551)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x0
# CHECK-NEXT: PhysicalAddress: 0x0
# CHECK-NEXT: FileSize: 0
# CHECK-NEXT: MemSize: 4096
# CHECK-NEXT: Flags [ (0x6)
# CHECK-NEXT: PF_R (0x4)
# CHECK-NEXT: PF_W (0x2)
# CHECK-NEXT: ]
# CHECK-NEXT: Alignment: 0
# CHECK1: Type: PT_GNU_STACK (0x6474E551)
# CHECK1-NEXT: Offset: 0x0
# CHECK1-NEXT: VirtualAddress: 0x0
# CHECK1-NEXT: PhysicalAddress: 0x0
# CHECK1-NEXT: FileSize: 0
# CHECK1-NEXT: MemSize: 4096
# CHECK1-NEXT: Flags [ (0x6)
# CHECK1-NEXT: PF_R (0x4)
# CHECK1-NEXT: PF_W (0x2)
# CHECK1-NEXT: ]
# CHECK2: Type: PT_GNU_STACK (0x6474E551)
# CHECK2-NEXT: Offset: 0x0
# CHECK2-NEXT: VirtualAddress: 0x0
# CHECK2-NEXT: PhysicalAddress: 0x0
# CHECK2-NEXT: FileSize: 0
# CHECK2-NEXT: MemSize: 0
# CHECK2-NEXT: Flags [ (0x6)
# CHECK2-NEXT: PF_R (0x4)
# CHECK2-NEXT: PF_W (0x2)
# CHECK2-NEXT: ]