forked from OSchip/llvm-project
ELF: Omit PT_GNU_STACK segment if -z execstack is provided.
In the previous patch (r254003), I made the linker emit PT_GNU_STACK unconditionally. But sometimes you want to have a control over the presence of the segment. With this patch, you can omit the segment by passing -z execstack option. llvm-svn: 254039
This commit is contained in:
parent
28b700373e
commit
a46566f2db
|
@ -933,12 +933,11 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {
|
||||||
|
|
||||||
// PT_GNU_STACK is a special section to tell the loader to make the
|
// PT_GNU_STACK is a special section to tell the loader to make the
|
||||||
// pages for the stack non-executable.
|
// pages for the stack non-executable.
|
||||||
Elf_Phdr *PH = &Phdrs[++PhdrIdx];
|
if (!Config->ZExecStack) {
|
||||||
PH->p_type = PT_GNU_STACK;
|
Elf_Phdr *PH = &Phdrs[++PhdrIdx];
|
||||||
if (Config->ZExecStack)
|
PH->p_type = PT_GNU_STACK;
|
||||||
PH->p_flags = PF_R | PF_W | PF_X;
|
|
||||||
else
|
|
||||||
PH->p_flags = PF_R | PF_W;
|
PH->p_flags = PF_R | PF_W;
|
||||||
|
}
|
||||||
|
|
||||||
// Fix up PT_INTERP as we now know the address of .interp section.
|
// Fix up PT_INTERP as we now know the address of .interp section.
|
||||||
if (Interp) {
|
if (Interp) {
|
||||||
|
@ -962,11 +961,13 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {
|
||||||
// Returns the number of PHDR entries.
|
// Returns the number of PHDR entries.
|
||||||
template <class ELFT> int Writer<ELFT>::getPhdrsNum() const {
|
template <class ELFT> int Writer<ELFT>::getPhdrsNum() const {
|
||||||
bool Tls = false;
|
bool Tls = false;
|
||||||
int I = 3; // 3 for PT_PHDR, first PT_LOAD and PT_GNU_STACK
|
int I = 2; // 2 for PT_PHDR and first PT_LOAD
|
||||||
if (needsInterpSection())
|
if (needsInterpSection())
|
||||||
++I;
|
++I;
|
||||||
if (isOutputDynamic())
|
if (isOutputDynamic())
|
||||||
++I;
|
++I;
|
||||||
|
if (!Config->ZExecStack)
|
||||||
|
++I;
|
||||||
uintX_t Last = PF_R;
|
uintX_t Last = PF_R;
|
||||||
for (OutputSectionBase<ELFT> *Sec : OutputSections) {
|
for (OutputSectionBase<ELFT> *Sec : OutputSections) {
|
||||||
if (!needsPhdr<ELFT>(Sec))
|
if (!needsPhdr<ELFT>(Sec))
|
||||||
|
|
|
@ -1,46 +1,30 @@
|
||||||
# REQUIRES: x86
|
# REQUIRES: x86
|
||||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
|
||||||
# RUN: ld.lld %t1 -z execstack -o %t
|
# RUN: ld.lld %t1 -z execstack -o %t
|
||||||
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=CHECK_RWX %s
|
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RWX %s
|
||||||
# RUN: ld.lld %t1 -o %t
|
# RUN: ld.lld %t1 -o %t
|
||||||
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=CHECK_RW %s
|
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RW %s
|
||||||
|
|
||||||
# CHECK_RW: Sections [
|
# RW: Sections [
|
||||||
# CHECK_RW-NOT: Name: .note.GNU-stack
|
# RW-NOT: Name: .note.GNU-stack
|
||||||
# CHECK_RW: ProgramHeaders [
|
# RW: ProgramHeaders [
|
||||||
# CHECK_RW: ProgramHeader {
|
# RW: ProgramHeader {
|
||||||
# CHECK_RW: Type: PT_GNU_STACK
|
# RW: Type: PT_GNU_STACK
|
||||||
# CHECK_RW-NEXT: Offset: 0x0
|
# RW-NEXT: Offset: 0x0
|
||||||
# CHECK_RW-NEXT: VirtualAddress: 0x0
|
# RW-NEXT: VirtualAddress: 0x0
|
||||||
# CHECK_RW-NEXT: PhysicalAddress: 0x0
|
# RW-NEXT: PhysicalAddress: 0x0
|
||||||
# CHECK_RW-NEXT: FileSize: 0
|
# RW-NEXT: FileSize: 0
|
||||||
# CHECK_RW-NEXT: MemSize: 0
|
# RW-NEXT: MemSize: 0
|
||||||
# CHECK_RW-NEXT: Flags [
|
# RW-NEXT: Flags [
|
||||||
# CHECK_RW-NEXT: PF_R
|
# RW-NEXT: PF_R
|
||||||
# CHECK_RW-NEXT: PF_W
|
# RW-NEXT: PF_W
|
||||||
# CHECK_RW-NEXT: ]
|
# RW-NEXT: ]
|
||||||
# CHECK_RW-NEXT: Alignment: 0
|
# RW-NEXT: Alignment: 0
|
||||||
# CHECK_RW-NEXT: }
|
# RW-NEXT: }
|
||||||
# CHECK_RW-NEXT: ]
|
# RW-NEXT: ]
|
||||||
|
|
||||||
# CHECK_RWX: Sections [
|
# RWX-NOT: Name: .note.GNU-stack
|
||||||
# CHECK_RWX-NOT: Name: .note.GNU-stack
|
# RWX-NOT: Type: PT_GNU_STACK
|
||||||
# CHECK_RWX: ProgramHeaders [
|
|
||||||
# CHECK_RWX: ProgramHeader {
|
|
||||||
# CHECK_RWX: Type: PT_GNU_STACK
|
|
||||||
# CHECK_RWX-NEXT: Offset: 0x0
|
|
||||||
# CHECK_RWX-NEXT: VirtualAddress: 0x0
|
|
||||||
# CHECK_RWX-NEXT: PhysicalAddress: 0x0
|
|
||||||
# CHECK_RWX-NEXT: FileSize: 0
|
|
||||||
# CHECK_RWX-NEXT: MemSize: 0
|
|
||||||
# CHECK_RWX-NEXT: Flags [
|
|
||||||
# CHECK_RWX-NEXT: PF_R
|
|
||||||
# CHECK_RWX-NEXT: PF_W
|
|
||||||
# CHECK_RWX-NEXT: PF_X
|
|
||||||
# CHECK_RWX-NEXT: ]
|
|
||||||
# CHECK_RWX-NEXT: Alignment: 0
|
|
||||||
# CHECK_RWX-NEXT: }
|
|
||||||
# CHECK_RWX-NEXT: ]
|
|
||||||
|
|
||||||
.globl _start
|
.globl _start
|
||||||
_start:
|
_start:
|
||||||
|
|
Loading…
Reference in New Issue