This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [trans-mem,darwin] PR/52042 find tm_clone_table with PIE
- From: Jack Howarth <howarth at bromo dot med dot uc dot edu>
- To: Patrick Marlier <patrick dot marlier at gmail dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Mike Stump <mrs at gcc dot gnu dot org>, Iain Sandoe <developer at sandoe-acoustics dot co dot uk>
- Date: Wed, 8 Feb 2012 00:12:49 -0500
- Subject: Re: [trans-mem,darwin] PR/52042 find tm_clone_table with PIE
- References: <4F31EDC9.2060600@gmail.com>
On Tue, Feb 07, 2012 at 10:36:41PM -0500, Patrick Marlier wrote:
> 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!
Done.
Native configuration is x86_64-apple-darwin11.3.0
=== libitm tests ===
Running target unix/-m32
FAIL: libitm.c++/eh-1.C execution test
=== libitm Summary for unix/-m32 ===
# of expected passes 25
# of unexpected failures 1
# of expected failures 3
# of unsupported tests 1
Running target unix/-m64
FAIL: libitm.c++/eh-1.C execution test
=== libitm Summary for unix/-m64 ===
# of expected passes 25
# of unexpected failures 1
# of expected failures 3
# of unsupported tests 1
=== libitm Summary ===
# of expected passes 50
# of unexpected failures 2
# of expected failures 6
# of unsupported tests 2
Compiler version: gcc libitm
Platform: x86_64-apple-darwin11.3.0
configure flags: --prefix=/sw --prefix=/sw/lib/gcc4.7 --mandir=/sw/share/man --infodir=/sw/lib/gcc4.7/info --with-build-config=bootstrap-lto --enable-stage1-languages=c,lto --enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.7 --enable-checking=release --enable-cloog-backend=isl
I believe the remaining libitm.c++/eh-1.C execution test failures are due to
the weakref linker bug currently in Xcode 4.x (radr://10466868) which I hae been
told will be fixed in the next Xcode release after Xcode 4.3.
Jack
>
> 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