diff mbox

[RFC,Darwin] provide the crt stuff for tm.

Message ID 576CABB2-597C-4C7B-BE4C-DF03B57E6DF7@sandoe-acoustics.co.uk
State New
Headers show

Commit Message

Iain Sandoe Nov. 20, 2011, 11:27 p.m. UTC
Since Darwin has its own crt infrastructure, we will still need to  
deal with this (even once the tm version is merged into gcc/crtstuff)...

with all the current patches for libitm/darwin [sjlj.S, weakrefs, tm  
clone table sect] + this one
  I get:

---

Native configuration is i686-apple-darwin9

                 === libitm tests ===

Schedule of variations:
     unix/-m32
     unix/-m64

Running target unix/-m32
Using /usr/local/dejagnu-git/share/dejagnu/baseboards/unix.exp as  
board description file for target.
Using /usr/local/dejagnu-git/share/dejagnu/config/unix.exp as generic  
interface file for target.
Using /GCC/gcc-live-trunk/libitm/testsuite/config/default.exp as tool- 
and-target-specific interface file.
Running /GCC/gcc-live-trunk/libitm/testsuite/libitm.c/c.exp ...
FAIL: libitm.c/memcpy-1.c execution test
FAIL: libitm.c/memset-1.c execution test
Running /GCC/gcc-live-trunk/libitm/testsuite/libitm.c++/c++.exp ...

                 === libitm Summary for unix/-m32 ===

# of expected passes            21
# of unexpected failures        2
# of expected failures          5
# of unresolved testcases       1
Running target unix/-m64
Using /usr/local/dejagnu-git/share/dejagnu/baseboards/unix.exp as  
board description file for target.
Using /usr/local/dejagnu-git/share/dejagnu/config/unix.exp as generic  
interface file for target.
Using /GCC/gcc-live-trunk/libitm/testsuite/config/default.exp as tool- 
and-target-specific interface file.
Running /GCC/gcc-live-trunk/libitm/testsuite/libitm.c/c.exp ...
Running /GCC/gcc-live-trunk/libitm/testsuite/libitm.c++/c++.exp ...

                 === libitm Summary for unix/-m64 ===

# of expected passes            23
# of expected failures          5
# of unresolved testcases       1

                 === libitm Summary ===

# of expected passes            44
# of unexpected failures        2
# of expected failures          10
# of unresolved testcases       2



comments/OK for trunk?
Iain

gcc:

	* config/darwin.h (ENDFILE_SPEC): New.
	(DARWIN_CRT1_SPEC): Add crttms.o.

libgcc:

	* config/darwin-crt-tm.c: New file.
	* config.host (darwin): Build crttms.o crttme.o to provide
	startup and shutdown for tm clones.
	* config/t-darwin (crttms.o): New build rule.
	(crttme.o): New build rule.

Comments

Richard Henderson Nov. 21, 2011, 12:12 a.m. UTC | #1
On 11/20/2011 01:27 PM, Iain Sandoe wrote:
> comments/OK for trunk?
> Iain
> 
> gcc:
> 
>     * config/darwin.h (ENDFILE_SPEC): New.
>     (DARWIN_CRT1_SPEC): Add crttms.o.
> 
> libgcc:
> 
>     * config/darwin-crt-tm.c: New file.
>     * config.host (darwin): Build crttms.o crttme.o to provide
>     startup and shutdown for tm clones.
>     * config/t-darwin (crttms.o): New build rule.
>     (crttme.o): New build rule.

Ok by me; Mike will want to look at the Darwin specifics.


r~
Iain Sandoe Nov. 21, 2011, 9:17 a.m. UTC | #2
Hi Richard, Mike,

On 21 Nov 2011, at 00:12, Richard Henderson wrote:

> On 11/20/2011 01:27 PM, Iain Sandoe wrote:
>> comments/OK for trunk?
>> Iain
>>
>> gcc:
>>
>>    * config/darwin.h (ENDFILE_SPEC): New.
>>    (DARWIN_CRT1_SPEC): Add crttms.o.
>>
>> libgcc:
>>
>>    * config/darwin-crt-tm.c: New file.
>>    * config.host (darwin): Build crttms.o crttme.o to provide
>>    startup and shutdown for tm clones.
>>    * config/t-darwin (crttms.o): New build rule.
>>    (crttme.o): New build rule.
>
> Ok by me; Mike will want to look at the Darwin specifics.

Actually, two questions have come to mind overnight;

1. should I be applying this constructor/destructor pair to shared  
libraries as well?
  (the specs need minor amendment)

2. Mike: I think to append "regular,no_dead_strip" to the section  
text, OK to that addition?

thanks
Iain
Richard Henderson Nov. 21, 2011, 6:54 p.m. UTC | #3
On 11/21/2011 01:17 AM, Iain Sandoe wrote:
> 1. should I be applying this constructor/destructor pair to shared libraries as well?
>  (the specs need minor amendment)

Yes.


r~
Mike Stump Nov. 21, 2011, 9:18 p.m. UTC | #4
On Nov 20, 2011, at 3:27 PM, Iain Sandoe <developer@sandoe-acoustics.co.uk> wrote:
> Since Darwin has its own crt infrastructure, we will still need to deal with this (even once the tm version is merged into gcc/crtstuff)...

> OK for trunk?

Ok.
Mike Stump Nov. 21, 2011, 9:21 p.m. UTC | #5
On Nov 21, 2011, at 1:17 AM, Iain Sandoe <developer@sandoe-acoustics.co.uk> wrote
> Actually, two questions have come to mind overnight;
> 
> 1. should I be applying this constructor/destructor pair to shared libraries as well?

I'll plead ignorance.

> 2. Mike: I think to append "regular,no_dead_strip" to the section text, OK to that addition?

Yes, sounds about right.  I think the ctors will come out anyway as no dead strip, can't hurt though if they do.
diff mbox

Patch

Index: libgcc/config/darwin-crt-tm.c
===================================================================
--- libgcc/config/darwin-crt-tm.c	(revision 0)
+++ libgcc/config/darwin-crt-tm.c	(revision 0)
@@ -0,0 +1,83 @@ 
+/* Provide the runtime intrastructure the transactional memory lib.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+   Contributed by Iain Sandoe <iains@gcc.gnu.org>
+
+   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/>.  */
+
+#include <mach-o/dyld.h>
+
+/* not listed in mach-o/dyld.h for some reason.  */
+extern char * getsectdata (const char*,const char*,unsigned long*); 
+
+#define WEAK __attribute__((weak))
+
+#ifndef ATTRIBUTE_UNUSED
+#define ATTRIBUTE_UNUSED __attribute__((unused))
+#endif
+
+extern void _ITM_registerTMCloneTable (void *, size_t) WEAK;
+extern void _ITM_deregisterTMCloneTable (void *) WEAK;
+
+#ifdef START
+
+void __doTMRegistrations (void) __attribute__ ((constructor));
+
+void __doTMRegistrations (void)
+{
+  char * tm_clone_table_sect_data;
+  unsigned long tmct_siz;
+  
+  tm_clone_table_sect_data = getsectdata ("__DATA",
+					  "__tm_clone_table",
+					  &tmct_siz);
+  tmct_siz /= (sizeof (size_t) * 2);
+  if (_ITM_registerTMCloneTable != NULL
+      && tm_clone_table_sect_data != NULL
+      && tmct_siz > 0)
+    _ITM_registerTMCloneTable (tm_clone_table_sect_data, (size_t)tmct_siz);
+}
+
+#endif
+
+#ifdef END
+
+void __doTMdeRegistrations (void) __attribute__ ((destructor));
+
+void __doTMdeRegistrations (void)
+{
+  char * tm_clone_table_sect_data;
+  unsigned long tmct_siz;
+  
+  tm_clone_table_sect_data = getsectdata ("__DATA",
+					  "__tm_clone_table",
+					  &tmct_siz);
+  
+  if (_ITM_deregisterTMCloneTable != NULL
+      && tm_clone_table_sect_data != NULL
+      && tmct_siz > 0)
+    _ITM_deregisterTMCloneTable (tm_clone_table_sect_data);
+
+}
+
+/* Provide dumy funcs for the weak ones - needed on most Darwin versions
+   for now.  */
+
+void _ITM_registerTMCloneTable (void *n ATTRIBUTE_UNUSED, size_t s ATTRIBUTE_UNUSED)
+{}
+void _ITM_deregisterTMCloneTable (void *n ATTRIBUTE_UNUSED)
+{}
+#endif
\ No newline at end of file
Index: libgcc/config.host
===================================================================
--- libgcc/config.host	(revision 181530)
+++ libgcc/config.host	(working copy)
@@ -170,7 +170,7 @@  case ${host} in
 *-*-darwin*)
   asm_hidden_op=.private_extern
   tmake_file="$tmake_file t-darwin ${cpu_type}/t-darwin t-libgcc-pic t-slibgcc-darwin"
