Newlib _ctype_ alias kludge now invalid due to PR middle-end/15700 fix.

Jeff Johnston jjohnstn@redhat.com
Tue Mar 22 17:04:00 GMT 2005


Corinna Vinschen wrote:
> On Mar 22 11:53, Corinna Vinschen wrote:
> 
>>On Mar 21 17:06, Jeff Johnston wrote:
>>
>>>This is introducing machine-specific code into a shared file.  I would 
>>>rather see you add a new ctype_.c file in libc/machine/i386 which uses the 
>>>.asm method and avoids the array aliasing altogether.  That should solve 
>>>your problem and remove the need for Cygwin flag checks in the shared 
>>>ctype_.c file.
>>
>>Ok, I've prepared a patch along these lines.  The special handling for
>>Cygwin was useless anyway (no need for "__declspec(dllexport)"), so it's
>>just special handling for i386.
>>
>>Ok to apply?
> 
> 
> Actually, I don't want to apply that patch.  It's not right.
> 
> The assembler code is not really i386, it's target independent, because
> it only uses pseudo ops.  It's the one way to keep backward compatibility
> and it entirely drops the need for the array aliasing test in configure.
> Why giving up binary backward compatibility for all non-386 targets?
>

I realize the pseudo-ops are ok but I am worried about the names.  Correct me if 
I am wrong, but the compiler will not adjust the names you choose in the asm 
construct.  How do you intend to account for different platforms and their 
prepending characters (_ctype_ vs __ctype_ vs ?_ctype_)?  This is why I said it 
is machine-specific.

> So, is it really correct to move this stuff into machine/*?  I don't
> think so.  Below is an alternative patch, which is more correct, IMHO.
> 
> Using the assembler stuff for all targets should be ok, because
> ALLOW_NEGATIVE_CTYPE_INDEX requires __GNUC__ anyway.
> 
> 
> Corinna
> 
> 	* Makefile.in (libc_cv_array_aliasing): Remove.
> 	* configure.in: Remove array aliasing check.
> 	* newlib.hin (_HAVE_ARRAY_ALIASING): Remove.
> 	* libc/ctype/ctype_.c: Remove useless special Cygwin handling.
> 	Always define _ctype_ using assembler if ALLOW_NEGATIVE_CTYPE_INDEX
> 	is set.
> 
> Index: Makefile.in
> ===================================================================
> RCS file: /cvs/src/src/newlib/Makefile.in,v
> retrieving revision 1.37
> diff -u -p -r1.37 Makefile.in
> --- Makefile.in	17 Mar 2005 20:11:17 -0000	1.37
> +++ Makefile.in	22 Mar 2005 11:07:27 -0000
> @@ -103,7 +103,6 @@ SYS_OBJECTLIST = @SYS_OBJECTLIST@
>  UNIX_OBJECTLIST = @UNIX_OBJECTLIST@
>  VERSION = @VERSION@
>  aext = @aext@
> -libc_cv_array_aliasing = @libc_cv_array_aliasing@
>  libc_cv_initfinit_array = @libc_cv_initfinit_array@
>  libm_machine_dir = @libm_machine_dir@
>  machine_dir = @machine_dir@
> Index: configure.in
> ===================================================================
> RCS file: /cvs/src/src/newlib/configure.in,v
> retrieving revision 1.27
> diff -u -p -r1.27 configure.in
> --- configure.in	17 Mar 2005 20:11:17 -0000	1.27
> +++ configure.in	22 Mar 2005 11:07:27 -0000
> @@ -354,25 +354,6 @@ if test $libc_cv_initfinit_array = yes; 
>    AC_DEFINE_UNQUOTED(HAVE_INITFINI_ARRAY)
>  fi
>  
> -AC_CACHE_CHECK(for array aliasing support,
> -	       libc_cv_array_aliasing, [dnl
> -cat > conftest.c <<EOF
> -char x[3] = { 'a', 'b', 'c' };
> -extern char y[2] __attribute__((alias ("x+1")));
> -EOF
> -if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -c conftest.c
> -		   1>&AS_MESSAGE_LOG_FD])
> -then
> -  libc_cv_array_aliasing=yes
> -else
> -  libc_cv_array_aliasing=no
> -fi
> -rm -f conftest*])
> -AC_SUBST(libc_cv_array_aliasing)
> -if test $libc_cv_array_aliasing = yes; then
> -  AC_DEFINE_UNQUOTED(_HAVE_ARRAY_ALIASING)
> -fi
> -
>  AC_OUTPUT(Makefile,
>  [if test -n "$CONFIG_FILES"; then
>    unset ac_file
> Index: newlib.hin
> ===================================================================
> RCS file: /cvs/src/src/newlib/newlib.hin,v
> retrieving revision 1.9
> diff -u -p -r1.9 newlib.hin
> --- newlib.hin	17 Mar 2005 20:11:17 -0000	1.9
> +++ newlib.hin	22 Mar 2005 11:07:27 -0000
> @@ -141,8 +141,5 @@
>   * sections.  */
>  #undef  HAVE_INITFINI_ARRAY
>  
> -/* Define if the compiler supports aliasing an array to an address.  */
> -#undef  _HAVE_ARRAY_ALIASING
> -
>  #endif /* !__NEWLIB_H__ */
>  
> Index: libc/ctype/ctype_.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/ctype/ctype_.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 ctype_.c
> --- libc/ctype/ctype_.c	17 Mar 2005 20:11:22 -0000	1.4
> +++ libc/ctype/ctype_.c	22 Mar 2005 11:07:27 -0000
> @@ -84,44 +84,21 @@ static _CONST char _ctype_b[128 + 256] =
>  	_CTYPE_DATA_128_256
>  };
>  
> -#  if defined(__CYGWIN__)
> -_CONST char __declspec(dllexport) *__ctype_ptr = _ctype_b + 128;
> -#  else
> -_CONST char *__ctype_ptr = _ctype_b + 128;
> -#  endif
> -
> -#  if defined(_HAVE_ARRAY_ALIASING)
> -
> -#    if defined(__CYGWIN__)
> -extern _CONST char __declspec(dllexport) _ctype_[1 + 256] __attribute__ ((alias ("_ctype_b+127")));
> -#    else
> -extern _CONST char _ctype_[1 + 256] __attribute__ ((alias ("_ctype_b+127")));
> -#    endif
> +__asm__ (
> +   ".data \n\t"
> +   ".globl  __ctype_ \n\t"
> +   ".set    __ctype_,__ctype_b+127");
>  
> -#  else /* !_HAVE_ARRAY_ALIASING */
> -
> -#    if defined(__CYGWIN__)
> -_CONST char __declspec(dllexport) _ctype_[1 + 256] = {
> -#    else
> -_CONST char _ctype_[1 + 256] = {
> -#    endif
> -	0,
> -	_CTYPE_DATA_0_127,
> -	_CTYPE_DATA_128_256
> -};
> -#  endif /* !_HAVE_ARRAY_ALIASING */
> +_CONST char *__ctype_ptr = _ctype_b + 128;
>  
>  #else	/* !defined(ALLOW_NEGATIVE_CTYPE_INDEX) */
>  
> -# if defined(__CYGWIN__)
> -_CONST char __declspec(dllexport) _ctype_[1 + 256] = {
> -# else
>  _CONST char _ctype_[1 + 256] = {
> -# endif
>  	0,
>  	_CTYPE_DATA_0_127,
>  	_CTYPE_DATA_128_256
>  };
>  
>  _CONST char *__ctype_ptr = _ctype_ + 1;
> +
>  #endif
> 



More information about the Newlib mailing list