Skip to content

Commit 3f34248

Browse files
committed
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
1 parent cf06750 commit 3f34248

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/cmd/6l/asm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,11 @@ asmb(void)
10821082
ph->type = PT_GNU_STACK;
10831083
ph->flags = PF_W+PF_R;
10841084
ph->align = 8;
1085+
1086+
ph = newElfPhdr();
1087+
ph->type = PT_PAX_FLAGS;
1088+
ph->flags = 0x2a00; // mprotect, randexec, emutramp disabled
1089+
ph->align = 8;
10851090

10861091
sh = newElfShstrtab(elfstr[ElfStrShstrtab]);
10871092
sh->type = SHT_STRTAB;

src/cmd/8l/asm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,11 @@ asmb(void)
11271127
ph->flags = PF_W+PF_R;
11281128
ph->align = 4;
11291129

1130+
ph = newElfPhdr();
1131+
ph->type = PT_PAX_FLAGS;
1132+
ph->flags = 0x2a00; // mprotect, randexec, emutramp disabled
1133+
ph->align = 4;
1134+
11301135
sh = newElfShstrtab(elfstr[ElfStrShstrtab]);
11311136
sh->type = SHT_STRTAB;
11321137
sh->addralign = 1;

src/cmd/ld/elf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ typedef struct {
251251
#define PT_LOPROC 0x70000000 /* First processor-specific type. */
252252
#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */
253253
#define PT_GNU_STACK 0x6474e551
254+
#define PT_PAX_FLAGS 0x65041580
254255

255256
/* Values for p_flags. */
256257
#define PF_X 0x1 /* Executable. */

0 commit comments

Comments
 (0)