From 6eee1fc68f366651379e776e4e3408069772562f Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Fri, 10 Aug 2012 14:00:17 -0700 Subject: [PATCH] crtend*: Add GNU_STACK note Add a GNU_STACK marker to crtend* files. This tells the linker that these files do not require an executable stack. When linking, a missing GNU_STACK marker in any .o file can prevent the compiler from automatically marking the final executable as NX safe (executable stack not required). In Android, we normally work around this by adding -Wa,--noexecstack / -Wl,-z,noexecstack. For files like crtend.S / crtend_so.S, which are included in every executable / shared library, it's better to add the GNU_STACK note directly to the assembly file. This allows the compiler to automatically mark the final executable as NX safe without any special command line options. References: http://www.gentoo.org/proj/en/hardened/gnu-stack.xml Change-Id: I07bd058f9f60ddd8b146e0fb36ba26ff84c0357d --- libc/arch-arm/bionic/crtend.S | 3 +++ libc/arch-arm/bionic/crtend_so.S | 3 +++ 2 files changed, 6 insertions(+) diff --git a/libc/arch-arm/bionic/crtend.S b/libc/arch-arm/bionic/crtend.S index 2f3b1ede3..7196fc10d 100644 --- a/libc/arch-arm/bionic/crtend.S +++ b/libc/arch-arm/bionic/crtend.S @@ -38,3 +38,6 @@ .section .ctors, "aw" .long 0 +#if defined(__linux__) && defined(__ELF__) + .section .note.GNU-stack,"",%progbits +#endif diff --git a/libc/arch-arm/bionic/crtend_so.S b/libc/arch-arm/bionic/crtend_so.S index a1281c402..0cb99478a 100644 --- a/libc/arch-arm/bionic/crtend_so.S +++ b/libc/arch-arm/bionic/crtend_so.S @@ -36,3 +36,6 @@ .section .fini_array, "aw" .long 0 +#if defined(__linux__) && defined(__ELF__) + .section .note.GNU-stack,"",%progbits +#endif