Add -mtls-use-call option to avoid %gs:0 TLS accesses.

Adds an option to the 32-bit code generator to match the 64-bit
variant's behavior of generating calls to __nacl_read_tp rather
than fetches from %gs:0 to begin TLS access sequences.

We'll want this for the builds of newlib and libstdc++ that go into
the integrated runtime.  They have their own uses of TLS, which must
be kept separate from the user-side libc's TLS setup.  We'll reserve
%gs for the user side.

BUG=http://code.google.com/p/nativeclient/issues/detail?id=1595

Review URL: http://codereview.chromium.org/6691046
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 5fdcfe3..a1db9d5 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1083,6 +1083,7 @@
 *-*-nacl*)
 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h svr4.h i386/nacl.h"
 	tmake_file="${tmake_file} i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules i386/t-nacl64"
+	extra_options="${extra_options} i386/nacl.opt"
 	;;
 i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
 			# Intel 80386's running GNU/*
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 7687ca0..01310a4 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -10112,7 +10112,7 @@
 {
   rtx tp, reg, insn;
 
-  if (TARGET_64BIT && TARGET_NACL)
+  if (TARGET_NACL && (TARGET_64BIT || TARGET_TLS_USE_CALL))
     {
       rtx rax = gen_rtx_REG (Pmode, AX_REG);
 
diff --git a/gcc/config/i386/nacl.opt b/gcc/config/i386/nacl.opt
new file mode 100644
index 0000000..2b91522
--- /dev/null
+++ b/gcc/config/i386/nacl.opt
@@ -0,0 +1,24 @@
+; i386-dependent options for NaCL.
+;
+; Copyright (C) 2011 Free Software Foundation, Inc.
+; Contributed by Google
+;
+; 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
+; <http://www.gnu.org/licenses/>.
+
+mtls-use-call
+Target Var(TARGET_TLS_USE_CALL) Init(0)
+Use a function call rather than direct segment register access for TLS