This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Add Android related compilation options and multilib options


This patch does three things:

1. Add -mandroid option to the compiler.
   (This part was originally written by Doug Kwan dougkwan@google.com
for gcc-4.3.1)
    With this option, users can easily compile programs for android.
    Suppose arm-eabi-gcc is built with android sysroot. Then we can use a simple
      command to compile a program:
    eg.  arm-eabi-gcc -mandroid hello.c -o hello

2. Add mandroid multilib option and armv7a multilib option.

3. Allow users to use --with-multilib-list option to enable building
non-default multilibs for a
    few arm targets.
    For example, if we want to build a toolchain for Android
(armv5te), we specify
      --target=arm-eabi  --with-multilib-list=mandroid,mthumb-interwork
    If we want to build a toolchain for Android (armv7-a), we specify
       --with-multilib-list=mandroid,mthumb-interwork,armv7a. So the
armv7-a runtime
       libraries will also be built.
    If we want to build a toolchain with newlib library, we specify
       --with-multilib-list=default  or --with-multilib-list=  or
don't give this option.

I have done the following tests:
1. Test -mandroid option and mandroid multilib.
  Built a arm toolchain with bionic C library for Android. Tested the
-mandroid option. Did gcc dejagnu tests on G1 phone.
2. Test armv7a multilib.
  Built the toolchain. The armv7a runtime libraries are built properly.
3. Test --with-multilib-list.
  Tried different combinations of non-default multilibs and wrong options.
4. General test.
  Built a arm toolchain with newlib. Did gcc dejagnu tests on GNU arm
emulator. There is no change before and after the patch.


2009-06-15  Jing Yu  <jingyu@google.com>

        * config/arm/eabi.h (ANDROID_CC1_SPEC): Add -Bdynamic in linker spec.
        Make "-fno-exceptions -fpic -fno-short-enums -mthumb-interwork"
        default C flags.
        * config/arm/eabi.opt: Allow -mno-android.
        * doc/invoke.texi: Document -mandroid.
        * config.gcc: Add with-multilib-list handling for the following arm
        targets that include config/arm/t-arm-elf:
        arm*-*-linux*, arm*-*-uclinux*, arm*-*-ecos-elf,
        arm*-*-eabi*, arm*-*-symbianelf*, arm*-*-rtems, arm*-*-elf.
        * config/arm/t-arm-elf: Add armv7-a multilib option. Add mandroid
        multilib option. Change how the mthumb-interwork multilib option
        is added.
        * config/arm/t-mlib-armv7a: New.
        * config/arm/t-mlib-mandroid: New.
        * config/arm/t-mlib-mthumb-interwork: New.


Any comment is welcome.

Thanks,

Jing
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 148507)
+++ doc/invoke.texi	(working copy)
@@ -458,7 +458,8 @@ Objective-C and Objective-C++ Dialects}.
 -mcaller-super-interworking  -mcallee-super-interworking @gol
 -mtp=@var{name} @gol
 -mword-relocations @gol
