[PATCH][Revised2] Add libgcc/config/t-emutls for darwin

Jack Howarth howarth@bromo.med.uc.edu
Sun Mar 28 17:09:00 GMT 2010


Revision with ChangeLog and comment corrections.

------------------------------------------------

This is a revision of my previous patch. In order
to avoid maintaining a list of all those targets
using emutls, I switched to a wrapper testing
if ${set_have_cc_tls} is not a null string in
which case the default of the case statement
can safely append "t-emutls" to tmake_file.

----------------------------------------------

While testing the patch to eliminate race conditions in
indirect value profiling...

http://gcc.gnu.org/ml/gcc-patches/2008-12/msg00892.html

as adjusted for current gcc trunk...

Index: gcc/tree-profile.c
===================================================================
--- gcc/tree-profile.c  (revision 157765)
+++ gcc/tree-profile.c  (working copy)
@@ -82,6 +82,7 @@
   TREE_PUBLIC (ic_void_ptr_var) = 0;
   DECL_ARTIFICIAL (ic_void_ptr_var) = 1;
   DECL_INITIAL (ic_void_ptr_var) = NULL;
+  DECL_TLS_MODEL (ic_void_ptr_var) = decl_default_tls_model (ic_void_ptr_var);
   varpool_finalize_decl (ic_void_ptr_var);
 
   gcov_type_ptr = build_pointer_type (get_gcov_type ());
@@ -93,6 +94,7 @@
   TREE_PUBLIC (ic_gcov_type_ptr_var) = 0;
   DECL_ARTIFICIAL (ic_gcov_type_ptr_var) = 1;
   DECL_INITIAL (ic_gcov_type_ptr_var) = NULL;
+  DECL_TLS_MODEL (ic_gcov_type_ptr_var) = decl_default_tls_model (ic_gcov_type_ptr_var);
   varpool_finalize_decl (ic_gcov_type_ptr_var);
 }
 
I discovered that on darwin the profile testcases fail due to
unresolved emutls symbols despite their presence of the versioned
libgcc_ext. This is because the build of libgcc on darwin is only 
passed -DHAVE_CC_TLS but not -DUSE_TLS (appropriately since darwin
doesn't have assembler support for TLS but must use EMUTLS instead).
   The attached patch solves this problem by adding a new
libgcc/config/t-emutls file to pass -DUSE_EMUTLS and the appropriate
case statement in libgcc/config.host to add t-emults to tmake_file.
With this change the race condition patch produces no regressions in
the gcc testsuite. Bootstrapped and regression tested on 
x86_64-apple-darwin10. Okay for gcc trunk?
                    Jack
ps What other targets use emulated tls? They probably should be
added to the case statement. I should also note that on x86_64-apple-darwin10,
the test for threading used by configure in libgcc...

__thread int a; int b; int main() { return a = b; }

fails to compile with Apple's system gcc 4.2.1 compiler...

[MacPro:~] howarth% gcc thread_test.c
thread_test.c:1: error: thread-local storage not supported for this target

but does compile and run fine with current gcc trunk compiler (unpatched).


2010-03-28  Jack Howarth <howarth@bromo.med.uc.edu>

	* config.host (tmake_file): Check set_have_cc_tls for non-null
	and add case default for t-emutls.
	* t-emutls: New file.


Index: libgcc/config.host
===================================================================
--- libgcc/config.host	(revision 157783)
+++ libgcc/config.host	(working copy)
@@ -588,13 +588,18 @@
 	;;
 esac
 
+if test -n ${set_have_cc_tls} ; then
 case ${host} in
 i[34567]86-*-linux* | x86_64-*-linux* | \
   i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | \
   i[34567]86-*-gnu*)
 	tmake_file="${tmake_file} t-tls"
 	;;
+*)
+	tmake_file="${tmake_file} t-emutls"
+	;;
 esac
+fi
 
 case ${host} in
 i[34567]86-*-darwin* | x86_64-*-darwin* | \
Index: libgcc/config/t-emutls 
===================================================================
--- libgcc/config/t-emutls	(revision 0)
+++ libgcc/config/t-emutls	(revision 0)
@@ -0,0 +1,2 @@
+# Use emulated thread-local storage
+INTERNAL_CFLAGS += -DUSE_EMUTLS



More information about the Gcc-patches mailing list