[lld] r293849 - Make `-z stack-size` compatible with ld.bfd.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 17:12:46 PST 2017
Author: ruiu
Date: Wed Feb 1 19:12:45 2017
New Revision: 293849
URL: http://llvm.org/viewvc/llvm-project?rev=293849&view=rev
Log:
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.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/zstack-size.s
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=293849&r1=293848&r2=293849&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Feb 1 19:12:45 2017
@@ -575,7 +575,7 @@ void LinkerDriver::readConfigs(opt::Inpu
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);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=293849&r1=293848&r2=293849&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Feb 1 19:12:45 2017
@@ -1257,11 +1257,8 @@ template <class ELFT> std::vector<PhdrEn
// 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
Modified: lld/trunk/test/ELF/zstack-size.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/zstack-size.s?rev=293849&r1=293848&r2=293849&view=diff
==============================================================================
--- lld/trunk/test/ELF/zstack-size.s (original)
+++ lld/trunk/test/ELF/zstack-size.s Wed Feb 1 19:12:45 2017
@@ -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: ]
More information about the llvm-commits
mailing list