Update driver and libgcc configuration for dynamic linking

This makes the GCC driver pass the right options to the linker
for dynamic linking with glibc.  It also updates the libgcc
configuration for NaCl as appropriate for the glibc build.  The
libgcc build is still affected by the --with-newlib configure
switch, because we need that configuration to build the bootstrap
libgcc used when building glibc.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3068
TEST= hand-tested toolchain update

Change-Id: I90f529677e709dd43a0ca4f5f39cc8a018c17241
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 313b9c8..d0963ae 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -745,6 +745,12 @@
 *-*-nacl*)
   gas=yes
   gnu_ld=yes
+  if test x$with_newlib != xyes; then
+    case ${enable_threads} in
+      "" | yes | posix) thread_file='posix' ;;
+    esac
+    tmake_file="t-slibgcc"
+  fi
   default_use_cxa_atexit=yes
   default_gnu_indirect_function=yes
   use_gcc_tgmath=no
diff --git a/gcc/config/arm/nacl.h b/gcc/config/arm/nacl.h
index a0d170b..4f10cda 100644
--- a/gcc/config/arm/nacl.h
+++ b/gcc/config/arm/nacl.h
@@ -1,5 +1,5 @@
 /* Definitions for ARM running Native Client
-   Copyright (C) 2012-2013 Free Software Foundation, Inc.
+   Copyright (C) 2012-2015 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
@@ -76,7 +76,7 @@
 #define GNU_USER_DYNAMIC_LINKER "/lib/ld-nacl-arm.so.1"
 
 #undef  LINK_SPEC
-#define LINK_SPEC EABI_LINK_SPEC LINUX_TARGET_LINK_SPEC
+#define LINK_SPEC EABI_LINK_SPEC NACL_LINK_SPEC
 
 #undef  CC1_SPEC
 #define CC1_SPEC GNU_USER_TARGET_CC1_SPEC
diff --git a/gcc/config/nacl.h b/gcc/config/nacl.h
index 16b2749..9bc8752 100644
--- a/gcc/config/nacl.h
+++ b/gcc/config/nacl.h
@@ -1,5 +1,5 @@
 /* Definitions for Native Client systems.
-   Copyright (C) 2013 Free Software Foundation, Inc.
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -73,14 +73,9 @@
 #define LONG_DOUBLE_TYPE_SIZE		DOUBLE_TYPE_SIZE
 #undef LIBGCC2_HAS_TF_MODE
 
-/* For now, -static is effectively the default.  But the driver
-   doesn't know that.  The gnu-user.h definition is:
-   "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
-
-   TODO(mcgrathr): When we have multilib for newlib (static-only) vs glibc
-   (dynamic by default, -static available), this will need to be defined so
-   that it uses the -static flavor for newlib and the gnu-user.h default
-   (i.e. switching on -static) for glibc.  */
-#undef LINK_GCC_C_SEQUENCE_SPEC
-#define LINK_GCC_C_SEQUENCE_SPEC \
-  "--start-group %G %L --end-group"
+/* For dynamic linking an ET_EXEC, we need to place the text segment
+   far enough above the normal 0x20000 default that there is enough
+   space for the untrusted ELF loader.  */
+#define NACL_LINK_SPEC \
+  "%{!static:%{!shared:%{!pie:-Ttext-segment=0x100000}}}" \
+  LINUX_TARGET_LINK_SPEC