--mfix-cortex-m3-ldrd}
+-mfix-cortex-m3-ldrd @gol
+-mandroid}
 
 @emph{AVR Options}
 @gccoptlist{-mmcu=@var{mcu}  -msize  -minit-stack=@var{n}  -mno-interrupts @gol
@@ -9441,6 +9442,37 @@ This is enabled by default on targets (u
 loader imposes this restriction, and when @option{-fpic} or @option{-fPIC}
 is specified.
 
+@item -mandroid
+@opindex mandroid
+Enable Android specific compilier options.
+
+If this option is used, a preprocessor macro @code{__ANDROID__} is defined
+and has the value 1 during compilation. The option also implies C/C++ options
+@option{-fno-exceptions} @option{-fpic} @option{-mthumb-interwork}
+@option{-fno-short-enums} and C++ option @option{-fno-rtti}. These implied
+options can be overridden. For example RTTI in C++ code can still be enabled
+with -frtti even when -mandroid is also used.
+
+Linking options depend on whether a static executable, a dynamic
+executable or a shared library is built. When @option{-static} is given,
+@option{-mandroid} implies linking flag @option{-Bstatic}, start file
+@file{crtbegin_static.o} and end file @file{crtend_android.o}.
+
+When @option{-shared} is given, @option{-mandroid} implies the linking
+flag @option{-Bsymbolic} and no start and end files.
+
+When none of @option{-static} and @option{-shared} is given, @option{-mandroid}
+implies linking flags @option{-Bdynamic -dynamic-linker /system/bin/linker},
+start file @file{crtbegin_dynamic.o} and end file @file{crtend_android.o}. The
+dynamic linker used can be overriden by another @option{-dynamic-linker} in
+command line.
+
+The linking option @option{-ldl} is also added if @option{-static} is not
+given.
+
+If more than one of @option{-dynamic}, @option{-static} and @option{-shared}
+are given, behaviour of @option{-mandroid} is undefined.
+
 @end table
 
 @node AVR Options
Index: config.gcc
===================================================================
--- config.gcc	(revision 148507)
+++ config.gcc	(working copy)
@@ -703,88 +703,113 @@ arm*-*-netbsd*)
 	extra_parts=""
 	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"
-	case $target in
-	arm*b-*)
-		tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
-		;;
-	esac
-	tmake_file="${tmake_file} t-linux arm/t-arm"
-	case ${target} in
-	arm*-*-linux-*eabi)
-	    tm_file="$tm_file arm/bpabi.h arm/linux-eabi.h"
-	    tmake_file="$tmake_file arm/t-arm-elf arm/t-bpabi arm/t-linux-eabi"
-  	    # The BPABI long long divmod functions return a 128-bit value in
-	    # registers r0-r3.  Correctly modeling that requires the use of
-	    # TImode.
-	    need_64bit_hwint=yes
-	    # The EABI requires the use of __cxa_atexit.
-	    default_use_cxa_atexit=yes
-	    ;;
-	*)
-	    tmake_file="$tmake_file arm/t-linux"
-	    ;;
-	esac
-	tm_file="$tm_file arm/aout.h arm/arm.h"
-	tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
-	;;
-arm*-*-uclinux*)		# ARM ucLinux
-	tm_file="dbxelf.h elfos.h arm/unknown-elf.h arm/elf.h arm/linux-gas.h arm/uclinux-elf.h glibc-stdint.h"
-	tmake_file="arm/t-arm arm/t-arm-elf"
-	case ${target} in
-	arm*-*-uclinux*eabi)
-	    tm_file="$tm_file arm/bpabi.h arm/uclinux-eabi.h"
-	    tmake_file="$tmake_file arm/t-bpabi"
-  	    # The BPABI long long divmod functions return a 128-bit value in
-	    # registers r0-r3.  Correctly modeling that requires the use of
-	    # TImode.
-	    need_64bit_hwint=yes
-	    # The EABI requires the use of __cxa_atexit.
-	    default_use_cxa_atexit=yes
-	esac
-	tm_file="$tm_file arm/aout.h arm/arm.h"
-	tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
-	;;
-arm*-*-ecos-elf)
-	tm_file="dbxelf.h elfos.h newlib-stdint.h arm/unknown-elf.h arm/elf.h arm/aout.h arm/arm.h arm/ecos-elf.h"
-	tmake_file="arm/t-arm arm/t-arm-elf"
-	tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
-	;;
-arm*-*-eabi* | arm*-*-symbianelf* )
-	# The BPABI long long divmod functions return a 128-bit value in
-	# registers r0-r3.  Correctly modeling that requires the use of
-	# TImode.
-	need_64bit_hwint=yes
-	default_use_cxa_atexit=yes
-	tm_file="dbxelf.h elfos.h arm/unknown-elf.h arm/elf.h arm/bpabi.h"
-	tmake_file="arm/t-arm arm/t-arm-elf"
+arm*-*-linux* | arm*-*-uclinux* | arm*-*-ecos-elf | \
+arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems | arm*-*-elf)
+	# These targets share t-arm-elf.
+	arm_multilibs=${with_multilib_list}
+	arm_multilibs=`echo $arm_multilibs | sed -e 's/,/ /g' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ_ abcdefghijklmnopqrstuvwxyz-`
+	if test "$arm_multilibs" != "default"; then
+	    tmlib_file=""
+	    for arm_multilib in ${arm_multilibs}; do
+	        case ${arm_multilib} in
+		mthumb-interwork | mandroid | armv7a)
+			tmlib_file="${tmlib_file} arm/t-mlib-${arm_multilib}"
+			;;
+		\!*)
+			echo "with_multilib_list=${arm_multilib} is ignored."
+			;;
+		*)
+			echo "with_multilib_list=${arm_multilib} not supported."
+			exit 1
+			;;
+		esac
+	    done
+	fi
 	case ${target} in
