From 3f34248a7712e451b4217aa135e9236e93ece964 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 3 Aug 2012 15:27:35 -0400 Subject: [PATCH] cmd/ld: add PT_PAX_FLAGS ELF header PAX systems are Linux systems that are more paranoid about memory permissions. These flags tell them to relax when running Go binaries. Fixes #47. R=iant CC=golang-dev https://golang.org/cl/6326054 --- src/cmd/6l/asm.c | 5 +++++ src/cmd/8l/asm.c | 5 +++++ src/cmd/ld/elf.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/cmd/6l/asm.c b/src/cmd/6l/asm.c index 8d8c6d725c..a9901c7374 100644 --- a/src/cmd/6l/asm.c +++ b/src/cmd/6l/asm.c @@ -1082,6 +1082,11 @@ asmb(void) ph->type = PT_GNU_STACK; ph->flags = PF_W+PF_R; ph->align = 8; + + ph = newElfPhdr(); + ph->type = PT_PAX_FLAGS; + ph->flags = 0x2a00; // mprotect, randexec, emutramp disabled + ph->align = 8; sh = newElfShstrtab(elfstr[ElfStrShstrtab]); sh->type = SHT_STRTAB; diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c index 6c3a76e4d4..99c9b238b1 100644 --- a/src/cmd/8l/asm.c +++ b/src/cmd/8l/asm.c @@ -1127,6 +1127,11 @@ asmb(void) ph->flags = PF_W+PF_R; ph->align = 4; + ph = newElfPhdr(); + ph->type = PT_PAX_FLAGS; + ph->flags = 0x2a00; // mprotect, randexec, emutramp disabled + ph->align = 4; + sh = newElfShstrtab(elfstr[ElfStrShstrtab]); sh->type = SHT_STRTAB; sh->addralign = 1; diff --git a/src/cmd/ld/elf.h b/src/cmd/ld/elf.h index cfe1f9e53c..13c3d4da1f 100644 --- a/src/cmd/ld/elf.h +++ b/src/cmd/ld/elf.h @@ -251,6 +251,7 @@ typedef struct { #define PT_LOPROC 0x70000000 /* First processor-specific type. */ #define PT_HIPROC 0x7fffffff /* Last processor-specific type. */ #define PT_GNU_STACK 0x6474e551 +#define PT_PAX_FLAGS 0x65041580 /* Values for p_flags. */ #define PF_X 0x1 /* Executable. */