From 7bbf60e7d1d437a9b07a900c2e4b5e6a431020b1 Mon Sep 17 00:00:00 2001 From: Jing Yu Date: Thu, 29 Apr 2010 13:29:40 -0700 Subject: Add GNU-stack annotation to Android code. Change-Id: I3554e76370446fe42a2624114b9c8e1d8a3cec28 --- gcc-4.2.1/README.android | 19 +++++++++++++++++++ gcc-4.2.1/gcc/config/arm/arm.c | 4 ++++ gcc-4.2.1/gcc/config/arm/arm.h | 6 ++++++ gcc-4.2.1/gcc/config/arm/crti.asm | 5 +++++ gcc-4.2.1/gcc/config/arm/crtn.asm | 5 +++++ gcc-4.2.1/gcc/config/arm/eabi.h | 3 +++ gcc-4.2.1/gcc/config/arm/lib1funcs.asm | 7 +++++++ gcc-4.2.1/gcc/config/arm/libunwind.S | 6 ++++++ gcc-4.2.1/gcc/config/arm/linux-elf.h | 4 ++++ 9 files changed, 59 insertions(+) diff --git a/gcc-4.2.1/README.android b/gcc-4.2.1/README.android index 710653899..ebaa4d75f 100644 --- a/gcc-4.2.1/README.android +++ b/gcc-4.2.1/README.android @@ -2,6 +2,25 @@ This is a modified version of gcc-4.2.1 for Android. It is based on a Google customized gcc-4.2.1. The Google specific changes are documented in README.google. In addition, this gcc also contains the following changes. +2010-04-29 Jing Yu + + Add GNU-stack to generated code to enhance security. Port from + http://gcc.gnu.org/ml/gcc-patches/2006-11/msg00119.html + and also add a local patch which enforces eabi target to include + the GNU-stack annotation. + + Changed Files: + + gcc/config/arm/linux-elf.h + gcc/config/arm/arm.c + gcc/config/arm/arm.h + gcc/config/arm/lib1funcs.asm + gcc/config/arm/crti.asm + gcc/config/arm/crtn.asm + gcc/config/arm/libunwind.S + gcc/config/arm/eabi.h + + 2009-03-19 Doug Kwan Fix two bugs that caused different code to be generated on Linux diff --git a/gcc-4.2.1/gcc/config/arm/arm.c b/gcc-4.2.1/gcc/config/arm/arm.c index aee29b630..ec34cb208 100644 --- a/gcc-4.2.1/gcc/config/arm/arm.c +++ b/gcc-4.2.1/gcc/config/arm/arm.c @@ -14468,6 +14468,10 @@ arm_file_end (void) { int regno; + if (NEED_INDICATE_EXEC_STACK) + /* Add .note.GNU-stack. */ + file_end_indicate_exec_stack (); + if (! thumb_call_reg_needed) return; diff --git a/gcc-4.2.1/gcc/config/arm/arm.h b/gcc-4.2.1/gcc/config/arm/arm.h index 784142cfb..d4cb3d686 100644 --- a/gcc-4.2.1/gcc/config/arm/arm.h +++ b/gcc-4.2.1/gcc/config/arm/arm.h @@ -2595,4 +2595,10 @@ enum arm_builtins ARM_BUILTIN_MAX }; + +/* Do not emit .note.GNU-stack by default. */ +#ifndef NEED_INDICATE_EXEC_STACK +#define NEED_INDICATE_EXEC_STACK 0 +#endif + #endif /* ! GCC_ARM_H */ diff --git a/gcc-4.2.1/gcc/config/arm/crti.asm b/gcc-4.2.1/gcc/config/arm/crti.asm index 166a3ce34..abacdd1e3 100644 --- a/gcc-4.2.1/gcc/config/arm/crti.asm +++ b/gcc-4.2.1/gcc/config/arm/crti.asm @@ -30,6 +30,11 @@ # This exception does not however invalidate any other reasons why # the executable file might be covered by the GNU General Public License. # +/* An executable stack is *not* required for these functions. */ +#if defined(__ELF__) && defined(__linux__) +.section .note.GNU-stack,"",%progbits +.previous +#endif # This file just make a stack frame for the contents of the .fini and # .init sections. Users may put any desired instructions in those diff --git a/gcc-4.2.1/gcc/config/arm/crtn.asm b/gcc-4.2.1/gcc/config/arm/crtn.asm index 360afae97..84facb933 100644 --- a/gcc-4.2.1/gcc/config/arm/crtn.asm +++ b/gcc-4.2.1/gcc/config/arm/crtn.asm @@ -30,6 +30,11 @@ # This exception does not however invalidate any other reasons why # the executable file might be covered by the GNU General Public License. # +/* An executable stack is *not* required for these functions. */ +#if defined(__ELF__) && defined(__linux__) +.section .note.GNU-stack,"",%progbits +.previous +#endif # This file just makes sure that the .fini and .init sections do in # fact return. Users may put any desired instructions in those sections. diff --git a/gcc-4.2.1/gcc/config/arm/eabi.h b/gcc-4.2.1/gcc/config/arm/eabi.h index d69598c00..afe81556c 100644 --- a/gcc-4.2.1/gcc/config/arm/eabi.h +++ b/gcc-4.2.1/gcc/config/arm/eabi.h @@ -129,3 +129,6 @@ "%{mandroid: %(endfile_android) ;" \ " : %(endfile_default)}" +/* Add .note.GNU-stack. */ +#undef NEED_INDICATE_EXEC_STACK +#define NEED_INDICATE_EXEC_STACK 1 diff --git a/gcc-4.2.1/gcc/config/arm/lib1funcs.asm b/gcc-4.2.1/gcc/config/arm/lib1funcs.asm index 2792b35e3..7e0831ade 100644 --- a/gcc-4.2.1/gcc/config/arm/lib1funcs.asm +++ b/gcc-4.2.1/gcc/config/arm/lib1funcs.asm @@ -27,6 +27,13 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* An executable stack is *not* required for these functions. */ +#if defined(__ELF__) && defined(__linux__) +.section .note.GNU-stack,"",%progbits +.previous +#endif + /* ------------------------------------------------------------------------ */ /* We need to know what prefix to add to function names. */ diff --git a/gcc-4.2.1/gcc/config/arm/libunwind.S b/gcc-4.2.1/gcc/config/arm/libunwind.S index 81e4236f6..47625e3c1 100644 --- a/gcc-4.2.1/gcc/config/arm/libunwind.S +++ b/gcc-4.2.1/gcc/config/arm/libunwind.S @@ -26,6 +26,12 @@ the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* An executable stack is *not* required for these functions. */ +#if defined(__ELF__) && defined(__linux__) +.section .note.GNU-stack,"",%progbits +.previous +#endif + #ifndef __symbian__ #include "lib1funcs.asm" diff --git a/gcc-4.2.1/gcc/config/arm/linux-elf.h b/gcc-4.2.1/gcc/config/arm/linux-elf.h index acb13cd01..a746cf541 100644 --- a/gcc-4.2.1/gcc/config/arm/linux-elf.h +++ b/gcc-4.2.1/gcc/config/arm/linux-elf.h @@ -104,3 +104,7 @@ /* The GNU/Linux profiler needs a frame pointer. */ #define SUBTARGET_FRAME_POINTER_REQUIRED current_function_profile + +/* Add .note.GNU-stack. */ +#undef NEED_INDICATE_EXEC_STACK +#define NEED_INDICATE_EXEC_STACK 1 -- cgit v1.2.3