-	arm*-*-eabi*)
-	  tm_file="$tm_file arm/eabi.h newlib-stdint.h"
-	  tmake_file="${tmake_file} arm/t-bpabi"
-	  extra_options="${extra_options} arm/eabi.opt"
-	  use_gcc_stdint=wrap
-	  ;;
-	arm*-*-symbianelf*)
-	  tm_file="${tm_file} arm/symbian.h"
-	  # We do not include t-bpabi for Symbian OS because the system
-	  # provides its own implementation of the BPABI functions.
-	  tmake_file="${tmake_file} arm/t-symbian"
-	  ;;
+	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"
+		case $target in
+		arm*b-*)
+			tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
+			;;
+		esac
+		tmake_file="${tmake_file} t-linux arm/t-arm"
+		case ${target} in
+		arm*-*-linux-*eabi)
+	    		tm_file="$tm_file arm/bpabi.h arm/linux-eabi.h"
+	    		tmake_file="$tmake_file ${tmlib_file} arm/t-arm-elf arm/t-bpabi arm/t-linux-eabi"
+  	    		# The BPABI long long divmod functions return a 128-bit value in
+	    		# registers r0-r3.  Correctly modeling that requires the use of
+	    		# TImode.
+	    		need_64bit_hwint=yes
+	    		# The EABI requires the use of __cxa_atexit.
+	    		default_use_cxa_atexit=yes
+	    		;;
+		*)
+	    		tmake_file="$tmake_file arm/t-linux"
+	    		;;
+		esac
+		tm_file="$tm_file arm/aout.h arm/arm.h"
+		tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
+		;;
+	arm*-*-uclinux*)		# ARM ucLinux
+		tm_file="dbxelf.h elfos.h arm/unknown-elf.h arm/elf.h arm/linux-gas.h arm/uclinux-elf.h glibc-stdint.h"
+		tmake_file="arm/t-arm ${tmlib_file} arm/t-arm-elf"
+		case ${target} in
+		arm*-*-uclinux*eabi)
+	    		tm_file="$tm_file arm/bpabi.h arm/uclinux-eabi.h"
+	    		tmake_file="$tmake_file arm/t-bpabi"
+  	    		# The BPABI long long divmod functions return a 128-bit value in
+	    		# registers r0-r3.  Correctly modeling that requires the use of
+	    		# TImode.
+	    		need_64bit_hwint=yes
+	    		# The EABI requires the use of __cxa_atexit.
+	    		default_use_cxa_atexit=yes
+		esac
+		tm_file="$tm_file arm/aout.h arm/arm.h"
+		tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
+		;;
+	arm*-*-ecos-elf)
+		tm_file="dbxelf.h elfos.h newlib-stdint.h arm/unknown-elf.h arm/elf.h arm/aout.h arm/arm.h arm/ecos-elf.h"
+		tmake_file="arm/t-arm ${tmlib_file} arm/t-arm-elf"
+		tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
+		;;
+	arm*-*-eabi* | arm*-*-symbianelf* )
+		# The BPABI long long divmod functions return a 128-bit value in
+		# registers r0-r3.  Correctly modeling that requires the use of
+		# TImode.
+		need_64bit_hwint=yes
+		default_use_cxa_atexit=yes
+		tm_file="dbxelf.h elfos.h arm/unknown-elf.h arm/elf.h arm/bpabi.h"
+		tmake_file="arm/t-arm ${tmlib_file} arm/t-arm-elf"
+		case ${target} in
+		arm*-*-eabi*)
+	  		tm_file="$tm_file arm/eabi.h newlib-stdint.h"
+	  		tmake_file="${tmake_file} arm/t-bpabi"
+	  		extra_options="${extra_options} arm/eabi.opt"
+	  		use_gcc_stdint=wrap
+	  		;;
+		arm*-*-symbianelf*)
+	  		tm_file="${tm_file} arm/symbian.h"
+	  		# We do not include t-bpabi for Symbian OS because the system
+	  		# provides its own implementation of the BPABI functions.
+	  		tmake_file="${tmake_file} arm/t-symbian"
+	  		;;
+		esac
+		tm_file="${tm_file} arm/aout.h arm/arm.h"
+		tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
+		;;
+	arm*-*-rtems*)
+		tm_file="dbxelf.h elfos.h arm/unknown-elf.h arm/elf.h arm/aout.h arm/arm.h arm/rtems-elf.h rtems.h newlib-stdint.h"
+		tmake_file="arm/t-arm ${tmlib_file} arm/t-arm-elf t-rtems arm/t-rtems"
+		tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
+		;;
+	arm*-*-elf)
+		tm_file="dbxelf.h elfos.h newlib-stdint.h arm/unknown-elf.h arm/elf.h arm/aout.h arm/arm.h"
+		tmake_file="arm/t-arm ${tmlib_file} arm/t-arm-elf"
+		tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
+		;;
 	esac
