arm-linux-androideabi: Use -fpic by default instead of -fPIC

Used to prevent a performance degradation compared to arm-eabi
when using the standalone toolchain. NDK toolchain not affected.

Change-Id: I4c603974fdc16dd6eb7be68dd0b72c4a98f25484
diff --git a/build/tools/toolchain-patches/gcc/0001-arm-linux-androideabi-make-fpic-the-default-instead-.patch b/build/tools/toolchain-patches/gcc/0001-arm-linux-androideabi-make-fpic-the-default-instead-.patch
new file mode 100644
index 0000000..1c6dce3
--- /dev/null
+++ b/build/tools/toolchain-patches/gcc/0001-arm-linux-androideabi-make-fpic-the-default-instead-.patch
@@ -0,0 +1,36 @@
+From 8fb36c2f3114aec33c84a43eb5fd14c845f65bfc Mon Sep 17 00:00:00 2001
+From: David 'Digit' Turner <digit@android.com>
+Date: Sat, 8 Jan 2011 14:46:50 +0100
+Subject: [PATCH] arm-linux-androideabi: make -fpic the default, instead of -fPIC
+
+This patch modifies the arm-linux-androideabi configuration to use
+-fpic by default, instead of -fPIC.
+
+This should only affect users the standalone Android NDK toolchain,
+since both the Android platform and NDK build scripts will append
+the -fpic flag at compile time for all generated object files.
+
+Note that this doesn't change the arm-eabi configuration to avoid
+breaking stuff when building the kernel.
+
+Change-Id: Ib7f97a05bf1bb83778863f885628c1741896fb0a
+---
+ gcc-4.4.3/gcc/config/linux-android.h |    2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/gcc-4.4.3/gcc/config/linux-android.h b/gcc-4.4.3/gcc/config/linux-android.h
+index a43bab5..ae4b26f 100644
+--- a/gcc-4.4.3/gcc/config/linux-android.h
++++ b/gcc-4.4.3/gcc/config/linux-android.h
+@@ -37,7 +37,7 @@
+ 
+ #define ANDROID_CC1_SPEC						\
+   "%{!mglibc:%{!muclibc:%{!mbionic: -mbionic}}} "			\
+-  "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
++  "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fpic}}}}"
+ 
+ #define ANDROID_CC1PLUS_SPEC						\
+   "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} "		\
+-- 
+1.7.3.1
+
diff --git a/docs/CHANGES.html b/docs/CHANGES.html
index 62c6099..79ba224 100644
--- a/docs/CHANGES.html
+++ b/docs/CHANGES.html
@@ -70,6 +70,13 @@
 - &lt;asm/byteorder.&gt;: Replaced 'asm' with '__asm__' to allow compilation
   with -std=c99. See https://review.source.android.com/#change,20076
 
+- standalone toolchain: The -fpic flag is now the default for the
+  arm-linux-androideabi toolchain, instead of -fPIC. This avoids a performance
+  degradation when compared to the old android-eabi configuration.
+
+  This only affects users of the standalone toolchain. The NDK build script
+  always enforced -fpic implicitely.
+
 -------------------------------------------------------------------------------
 android-ndk-r5
 
diff --git a/tests/run-standalone-tests.sh b/tests/run-standalone-tests.sh
index b012959..f38c843 100755
--- a/tests/run-standalone-tests.sh
+++ b/tests/run-standalone-tests.sh
@@ -60,7 +60,7 @@
 
 install_toolchain android-9
 
-for CXXSRC in $PROGDIR/standalone/*/*.cpp; do
+for CXXSRC in $PROGDIR/standalone/*/*.cpp $PROGDIR/standalone/*/*.c; do
     compile_and_link_cxx $CXXSRC
 done
 
diff --git a/tests/standalone/test-fpic/test-fpic.c b/tests/standalone/test-fpic/test-fpic.c
new file mode 100644
index 0000000..dded543
--- /dev/null
+++ b/tests/standalone/test-fpic/test-fpic.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* This test is used to check that -fpic is a default compiler option
+ * for the arm-linux-androideabi toolchain.
+ */
+#ifdef __arm__
+#ifndef __PIC__
+#error __PIC__ is not defined!
+#endif
+#if __PIC__ == 2
+#error -fPIC is the default, should be -fpic
+#endif
+#if __PIC__ != 1
+#error __PIC__ value is unsupported! Should be 1 to indicate -fpic is the default.
+#endif
+#endif
+
+int main(void)
+{
+    return 0;
+}