Tentative fix for libstdc++ failures on target overwritting libfunc names

Jan Hubicka hubicka@ucw.cz
Thu Sep 6 00:09:00 GMT 2007


> 
> Hi,
> the optabs patch introduced failures on some targets overwritting default libfuncs
> in combination with PCH.  THe problem is that optabs hashtable uses optab pointer
> to identify the table, but the pointer is not stable across PCH, since it resist in
> malloc pool and some OSes do randomizing of userspace addresses.
> 
> This patch should solve it, I've bootstrapped it on i686-linux and waiting for
> confirmation that it indeed fix the problem before comitting.

I've commited the patch today after Hans-Peter Nilsson cibfurned ut
fixes the problem.

Honza
> 
> 	* optabs.c (libfunc_entry): Change optab to integer.
> 	(hash_libfunc, convert_optab_libfunc, optab_libfunc,
> 	set_optab_libfunc, set_conv_libfunc): Use optable indexes instead
> 	of pointers for hashing.
> Index: optabs.c
> ===================================================================
> *** optabs.c	(revision 128102)
> --- optabs.c	(working copy)
> *************** void debug_optab_libfuncs (void);
> *** 123,129 ****
>      optab.  In the first case mode2 is unused.  */
>   struct libfunc_entry GTY(())
>   {
> !   void * GTY((skip)) optab;
>     enum machine_mode mode1, mode2;
>     rtx libfunc;
>   };
> --- 123,129 ----
>      optab.  In the first case mode2 is unused.  */
>   struct libfunc_entry GTY(())
>   {
> !   size_t optab;
>     enum machine_mode mode1, mode2;
>     rtx libfunc;
>   };
> *************** hash_libfunc (const void *p)
> *** 139,145 ****
>     const struct libfunc_entry *const e = (const struct libfunc_entry *) p;
>   
>     return (((int) e->mode1 + (int) e->mode2 * NUM_MACHINE_MODES)
> ! 	  ^ htab_hash_pointer (e->optab));
>   }
>   
>   /* Used for optab_hash.  */
> --- 139,145 ----
>     const struct libfunc_entry *const e = (const struct libfunc_entry *) p;
>   
>     return (((int) e->mode1 + (int) e->mode2 * NUM_MACHINE_MODES)
> ! 	  ^ e->optab);
>   }
>   
>   /* Used for optab_hash.  */
> *************** convert_optab_libfunc (convert_optab opt
> *** 165,171 ****
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
>   
> !   e.optab = optab;
>     e.mode1 = mode1;
>     e.mode2 = mode2;
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, NO_INSERT);
> --- 165,171 ----
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
>   
> !   e.optab = (size_t) (convert_optab_table[0] - optab);
>     e.mode1 = mode1;
>     e.mode2 = mode2;
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, NO_INSERT);
> *************** optab_libfunc (optab optab, enum machine
> *** 194,200 ****
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
>   
> !   e.optab = optab;
>     e.mode1 = mode;
>     e.mode2 = VOIDmode;
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, NO_INSERT);
> --- 194,200 ----
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
>   
> !   e.optab = (size_t) (optab_table[0] - optab);
>     e.mode1 = mode;
>     e.mode2 = VOIDmode;
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, NO_INSERT);
> *************** set_optab_libfunc (optab optable, enum m
> *** 5938,5944 ****
>     rtx val;
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
> !   e.optab = optable;
>     e.mode1 = mode;
>     e.mode2 = VOIDmode;
>   
> --- 5938,5944 ----
>     rtx val;
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
> !   e.optab = (size_t) (optab_table[0] - optable);
>     e.mode1 = mode;
>     e.mode2 = VOIDmode;
>   
> *************** set_optab_libfunc (optab optable, enum m
> *** 5949,5955 ****
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, INSERT);
>     if (*slot == NULL)
>       *slot = ggc_alloc (sizeof (struct libfunc_entry));
> !   (*slot)->optab = optable;
>     (*slot)->mode1 = mode;
>     (*slot)->mode2 = VOIDmode;
>     (*slot)->libfunc = val;
> --- 5949,5955 ----
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, INSERT);
>     if (*slot == NULL)
>       *slot = ggc_alloc (sizeof (struct libfunc_entry));
> !   (*slot)->optab = (size_t) (optab_table[0] - optable);
>     (*slot)->mode1 = mode;
>     (*slot)->mode2 = VOIDmode;
>     (*slot)->libfunc = val;
> *************** set_conv_libfunc (convert_optab optable,
> *** 5965,5971 ****
>     rtx val;
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
> !   e.optab = optable;
>     e.mode1 = tmode;
>     e.mode2 = fmode;
>   
> --- 5965,5971 ----
>     rtx val;
>     struct libfunc_entry e;
>     struct libfunc_entry **slot;
> !   e.optab = (size_t) (convert_optab_table[0] - optable);
>     e.mode1 = tmode;
>     e.mode2 = fmode;
>   
> *************** set_conv_libfunc (convert_optab optable,
> *** 5976,5982 ****
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, INSERT);
>     if (*slot == NULL)
>       *slot = ggc_alloc (sizeof (struct libfunc_entry));
> !   (*slot)->optab = optable;
>     (*slot)->mode1 = tmode;
>     (*slot)->mode2 = fmode;
>     (*slot)->libfunc = val;
> --- 5976,5982 ----
>     slot = (struct libfunc_entry **) htab_find_slot (libfunc_hash, &e, INSERT);
>     if (*slot == NULL)
>       *slot = ggc_alloc (sizeof (struct libfunc_entry));
> !   (*slot)->optab = (size_t) (convert_optab_table[0] - optable);
>     (*slot)->mode1 = tmode;
>     (*slot)->mode2 = fmode;
>     (*slot)->libfunc = val;



More information about the Gcc-patches mailing list