-	tm_file="${tm_file} arm/aout.h arm/arm.h"
-	tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
-	;;
-arm*-*-rtems*)
-	tm_file="dbxelf.h elfos.h arm/unknown-elf.h arm/elf.h arm/aout.h arm/arm.h arm/rtems-elf.h rtems.h newlib-stdint.h"
-	tmake_file="arm/t-arm arm/t-arm-elf t-rtems arm/t-rtems"
-	tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
-	;;
-arm*-*-elf)
-	tm_file="dbxelf.h elfos.h newlib-stdint.h arm/unknown-elf.h arm/elf.h arm/aout.h arm/arm.h"
-	tmake_file="arm/t-arm arm/t-arm-elf"
-	tmake_file="${tmake_file} arm/t-arm-softfp soft-fp/t-softfp"
 	;;
 arm*-wince-pe*)
 	tm_file="arm/semi.h arm/aout.h arm/arm.h arm/coff.h dbxcoff.h arm/pe.h arm/wince-pe.h"
Index: config/arm/eabi.h
===================================================================
--- config/arm/eabi.h	(revision 148507)
+++ config/arm/eabi.h	(working copy)
@@ -63,9 +63,14 @@
 "%{mandroid: %(link_android) ;" \
 "          : %(link_default)}"
 
-/* Android uses -fno-exceptions by default. */
+/* Android uses "-fno-exceptions -fpic -fno-short-enums -mthumb-interwork" by
+   default. */
 #undef ANDROID_CC1_SPEC
-#define ANDROID_CC1_SPEC "%{!fexceptions:-fno-exceptions}"
+#define ANDROID_CC1_SPEC \
+"%{!fexceptions:-fno-exceptions} " \
+"%{!fno-pic:%{!fno-PIC:-fpic}} " \
+"%{!fshort-enums:-fno-short-enums} " \
+"%{!mno-thumb-interwork:-mthumb-interwork}"
 
 /* Default CC1_SPEC as in arm.h. */
 #undef CC1_DEFAULT_SPEC
