This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[trans-mem,darwin] PR/52042 find tm_clone_table with PIE


Hi,

The problem in this PR is that with PIE, getsectdata does not return the position of tm_clone_table after the relocation.
While _dyld_get_image_vmaddr_slide(0) is enough for PIE, this is not enough for dylib.
I did not find an easy API function to get position of the tm_clone_table for a shared library (dylib). So the only way I found is to get the mach_header address of the current dylib (via _dyld_get_image_header_containing_address), iterate over loaded binaries to find the current shared library and use _dyld_get_image_vmaddr_slide to find the position.
Any other proposal (my knowledge of darwin is really limited)?


Can someone do a bootstrap and test libitm on darwin (I have a limited access to a darwin machine, at least libitm tests pass)? Thanks!

If tests passed, ok for 4.7?
--
Patrick Marlier.
libgcc:

	PR libitm/52042
        * config/darwin-crt-tm.c: Changes for PIE and shared library.

Index: config/darwin-crt-tm.c
===================================================================
--- config/darwin-crt-tm.c	(revision 183968)
+++ config/darwin-crt-tm.c	(working copy)
@@ -26,8 +26,20 @@ see the files COPYING3 and COPYING.RUNTIME respect
 #include <mach-o/dyld.h>
 
 /* not listed in mach-o/dyld.h for some reason.  */
-extern char * getsectdata (const char*,const char*,unsigned long*); 
+extern char *getsectdatafromheader (struct mach_header*, const char*,
+				    const char*, unsigned long*);
+extern char *getsectdatafromheader_64 (struct mach_header_64*, const char*,
+				       const char*, unsigned long*);
 
+#ifdef __LP64__
+#define GET_DATA_TMCT(mh,size) \
+  getsectdatafromheader_64 ((struct mach_header_64*) mh, \
+			    "__DATA", "__tm_clone_table", size)
+#else
+#define GET_DATA_TMCT(mh,size) \
+  getsectdatafromheader (mh, "__DATA", "__tm_clone_table", size)
+#endif
+
 #define WEAK __attribute__((weak))
 
 extern void _ITM_registerTMCloneTable (void *, size_t) WEAK;
@@ -39,17 +51,27 @@ void __doTMRegistrations (void) __attribute__ ((co
 
 void __doTMRegistrations (void)
 {
-  char * tm_clone_table_sect_data;
+  struct mach_header *mh;
+  char *tmct_fixed, *tmct = NULL;
   unsigned long tmct_siz;
+  unsigned int i, img_count; 
   
-  tm_clone_table_sect_data = getsectdata ("__DATA",
-					  "__tm_clone_table",
-					  &tmct_siz);
+  mh = _dyld_get_image_header_containing_address (
+		(const void*)&__doTMRegistrations);
+  tmct_fixed = GET_DATA_TMCT (mh, &tmct_siz);
   tmct_siz /= (sizeof (size_t) * 2);
+
+  img_count = _dyld_image_count();
+  for (i = 0; i < img_count && tmct == NULL; i++)
+    {
+      if (mh == _dyld_get_image_header(i))
+	tmct = tmct_fixed + (unsigned long)_dyld_get_image_vmaddr_slide(i); 
+    }
+
   if (_ITM_registerTMCloneTable != NULL
-      && tm_clone_table_sect_data != NULL
+      && tmct != NULL
       && tmct_siz > 0)
-    _ITM_registerTMCloneTable (tm_clone_table_sect_data, (size_t)tmct_siz);
+    _ITM_registerTMCloneTable ((void *)tmct, (size_t)tmct_siz);
 }
 
 #endif
@@ -60,18 +82,27 @@ void __doTMdeRegistrations (void) __attribute__ ((
 
 void __doTMdeRegistrations (void)
 {
-  char * tm_clone_table_sect_data;
+  struct mach_header *mh;
+  char *tmct_fixed, *tmct = NULL;
   unsigned long tmct_siz;
+  unsigned int i, img_count; 
   
-  tm_clone_table_sect_data = getsectdata ("__DATA",
-					  "__tm_clone_table",
-					  &tmct_siz);
-  
+  mh = _dyld_get_image_header_containing_address (
+		(const void *)&__doTMdeRegistrations);
+  tmct_fixed = GET_DATA_TMCT (mh, &tmct_siz);
+  tmct_siz /= (sizeof (size_t) * 2);
+
+  img_count = _dyld_image_count();
+  for (i = 0; i < img_count && tmct == NULL; i++)
+    {
+      if (mh == _dyld_get_image_header(i))
+	tmct = tmct_fixed + (unsigned long)_dyld_get_image_vmaddr_slide(i); 
+    }
+
   if (_ITM_deregisterTMCloneTable != NULL
-      && tm_clone_table_sect_data != NULL
+      && tmct != NULL
       && tmct_siz > 0)
-    _ITM_deregisterTMCloneTable (tm_clone_table_sect_data);
-
+    _ITM_deregisterTMCloneTable ((void *)tmct);
 }
 
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]