From 51b9db927f5dca75792b11cbc91266d6b842a6b2 Mon Sep 17 00:00:00 2001 From: Maxim Kuvyrkov Date: Thu, 27 May 2010 12:06:58 +0000 Subject: [PATCH] Support compilation for Android platform. Reimplement -mandroid. * config.gcc (*linux*): Include linux-android.h and linux-android.opt. (*android*): Set ANDROID_DEFAULT. (arm*-*-linux*): Include linux-android.h. (arm*-*-eabi*): Don't include previous -mandroid implementation. * config/arm/eabi.h: Remove, move Android-specific parts ... * config/linux-android.h: ... here. New file. * config/arm/eabi.opt: Rename to ... * config/linux-android.opt: ... this. (mandroid): Allow -mno-android option. Initialize based on ANDROID_DEFAULT. * config/linux.h (STARTFILE_SPEC, ENDFILE_SPEC, CC1_SPEC, LIB_SPEC): Move logic to corresponding LINUX_TARGET_* macros. (TARGET_OS_CPP_BUILTINS): Define __ANDROID__, when appropriate. * config/linux-eabi.h (LINK_SPEC, CC1_SPEC, CC1PLUS_SPEC, LIB_SPEC,) (STARTFILE_SPEC, ENDFILE_SPEC): Define to choose between Linux and Android definitions. (LINUX_TARGET_OS_CPP_BUILTINS): Define __ANDROID__ if TARGET_ANDROID. * doc/invoke.texi (-mandroid, -tno-android-cc, -tno-android-ld): Document. From-SVN: r159918 --- gcc/ChangeLog | 24 ++++ gcc/config.gcc | 21 ++- gcc/config/arm/eabi.h | 125 ------------------ gcc/config/arm/linux-eabi.h | 25 +++- gcc/config/linux-android.h | 54 ++++++++ .../{arm/eabi.opt => linux-android.opt} | 8 +- gcc/config/linux.h | 22 +-- gcc/doc/invoke.texi | 26 +++- 8 files changed, 163 insertions(+), 142 deletions(-) delete mode 100644 gcc/config/arm/eabi.h create mode 100644 gcc/config/linux-android.h rename gcc/config/{arm/eabi.opt => linux-android.opt} (74%) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4c4163e7e30..68fffda8e97 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,27 @@ +2010-05-27 Maxim Kuvyrkov + + Support compilation for Android platform. Reimplement -mandroid. + + * config.gcc (*linux*): Include linux-android.h and linux-android.opt. + (*android*): Set ANDROID_DEFAULT. + (arm*-*-linux*): Include linux-android.h. + (arm*-*-eabi*): Don't include previous -mandroid implementation. + * config/arm/eabi.h: Remove, move Android-specific parts ... + * config/linux-android.h: ... here. New file. + * config/arm/eabi.opt: Rename to ... + * config/linux-android.opt: ... this. + (mandroid): Allow -mno-android option. Initialize based on + ANDROID_DEFAULT. + * config/linux.h (STARTFILE_SPEC, ENDFILE_SPEC, CC1_SPEC, LIB_SPEC): + Move logic to corresponding LINUX_TARGET_* macros. + (TARGET_OS_CPP_BUILTINS): Define __ANDROID__, when appropriate. + * config/linux-eabi.h (LINK_SPEC, CC1_SPEC, CC1PLUS_SPEC, LIB_SPEC,) + (STARTFILE_SPEC, ENDFILE_SPEC): Define to choose between Linux and + Android definitions. + (LINUX_TARGET_OS_CPP_BUILTINS): Define __ANDROID__ if TARGET_ANDROID. + * doc/invoke.texi (-mandroid, -tno-android-cc, -tno-android-ld): + Document. + 2010-05-27 Maxim Kuvyrkov Add support for Bionic C library diff --git a/gcc/config.gcc b/gcc/config.gcc index d3fcaca39ca..022997a0a4c 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -534,6 +534,22 @@ case ${target} in default_use_cxa_atexit=yes use_gcc_tgmath=no use_gcc_stdint=wrap + # Add Android userspace support to Linux targets. + case $target in + *linux*) + tm_file="$tm_file linux-android.h" + extra_options="$extra_options linux-android.opt" + ;; + esac + # Enable compilation for Android by default for *android* targets. + case $target in + *-*-*android*) + tm_defines="$tm_defines ANDROID_DEFAULT=1" + ;; + *) + tm_defines="$tm_defines ANDROID_DEFAULT=0" + ;; + esac ;; *-*-netbsd*) tmake_file="t-slibgcc-elf-ver t-libc-ok t-netbsd t-libgcc-pic" @@ -717,7 +733,7 @@ arm*-*-netbsd*) use_collect2=yes ;; arm*-*-linux*) # ARM GNU/Linux with ELF - tm_file="dbxelf.h elfos.h linux.h glibc-stdint.h arm/elf.h arm/linux-gas.h arm/linux-elf.h" + tm_file="dbxelf.h elfos.h linux.h linux-android.h glibc-stdint.h arm/elf.h arm/linux-gas.h arm/linux-elf.h" case $target in arm*b-*) tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1" @@ -774,9 +790,8 @@ arm*-*-eabi* | arm*-*-symbianelf* ) tmake_file="arm/t-arm arm/t-arm-elf" case ${target} in arm*-*-eabi*) - tm_file="$tm_file arm/eabi.h newlib-stdint.h" + tm_file="$tm_file newlib-stdint.h" tmake_file="${tmake_file} arm/t-bpabi" - extra_options="${extra_options} arm/eabi.opt" use_gcc_stdint=wrap ;; arm*-*-symbianelf*) diff --git a/gcc/config/arm/eabi.h b/gcc/config/arm/eabi.h deleted file mode 100644 index c7d1d3ed20c..00000000000 --- a/gcc/config/arm/eabi.h +++ /dev/null @@ -1,125 +0,0 @@ -/* Configuration file for ARM EABI targets. - Copyright (C) 2008 - Free Software Foundation, Inc. - Contributed by Doug Kwan (dougkwan@google.com) - - This file is part of GCC. - - GCC is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GCC is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU General Public License - along with GCC; see the file COPYING3. If not see - . */ - -/* This file contains macro overrides for EABI targets. */ - -#undef TARGET_OS_CPP_BUILTINS -#define TARGET_OS_CPP_BUILTINS() \ - do \ - { \ - TARGET_BPABI_CPP_BUILTINS (); \ - if (TARGET_ANDROID) \ - builtin_define ("__ANDROID__"); \ - } \ - while (false) - -#undef SUBSUBTARGET_EXTRA_SPECS -#define SUBSUBTARGET_EXTRA_SPECS \ - { "link_android", ANDROID_LINK_SPEC }, \ - { "link_default", BPABI_LINK_SPEC }, \ - { "cc1_android", ANDROID_CC1_SPEC }, \ - { "cc1_default", CC1_DEFAULT_SPEC }, \ - { "cc1plus_android", ANDROID_CC1PLUS_SPEC }, \ - { "cc1plus_default", CC1PLUS_DEFAULT_SPEC }, \ - { "lib_android", ANDROID_LIB_SPEC }, \ - { "lib_default", LIB_DEFAULT_SPEC }, \ - { "startfile_android", ANDROID_STARTFILE_SPEC }, \ - { "startfile_default", UNKNOWN_ELF_STARTFILE_SPEC }, \ - { "endfile_android", ANDROID_ENDFILE_SPEC }, \ - { "endfile_default", UNKNOWN_ELF_ENDFILE_SPEC }, \ - -#undef ANDROID_LINK_SPEC -#define ANDROID_LINK_SPEC \ -"%{mbig-endian:-EB} %{mlittle-endian:-EL} " \ -"%{static:-Bstatic} %{shared:-shared} %{symbolic:-Bsymbolic} " \ -"%{!static:" \ - "%{shared: -Bsymbolic} " \ - "%{!shared:" \ - "%{rdynamic:-export-dynamic} " \ - "%{!dynamic-linker:-dynamic-linker /system/bin/linker}}} " \ -"-X" SUBTARGET_EXTRA_LINK_SPEC - -/* Override LINK_SPEC in bpabi.h. */ -#undef LINK_SPEC -#define LINK_SPEC \ -"%{mandroid: %(link_android) ;" \ -" : %(link_default)}" - -/* Android uses -fno-exceptions by default. */ -#undef ANDROID_CC1_SPEC -#define ANDROID_CC1_SPEC "%{!fexceptions:-fno-exceptions}" - -/* Default CC1_SPEC as in arm.h. */ -#undef CC1_DEFAULT_SPEC -#define CC1_DEFAULT_SPEC "" - -#undef CC1_SPEC -#define CC1_SPEC \ -"%{mandroid: %(cc1_android) ;" \ -" : %(cc1_default)}" - -/* Android uses -fno-rtti by default. */ -#undef ANDROID_CC1PLUS_SPEC -#define ANDROID_CC1PLUS_SPEC "%{!frtti:-fno-rtti}" - -/* Default CC1PLUS_SPEC as in gcc.c. */ -#undef CC1PLUS_DEFAULT_SPEC -#define CC1PLUS_DEFAULT_SPEC "" - -#undef CC1PLUS_SPEC -#define CC1PLUS_SPEC \ -"%{mandroid: %(cc1plus_android) ;" \ -" : %(cc1plus_default)}" - -#undef ANDROID_LIB_SPEC -#define ANDROID_LIB_SPEC "-lc %{!static:-ldl}" - -/* Default LIB_SPEC as in gcc.c. */ -#undef LIB_DEFAULT_SPEC -#define LIB_DEFAULT_SPEC \ -"%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" - -#undef LIB_SPEC -#define LIB_SPEC \ -"%{mandroid: %(lib_android) ;" \ -" : %(lib_default)}" - -#undef ANDROID_STARTFILE_SPEC -#define ANDROID_STARTFILE_SPEC \ -"%{!shared:" \ - "%{static: crtbegin_static%O%s ;" \ - " : crtbegin_dynamic%O%s}}" - -/* Override STARTFILE_SPEC in unknown-elf.h. */ -#undef STARTFILE_SPEC -#define STARTFILE_SPEC \ -"%{mandroid: %(startfile_android) ;" \ -" : %(startfile_default)}" - -#undef ANDROID_ENDFILE_SPEC -#define ANDROID_ENDFILE_SPEC "%{!shared:crtend_android%O%s}" - -/* Override ENDFILE_SPEC in unknown-elf.h. */ -#undef ENDFILE_SPEC -#define ENDFILE_SPEC \ -"%{mandroid: %(endfile_android) ;" \ -" : %(endfile_default)}" - diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h index fce1ed165d3..e69035e590d 100644 --- a/gcc/config/arm/linux-eabi.h +++ b/gcc/config/arm/linux-eabi.h @@ -66,7 +66,30 @@ /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to use the GNU/Linux version, not the generic BPABI version. */ #undef LINK_SPEC -#define LINK_SPEC LINUX_TARGET_LINK_SPEC BE8_LINK_SPEC +#define LINK_SPEC BE8_LINK_SPEC \ + LINUX_OR_ANDROID_LD (LINUX_TARGET_LINK_SPEC, \ + LINUX_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC) + +#undef CC1_SPEC +#define CC1_SPEC \ + LINUX_OR_ANDROID_CC (LINUX_TARGET_CC1_SPEC, \ + LINUX_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC) + +#define CC1PLUS_SPEC \ + LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC) + +#undef LIB_SPEC +#define LIB_SPEC \ + LINUX_OR_ANDROID_LD (LINUX_TARGET_LIB_SPEC, \ + LINUX_TARGET_LIB_SPEC " " ANDROID_LIB_SPEC) + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + LINUX_OR_ANDROID_LD (LINUX_TARGET_STARTFILE_SPEC, ANDROID_STARTFILE_SPEC) + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC \ + LINUX_OR_ANDROID_LD (LINUX_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC) /* Use the default LIBGCC_SPEC, not the version in linux-elf.h, as we do not use -lfloat. */ diff --git a/gcc/config/linux-android.h b/gcc/config/linux-android.h new file mode 100644 index 00000000000..a43bab5b035 --- /dev/null +++ b/gcc/config/linux-android.h @@ -0,0 +1,54 @@ +/* Configuration file for Linux Android targets. + Copyright (C) 2008, 2010 + Free Software Foundation, Inc. + Contributed by Doug Kwan (dougkwan@google.com) + Rewritten by CodeSourcery, Inc. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ + +#if ANDROID_DEFAULT +# define NOANDROID "mno-android" +#else +# define NOANDROID "!mandroid" +#endif + +#define LINUX_OR_ANDROID_CC(LINUX_SPEC, ANDROID_SPEC) \ + "%{" NOANDROID "|tno-android-cc:" LINUX_SPEC ";:" ANDROID_SPEC "}" + +#define LINUX_OR_ANDROID_LD(LINUX_SPEC, ANDROID_SPEC) \ + "%{" NOANDROID "|tno-android-ld:" LINUX_SPEC ";:" ANDROID_SPEC "}" + +#define ANDROID_LINK_SPEC \ + "%{shared: -Bsymbolic}" + +#define ANDROID_CC1_SPEC \ + "%{!mglibc:%{!muclibc:%{!mbionic: -mbionic}}} " \ + "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}" + +#define ANDROID_CC1PLUS_SPEC \ + "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} " \ + "%{!frtti:%{!fno-rtti: -fno-rtti}}" + +#define ANDROID_LIB_SPEC \ + "%{!static: -ldl}" + +#define ANDROID_STARTFILE_SPEC \ + "%{!shared:" \ + " %{static: crtbegin_static%O%s;: crtbegin_dynamic%O%s}}" + +#define ANDROID_ENDFILE_SPEC \ + "%{!shared: crtend_android%O%s}" diff --git a/gcc/config/arm/eabi.opt b/gcc/config/linux-android.opt similarity index 74% rename from gcc/config/arm/eabi.opt rename to gcc/config/linux-android.opt index 2cda98d56d1..ad659caf0d1 100644 --- a/gcc/config/arm/eabi.opt +++ b/gcc/config/linux-android.opt @@ -1,6 +1,6 @@ -; EABI specific options for ARM port of the compiler. +; Android specific options. -; Copyright (C) 2008 Free Software Foundation, Inc. +; Copyright (C) 2008, 2010 Free Software Foundation, Inc. ; ; This file is part of GCC. ; @@ -19,5 +19,5 @@ ; . mandroid -Target Report RejectNegative Mask(ANDROID) -Generate code for the Android operating system. +Target Report Mask(ANDROID) Var(flag_android) Init(ANDROID_DEFAULT ? OPTION_MASK_ANDROID : 0) +Generate code for the Android platform. diff --git a/gcc/config/linux.h b/gcc/config/linux.h index f86cc7bbaea..241e65668f0 100644 --- a/gcc/config/linux.h +++ b/gcc/config/linux.h @@ -42,16 +42,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see provides part of the support for getting C++ file-scope static object constructed before entering `main'. */ -#undef STARTFILE_SPEC #if defined HAVE_LD_PIE -#define STARTFILE_SPEC \ +#define LINUX_TARGET_STARTFILE_SPEC \ "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \ crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" #else -#define STARTFILE_SPEC \ +#define LINUX_TARGET_STARTFILE_SPEC \ "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \ crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" #endif +#undef STARTFILE_SPEC +#define STARTFILE_SPEC LINUX_TARGET_STARTFILE_SPEC /* Provide a ENDFILE_SPEC appropriate for GNU/Linux. Here we tack on the GNU/Linux magical crtend.o file (see crtstuff.c) which @@ -59,24 +60,27 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see object constructed before entering `main', followed by a normal GNU/Linux "finalizer" file, `crtn.o'. */ -#undef ENDFILE_SPEC -#define ENDFILE_SPEC \ +#define LINUX_TARGET_ENDFILE_SPEC \ "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" +#undef ENDFILE_SPEC +#define ENDFILE_SPEC LINUX_TARGET_ENDFILE_SPEC /* This is for -profile to use -lc_p instead of -lc. */ +#define LINUX_TARGET_CC1_SPEC "%{profile:-p}" #ifndef CC1_SPEC -#define CC1_SPEC "%{profile:-p}" +#define CC1_SPEC LINUX_TARGET_CC1_SPEC #endif /* The GNU C++ standard library requires that these macros be defined. */ #undef CPLUSPLUS_CPP_SPEC #define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)" -#undef LIB_SPEC -#define LIB_SPEC \ +#define LINUX_TARGET_LIB_SPEC \ "%{pthread:-lpthread} \ %{shared:-lc} \ %{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}" +#undef LIB_SPEC +#define LIB_SPEC LINUX_TARGET_LIB_SPEC /* C libraries supported on Linux. */ #define OPTION_GLIBC (linux_libc == LIBC_GLIBC) @@ -92,6 +96,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see builtin_assert ("system=linux"); \ builtin_assert ("system=unix"); \ builtin_assert ("system=posix"); \ + if (OPTION_ANDROID) \ + builtin_define ("__ANDROID__"); \ } while (0) #if defined(HAVE_LD_EH_FRAME_HDR) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 20fa3477210..baa8e88f348 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -559,7 +559,8 @@ Objective-C and Objective-C++ Dialects}. -mcpu=@var{cpu}} @emph{GNU/Linux Options} -@gccoptlist{-muclibc} +@gccoptlist{-mglibc -muclibc -mbionic -mandroid @gol +-tno-android-cc -tno-android-ld} @emph{H8/300 Options} @gccoptlist{-mrelax -mh -ms -mn -mint32 -malign-300} @@ -11489,6 +11490,29 @@ Use uClibc C library. This is the default on @opindex mbionic Use Bionic C library. This is the default on @samp{*-*-linux-*android*} targets. + +@item -mandroid +@opindex mandroid +Compile code compatible with Android platform. This is the default on +@samp{*-*-linux-*android*} targets. + +When compiling, this option enables @option{-mbionic}, @option{-fPIC}, +@option{-fno-exceptions} and @option{-fno-rtti} by default. When linking, +this option makes the GCC driver pass Android-specific options to the linker. +Finally, this option causes the preprocessor macro @code{__ANDROID__} +to be defined. + +@item -tno-android-cc +@opindex tno-android-cc +Disable compilation effects of @option{-mandroid}, i.e., do not enable +@option{-mbionic}, @option{-fPIC}, @option{-fno-exceptions} and +@option{-fno-rtti} by default. + +@item -tno-android-ld +@opindex tno-android-ld +Disable linking effects of @option{-mandroid}, i.e., pass standard Linux +linking options to the linker. + @end table @node H8/300 Options -- 2.30.2