@@ -122,4 +127,3 @@
 #define ENDFILE_SPEC \
 "%{mandroid: %(endfile_android) ;" \
 "          : %(endfile_default)}"
-
Index: config/arm/t-mlib-mthumb-interwork
===================================================================
--- config/arm/t-mlib-mthumb-interwork	(revision 0)
+++ config/arm/t-mlib-mthumb-interwork	(revision 0)
@@ -0,0 +1,3 @@
+# Config mthumb-interwork multilib.
+MLOPT_mthumb_interwork	= mno-thumb-interwork/mthumb-interwork
+MLDIR_mthumb_interwork	= normal interwork
Index: config/arm/t-mlib-armv7a
===================================================================
--- config/arm/t-mlib-armv7a	(revision 0)
+++ config/arm/t-mlib-armv7a	(revision 0)
@@ -0,0 +1,4 @@
+# Config armv7-a multilib.
+MLOPT_armv7a		= march=armv7-a
+MLDIR_armv7a		= armv7a
+MLMATCH_armv7a		= march?armv7=march?armv7-a march?armv7=mcpu?cortex-a8
Index: config/arm/t-arm-elf
===================================================================
--- config/arm/t-arm-elf	(revision 148507)
+++ config/arm/t-arm-elf	(working copy)
@@ -47,6 +47,10 @@ MULTILIB_MATCHES     =
 #MULTILIB_MATCHES      += march?armv7=mcpu?cortex-r4
 #MULTILIB_MATCHES      += march?armv7=mcpu?cortex-m3
 
+MULTILIB_OPTIONS	+= $(MLOPT_armv7a)
+MULTILIB_DIRNAMES	+= $(MLDIR_armv7a)
+MULTILIB_MATCHES	+= $(MLMATCH_armv7a)
+
 # MULTILIB_OPTIONS    += mcpu=ep9312
 # MULTILIB_DIRNAMES   += ep9312
 # MULTILIB_EXCEPTIONS += *mthumb/*mcpu=ep9312*
@@ -58,10 +62,14 @@ MULTILIB_MATCHES     =
 # MULTILIB_OPTIONS    += mhard-float/msoft-float
 # MULTILIB_DIRNAMES   += fpu soft
 # MULTILIB_EXCEPTIONS += *mthumb/*mhard-float*
-# 
-# MULTILIB_OPTIONS    += mno-thumb-interwork/mthumb-interwork
-# MULTILIB_DIRNAMES   += normal interwork
-# 
+ 
+MULTILIB_OPTIONS	+= $(MLOPT_mthumb_interwork)
+MULTILIB_DIRNAMES	+= $(MLDIR_mthumb_interwork)
+
+MULTILIB_OPTIONS	+= $(MLOPT_mandroid)
+MULTILIB_DIRNAMES	+= $(MLDIR_mandroid)
+MULTILIB_EXCEPTIONS	+= $(MLEXCEPT_mandroid)
+
 # MULTILIB_OPTIONS    += fno-leading-underscore/fleading-underscore
 # MULTILIB_DIRNAMES   += elf under
 # 
Index: config/arm/t-mlib-mandroid
===================================================================
--- config/arm/t-mlib-mandroid	(revision 0)
+++ config/arm/t-mlib-mandroid	(revision 0)
@@ -0,0 +1,5 @@
+# Config mandroid multilib.
+# -mandroind implies -mthumb-interwork.
+MLOPT_mandroid		= mandroid
+MLDIR_mandroid		= android
+MLEXCEPT_mandroid	= *mthumb-interwork/*mandroid*
Index: config/arm/eabi.opt
===================================================================
--- config/arm/eabi.opt	(revision 148507)
+++ config/arm/eabi.opt	(working copy)
@@ -19,5 +19,5 @@
 ; <http://www.gnu.org/licenses/>.
 
 mandroid
-Target Report RejectNegative Mask(ANDROID)
+Target Report Mask(ANDROID)
 Generate code for the Android operating system.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]