]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: add .note.GNU-stack section for external linking
authorShenghou Ma <minux.ma@gmail.com>
Fri, 3 May 2013 08:33:21 +0000 (16:33 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Fri, 3 May 2013 08:33:21 +0000 (16:33 +0800)
Fixes #5392.

R=iant, r
CC=golang-dev
https://golang.org/cl/9119043

src/cmd/ld/elf.c
src/pkg/runtime/cgo/gcc_386.S
src/pkg/runtime/cgo/gcc_amd64.S
src/pkg/runtime/cgo/gcc_arm.S

index 0d1b712ce8cb1db34d9dacb8800625adb3f0de6d..daef5793ffd2f8bdd9162497d0e3f1094cbf9fdc 100644 (file)
@@ -930,6 +930,8 @@ doelf(void)
                        addstring(shstrtab, ".rel.noptrdata");
                        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']) {
@@ -1403,8 +1405,13 @@ elfobj:
                        elfshreloc(sect);
                for(sect=segdata.sect; sect!=nil; sect=sect->next)
                        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']) {
                sh = elfshname(".symtab");
                sh->type = SHT_SYMTAB;
index 94ba5842f198d68f8c7887ff9019e604b9d2b28e..bf4142793c55a0110c36802be85100656cbf9b5a 100644 (file)
@@ -40,3 +40,6 @@ EXT(__stack_chk_fail_local):
 1:
        jmp 1b
 
+#ifdef __ELF__
+.section .note.GNU-stack,"",@progbits
+#endif
index 81b270195d1fd0bf9231b49996b66adc3bc53b2c..32d0200cf7b39e564e28fd09d132fbf9f61bf55c 100644 (file)
@@ -42,3 +42,7 @@ EXT(crosscall_amd64):
        popq %rbp
        popq %rbx
        ret
+
+#ifdef __ELF__
+.section .note.GNU-stack,"",@progbits
+#endif
index 809fcb9a06ed75d48c55b35ba36589ed36a80ab1..3bc5bd338f8dd3bff3b1e13eb069a0a8a682a1e2 100644 (file)
@@ -34,3 +34,6 @@ EXT(__stack_chk_fail_local):
 1:
        b 1b
 
+#ifdef __ELF__
+.section .note.GNU-stack,"",@progbits
+#endif