-  extra_parts=crt3.o
+  extra_parts="crt3.o crttms.o crttme.o"
   ;;
 *-*-freebsd[12] | *-*-freebsd[12].* | *-*-freebsd*aout*)
   # This is the place-holder for the generic a.out configuration
Index: libgcc/config/t-darwin
===================================================================
--- libgcc/config/t-darwin	(revision 181530)
+++ libgcc/config/t-darwin	(working copy)
@@ -3,6 +3,12 @@  crt3.o: $(srcdir)/config/darwin-crt3.c
 	$(crt_compile) \
 	  -fno-tree-dominator-opts $(DARWIN_EXTRA_CRT_BUILD_CFLAGS) -c $<
 
+crttms.o: $(srcdir)/config/darwin-crt-tm.c
+	$(crt_compile) $(DARWIN_EXTRA_CRT_BUILD_CFLAGS) -DSTART -c $<
+
+crttme.o: $(srcdir)/config/darwin-crt-tm.c
+	$(crt_compile) $(DARWIN_EXTRA_CRT_BUILD_CFLAGS) -DEND -c $<
+
 # -pipe because there's an assembler bug, 4077127, which causes
 # it to not properly process the first # directive, causing temporary
 # file names to appear in stabs, causing the bootstrap to fail.  Using -pipe
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 181530)
+++ gcc/config/darwin.h	(working copy)
@@ -372,10 +372,8 @@  extern GTY(()) int darwin_ms_struct;
 					      %(darwin_crt2)}}}}}}	    \
   %{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}"
 
-/* The native Darwin linker doesn't necessarily place files in the order
-   that they're specified on the link line.  Thus, it is pointless
-   to put anything in ENDFILE_SPEC.  */
-/* #define ENDFILE_SPEC "" */
+/* We want a destructor last in the list.  */
+#define ENDFILE_SPEC "%{fgnu-tm: -lcrttme.o}"
 
 #define DARWIN_EXTRA_SPECS						\
   { "darwin_crt1", DARWIN_CRT1_SPEC },					\
@@ -388,7 +386,8 @@  extern GTY(()) int darwin_ms_struct;
 
 #define DARWIN_CRT1_SPEC						\
   "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o)		\
-   %:version-compare(>= 10.5 mmacosx-version-min= -lcrt1.10.5.o)"
+   %:version-compare(>= 10.5 mmacosx-version-min= -lcrt1.10.5.o)	\
+   %{fgnu-tm: -lcrttms.o}"
 
 /* Default Darwin ASM_SPEC, very simple.  */
 #define ASM_SPEC "-arch %(darwin_arch) \