Commit e0db7fae authored by Shenghou Ma's avatar Shenghou Ma

cmd/ld: add .note.GNU-stack section for external linking

Fixes #5392.

R=iant, r
CC=golang-dev
https://golang.org/cl/9119043
parent 7cc0581f
...@@ -930,6 +930,8 @@ doelf(void) ...@@ -930,6 +930,8 @@ doelf(void)
addstring(shstrtab, ".rel.noptrdata"); addstring(shstrtab, ".rel.noptrdata");
addstring(shstrtab, ".rel.data"); addstring(shstrtab, ".rel.data");
} }
// add a .note.GNU-stack section to mark the stack as non-executable
addstring(shstrtab, ".note.GNU-stack");
} }
if(!debug['s']) { if(!debug['s']) {
...@@ -1403,8 +1405,13 @@ elfobj: ...@@ -1403,8 +1405,13 @@ elfobj:
elfshreloc(sect); elfshreloc(sect);
for(sect=segdata.sect; sect!=nil; sect=sect->next) for(sect=segdata.sect; sect!=nil; sect=sect->next)
elfshreloc(sect); elfshreloc(sect);
// add a .note.GNU-stack section to mark the stack as non-executable
sh = elfshname(".note.GNU-stack");
sh->type = SHT_PROGBITS;
sh->addralign = 1;
sh->flags = 0;
} }
if(!debug['s']) { if(!debug['s']) {
sh = elfshname(".symtab"); sh = elfshname(".symtab");
sh->type = SHT_SYMTAB; sh->type = SHT_SYMTAB;
......
...@@ -40,3 +40,6 @@ EXT(__stack_chk_fail_local): ...@@ -40,3 +40,6 @@ EXT(__stack_chk_fail_local):
1: 1:
jmp 1b jmp 1b
#ifdef __ELF__
.section .note.GNU-stack,"",@progbits
#endif
...@@ -42,3 +42,7 @@ EXT(crosscall_amd64): ...@@ -42,3 +42,7 @@ EXT(crosscall_amd64):
popq %rbp popq %rbp
popq %rbx popq %rbx
ret ret
#ifdef __ELF__
.section .note.GNU-stack,"",@progbits
#endif
...@@ -34,3 +34,6 @@ EXT(__stack_chk_fail_local): ...@@ -34,3 +34,6 @@ EXT(__stack_chk_fail_local):
1: 1:
b 1b b 1b
#ifdef __ELF__
.section .note.GNU-stack,"",@progbits
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment