diff mbox

fix include files to support non-GNU compilers

Message ID alpine.LRH.2.02.1409011849480.311@file01.intranet.prod.int.rdu2.redhat.com
State New
Headers show

Commit Message

Mikulas Patocka Sept. 1, 2014, 11:20 p.m. UTC
On Mon, 1 Sep 2014, Joseph S. Myers wrote:

> On Sun, 31 Aug 2014, Mikulas Patocka wrote:
> 
> > @@ -40,6 +42,8 @@
> >  
> >  #ifdef __WCHAR_MIN__
> >  # define __WCHAR_MIN	__WCHAR_MIN__
> > +#elif defined(__DECC)
> > +# define __WCHAR_MAX	(-__WCHAR_MAX - 1)
> 
> That seems wrong (defining __WCHAR_MAX in the section of code that should 
> be defining __WCHAR_MIN).
> 
> For the __align issue, you should use __glibc_align, as per the 
> __glibc_block precedent.

OK. Here I'm sending version 3 of the patch.




stdio.h: egcs doesn't respond to _VA_LIST_DEFINED. We only use this code
path on reasonably new gcc.

limits.h: __LONG_LONG_MAX__ is not defined by egcs. So we can't use it in
the definition of LLONG_MAX.

math.h: __REDIRECT_NTH is not defined on non-GNU compilers. In this case,
we don't declare long double redirection and instead declare a dummy
"struct __empty__declaration__" (we must declare something because C
doesn't allow stray semicolon in the program).

alpha-linux-gnu/sys/cdefs.h: for non-GNU compilers, we must define empty
__LDBL_REDIR1_DECL

alpha-linux-gnu/bits/wchar-ldbl.h: remove spurious semicolons. The
semicolon already exists at the end of __LDBL_REDIR_DECL and
__LDBL_REDIR1_DECL definition.

alpha-linux-gnu/bits/wchar.h: DEC C doesn't handle L'\0' in preprocessor
expression.

alpha-linux-gnu/bits/pthreadtypes.h:
alpha-linux-gnu/bits/semaphore.h:
netinet/in.h: __align is a keyword for the DEC C compiler. Use
__glibc_align instead.

---
 bits/wchar.h                                      |    4 +++
 include/limits.h                                  |    6 +++-
 inet/netinet/in.h                                 |    2 -
 libio/stdio.h                                     |    3 +-
 math/math.h                                       |    7 ++++-
 misc/sys/cdefs.h                                  |    1 
 sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h |   18 +++++++-------
 sysdeps/unix/sysv/linux/alpha/bits/semaphore.h    |    2 -
 wcsmbs/bits/wchar-ldbl.h                          |   28 +++++++++++-----------
 9 files changed, 43 insertions(+), 28 deletions(-)

Comments

Mike Frysinger March 7, 2015, 9:01 p.m. UTC | #1
On 01 Sep 2014 19:20, Mikulas Patocka wrote:
> OK. Here I'm sending version 3 of the patch.

please add proper ChangeLog entries for each file update

> --- glibc.orig/libio/stdio.h
> +++ glibc/libio/stdio.h
>
> +# if defined __GNUC__ && __GNUC__ >= 3

you need to use __GNUC_PREREQ (3, 0)


> --- glibc.orig/include/limits.h
> +++ glibc/include/limits.h
>
> -#  define LLONG_MAX	__LONG_LONG_MAX__
> +#  ifdef __LONG_LONG_MAX__
> +#   define LLONG_MAX	__LONG_LONG_MAX__
> +#  else
> +#   define LLONG_MAX	9223372036854775807LL
> +#  endif

OK

> --- glibc.orig/math/math.h
> +++ glibc/math/math.h
>
>  #   undef __MATHDECL_1
> -#   define __MATHDECL_2(type, function,suffix, args, alias) \
> +#   ifdef __REDIRECT_NTH
> +#    define __MATHDECL_2(type, function,suffix, args, alias) \
>    extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
>  			     args, alias)
> +#   else
> +#    define __MATHDECL_2(type, function,suffix, args, alias) \
> +		struct __empty__declaration__
> +#   endif
>  #   define __MATHDECL_1(type, function,suffix, args) \
>    __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))

i don't think this is correct.  i think you need to bracket the whole thing by 
an ifdef __REDIRECT_NTH check.  Joseph would know best here though.

> --- glibc.orig/misc/sys/cdefs.h
> +++ glibc/misc/sys/cdefs.h
>
>  # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
>  # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
>  # define __LDBL_REDIR_DECL(name)
> +# define __LDBL_REDIR1_DECL(name, alias)
>  # ifdef __REDIRECT
>  #  define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
>  #  define __REDIRECT_NTH_LDBL(name, proto, alias) \

OK (looks obvious)

> --- glibc.orig/wcsmbs/bits/wchar-ldbl.h
> +++ glibc/wcsmbs/bits/wchar-ldbl.h

dropping trailing semicolons here looks like an obvious fix

> --- glibc.orig/bits/wchar.h
> +++ glibc/bits/wchar.h
>
>  #ifdef __WCHAR_MAX__
>  # define __WCHAR_MAX	__WCHAR_MAX__
> +#elif defined __DECC
> +# define __WCHAR_MAX	0x7fffffff
>  #elif L'\0' - 1 > 0
>  # define __WCHAR_MAX	(0xffffffffu + L'\0')

the issue is that L'\0' doesn't work on your compiler ?  should we have some 
standards based check here instead of using __DECC ?


> --- glibc.orig/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
> +++ glibc/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
> --- glibc.orig/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h
> +++ glibc/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h
> --- glibc.orig/inet/netinet/in.h
> +++ glibc/inet/netinet/in.h

looks fine to rename __align to __glibc_align
-mike
Joseph Myers March 9, 2015, 3:54 p.m. UTC | #2
On Sat, 7 Mar 2015, Mike Frysinger wrote:

> > --- glibc.orig/math/math.h
> > +++ glibc/math/math.h
> >
> >  #   undef __MATHDECL_1
> > -#   define __MATHDECL_2(type, function,suffix, args, alias) \
> > +#   ifdef __REDIRECT_NTH
> > +#    define __MATHDECL_2(type, function,suffix, args, alias) \
> >    extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
> >  			     args, alias)
> > +#   else
> > +#    define __MATHDECL_2(type, function,suffix, args, alias) \
> > +		struct __empty__declaration__
> > +#   endif
> >  #   define __MATHDECL_1(type, function,suffix, args) \
> >    __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
> 
> i don't think this is correct.  i think you need to bracket the whole thing by 
> an ifdef __REDIRECT_NTH check.  Joseph would know best here though.

Indeed - the normal approach for such conditionals is to use #define when 
redirection isn't supported, but that's not possible in this case where 
the function declarations themselves come from macros.  So anyone with 
such a compiler that doesn't support redirection, and also has long double 
= double in a configuration where wider long double is the current default 
but -mlong-double-64 is also a supported configuration, will have to use 
libnldbl.a to get the versions of the long double functions, under their 
long double names, that are built for the -mlong-double-64 ABI and just 
wrap the double functions.  (I'm not sure libnldbl.a is documented 
anywhere, but that's my understanding of its intended use.)
Mikulas Patocka March 16, 2015, 4:50 p.m. UTC | #3
> > --- glibc.orig/math/math.h
> > +++ glibc/math/math.h
> >
> >  #   undef __MATHDECL_1
> > -#   define __MATHDECL_2(type, function,suffix, args, alias) \
> > +#   ifdef __REDIRECT_NTH
> > +#    define __MATHDECL_2(type, function,suffix, args, alias) \
> >    extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
> >  			     args, alias)
> > +#   else
> > +#    define __MATHDECL_2(type, function,suffix, args, alias) \
> > +		struct __empty__declaration__
> > +#   endif
> >  #   define __MATHDECL_1(type, function,suffix, args) \
> >    __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
> 
> i don't think this is correct.  i think you need to bracket the whole thing by 
> an ifdef __REDIRECT_NTH check.  Joseph would know best here though.

The problem here is that a stray semicolon at top level is invalid - it is 
accepted by gcc, but it is invalid by the C standard and not accepted by 
other compilers.

So if you do empty definition "#define define __MATHDECL_2(type, 
function,suffix, args, alias)" and then use it this way "__MATHDECL_1 
(int,__isinf,, (_Mdouble_ __value));", you get a stray semicolon and 
compiler failure. You need to declare something in the __MATHDECL_2 macro 
- so the patch declares an empty structure (prefixed by underscore, so it 
should not clash with user programs).

An alternate solution would be to drop the semicolons from the users of 
MATHDECL macro and move them to the MATHDECL macro itself, but it would 
make the patch bigger.

> > --- glibc.orig/bits/wchar.h
> > +++ glibc/bits/wchar.h
> >
> >  #ifdef __WCHAR_MAX__
> >  # define __WCHAR_MAX	__WCHAR_MAX__
> > +#elif defined __DECC
> > +# define __WCHAR_MAX	0x7fffffff
> >  #elif L'\0' - 1 > 0
> >  # define __WCHAR_MAX	(0xffffffffu + L'\0')
> 
> the issue is that L'\0' doesn't work on your compiler ?  should we have some 
> standards based check here instead of using __DECC ?

L'\0' is in the C89 standard - so it is a bug in the DEC C compiler that 
its preprocessor doesn't accept it.

Mikulas
Joseph Myers March 16, 2015, 11:53 p.m. UTC | #4
On Mon, 16 Mar 2015, Mikulas Patocka wrote:

> The problem here is that a stray semicolon at top level is invalid - it is 
> accepted by gcc, but it is invalid by the C standard and not accepted by 
> other compilers.
> 
> So if you do empty definition "#define define __MATHDECL_2(type, 
> function,suffix, args, alias)" and then use it this way "__MATHDECL_1 
> (int,__isinf,, (_Mdouble_ __value));", you get a stray semicolon and 
> compiler failure. You need to declare something in the __MATHDECL_2 macro 
> - so the patch declares an empty structure (prefixed by underscore, so it 
> should not clash with user programs).
> 
> An alternate solution would be to drop the semicolons from the users of 
> MATHDECL macro and move them to the MATHDECL macro itself, but it would 
> make the patch bigger.

I think you need to go a few steps back and write a self-contained 
explanation of what the various macros involved do and what you are trying 
to achieve, and the rationale for the approach you chose for the fix.

I'd say that if redirections aren't supported you should aim for the macro 
expansions for long double to look just like those for float and double 
(i.e. no redirections, just declaring each function with and without the 
__ prefix).  Is there some reason that is hard to achieve?
diff mbox

Patch

Index: glibc/libio/stdio.h
===================================================================
--- glibc.orig/libio/stdio.h
+++ glibc/libio/stdio.h
@@ -74,7 +74,7 @@  typedef struct _IO_FILE __FILE;
 #include <libio.h>
 
 #if defined __USE_XOPEN || defined __USE_XOPEN2K8
-# ifdef __GNUC__
+# if defined __GNUC__ && __GNUC__ >= 3
 #  ifndef _VA_LIST_DEFINED
 typedef _G_va_list va_list;
 #   define _VA_LIST_DEFINED
Index: glibc/include/limits.h
===================================================================
--- glibc.orig/include/limits.h
+++ glibc/include/limits.h
@@ -131,7 +131,11 @@ 
 #  define LLONG_MIN	(-LLONG_MAX-1)
 # endif
 # ifndef LLONG_MAX
-#  define LLONG_MAX	__LONG_LONG_MAX__
+#  ifdef __LONG_LONG_MAX__
+#   define LLONG_MAX	__LONG_LONG_MAX__
+#  else
+#   define LLONG_MAX	9223372036854775807LL
+#  endif
 # endif
 # ifndef ULLONG_MAX
 #  define ULLONG_MAX	(LLONG_MAX * 2ULL + 1)
Index: glibc/math/math.h
===================================================================
--- glibc.orig/math/math.h
+++ glibc/math/math.h
@@ -111,9 +111,14 @@  extern long double __REDIRECT_NTH (nextt
 #   endif
 
 #   undef __MATHDECL_1
-#   define __MATHDECL_2(type, function,suffix, args, alias) \
+#   ifdef __REDIRECT_NTH
+#    define __MATHDECL_2(type, function,suffix, args, alias) \
   extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
 			     args, alias)
+#   else
+#    define __MATHDECL_2(type, function,suffix, args, alias) \
+		struct __empty__declaration__
+#   endif
 #   define __MATHDECL_1(type, function,suffix, args) \
   __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
 #  endif
Index: glibc/misc/sys/cdefs.h
===================================================================
--- glibc.orig/misc/sys/cdefs.h
+++ glibc/misc/sys/cdefs.h
@@ -419,6 +419,7 @@ 
 # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
 # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
 # define __LDBL_REDIR_DECL(name)
+# define __LDBL_REDIR1_DECL(name, alias)
 # ifdef __REDIRECT
 #  define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
 #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
Index: glibc/wcsmbs/bits/wchar-ldbl.h
===================================================================
--- glibc.orig/wcsmbs/bits/wchar-ldbl.h
+++ glibc/wcsmbs/bits/wchar-ldbl.h
@@ -22,12 +22,12 @@ 
 
 #if defined __USE_ISOC95 || defined __USE_UNIX98
 __BEGIN_NAMESPACE_C99
-__LDBL_REDIR_DECL (fwprintf);
-__LDBL_REDIR_DECL (wprintf);
-__LDBL_REDIR_DECL (swprintf);
-__LDBL_REDIR_DECL (vfwprintf);
-__LDBL_REDIR_DECL (vwprintf);
-__LDBL_REDIR_DECL (vswprintf);
+__LDBL_REDIR_DECL (fwprintf)
+__LDBL_REDIR_DECL (wprintf)
+__LDBL_REDIR_DECL (swprintf)
+__LDBL_REDIR_DECL (vfwprintf)
+__LDBL_REDIR_DECL (vwprintf)
+__LDBL_REDIR_DECL (vswprintf)
 # if defined __USE_ISOC99 && !defined __USE_GNU \
      && !defined __REDIRECT \
      && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
@@ -35,31 +35,31 @@  __LDBL_REDIR1_DECL (fwscanf, __nldbl___i
 __LDBL_REDIR1_DECL (wscanf, __nldbl___isoc99_wscanf)
 __LDBL_REDIR1_DECL (swscanf, __nldbl___isoc99_swscanf)
 # else
-__LDBL_REDIR_DECL (fwscanf);
-__LDBL_REDIR_DECL (wscanf);
-__LDBL_REDIR_DECL (swscanf);
+__LDBL_REDIR_DECL (fwscanf)
+__LDBL_REDIR_DECL (wscanf)
+__LDBL_REDIR_DECL (swscanf)
 # endif
 __END_NAMESPACE_C99
 #endif
 
 #ifdef __USE_ISOC99
 __BEGIN_NAMESPACE_C99
-__LDBL_REDIR1_DECL (wcstold, wcstod);
+__LDBL_REDIR1_DECL (wcstold, wcstod)
 # if !defined __USE_GNU && !defined __REDIRECT \
      && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
 __LDBL_REDIR1_DECL (vfwscanf, __nldbl___isoc99_vfwscanf)
 __LDBL_REDIR1_DECL (vwscanf, __nldbl___isoc99_vwscanf)
 __LDBL_REDIR1_DECL (vswscanf, __nldbl___isoc99_vswscanf)
 # else
-__LDBL_REDIR_DECL (vfwscanf);
-__LDBL_REDIR_DECL (vwscanf);
-__LDBL_REDIR_DECL (vswscanf);
+__LDBL_REDIR_DECL (vfwscanf)
+__LDBL_REDIR_DECL (vwscanf)
+__LDBL_REDIR_DECL (vswscanf)
 # endif
 __END_NAMESPACE_C99
 #endif
 
 #ifdef __USE_GNU
-__LDBL_REDIR1_DECL (wcstold_l, wcstod_l);
+__LDBL_REDIR1_DECL (wcstold_l, wcstod_l)
 #endif
 
 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
Index: glibc/bits/wchar.h
===================================================================
--- glibc.orig/bits/wchar.h
+++ glibc/bits/wchar.h
@@ -32,6 +32,8 @@ 
 
 #ifdef __WCHAR_MAX__
 # define __WCHAR_MAX	__WCHAR_MAX__
+#elif defined __DECC
+# define __WCHAR_MAX	0x7fffffff
 #elif L'\0' - 1 > 0
 # define __WCHAR_MAX	(0xffffffffu + L'\0')
 #else
@@ -40,6 +42,8 @@ 
 
 #ifdef __WCHAR_MIN__
 # define __WCHAR_MIN	__WCHAR_MIN__
+#elif defined __DECC
+# define __WCHAR_MIN	(-__WCHAR_MAX - 1)
 #elif L'\0' - 1 > 0
 # define __WCHAR_MIN	(L'\0' + 0)
 #else
Index: glibc/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
===================================================================
--- glibc.orig/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
+++ glibc/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
@@ -38,7 +38,7 @@  typedef unsigned long int pthread_t;
 union pthread_attr_t
 {
   char __size[__SIZEOF_PTHREAD_ATTR_T];
-  long int __align;
+  long int __glibc_align;
 };
 #ifndef __have_pthread_attr_t
 typedef union pthread_attr_t pthread_attr_t;
@@ -70,7 +70,7 @@  typedef union
 #define __PTHREAD_MUTEX_HAVE_PREV	1
   } __data;
   char __size[__SIZEOF_PTHREAD_MUTEX_T];
-  long int __align;
+  long int __glibc_align;
 } pthread_mutex_t;
 
 /* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER.  */
@@ -79,7 +79,7 @@  typedef union
 typedef union
 {
   char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
-  int __align;
+  int __glibc_align;
 } pthread_mutexattr_t;
 
 
@@ -99,13 +99,13 @@  typedef union
     unsigned int __broadcast_seq;
   } __data;
   char __size[__SIZEOF_PTHREAD_COND_T];
-  __extension__ long long int __align;
+  __extension__ long long int __glibc_align;
 } pthread_cond_t;
 
 typedef union
 {
   char __size[__SIZEOF_PTHREAD_CONDATTR_T];
-  int __align;
+  int __glibc_align;
 } pthread_condattr_t;
 
 
@@ -139,7 +139,7 @@  typedef union
     unsigned int __flags;
   } __data;
   char __size[__SIZEOF_PTHREAD_RWLOCK_T];
-  long int __align;
+  long int __glibc_align;
 } pthread_rwlock_t;
 
 #define __PTHREAD_RWLOCK_ELISION_EXTRA 0
@@ -147,7 +147,7 @@  typedef union
 typedef union
 {
   char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
-  long int __align;
+  long int __glibc_align;
 } pthread_rwlockattr_t;
 #endif
 
@@ -161,13 +161,13 @@  typedef volatile int pthread_spinlock_t;
 typedef union
 {
   char __size[__SIZEOF_PTHREAD_BARRIER_T];
-  long int __align;
+  long int __glibc_align;
 } pthread_barrier_t;
 
 typedef union
 {
   char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
-  int __align;
+  int __glibc_align;
 } pthread_barrierattr_t;
 #endif
 
Index: glibc/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h
===================================================================
--- glibc.orig/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h
+++ glibc/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h
@@ -29,5 +29,5 @@ 
 typedef union
 {
   char __size[__SIZEOF_SEM_T];
-  long int __align;
+  long int __glibc_align;
 } sem_t;
Index: glibc/inet/netinet/in.h
===================================================================
--- glibc.orig/inet/netinet/in.h
+++ glibc/inet/netinet/in.h
@@ -567,8 +567,8 @@  extern int inet6_option_find (const stru
 /* Hop-by-Hop and Destination Options Processing (RFC 3542).  */
 extern int inet6_opt_init (void *__extbuf, socklen_t __extlen) __THROW;
 extern int inet6_opt_append (void *__extbuf, socklen_t __extlen, int __offset,
-			     uint8_t __type, socklen_t __len, uint8_t __align,
-			     void **__databufp) __THROW;
+			     uint8_t __type, socklen_t __len,
+			     uint8_t __glibc_align, void **__databufp) __THROW;
 extern int inet6_opt_finish (void *__extbuf, socklen_t __extlen, int __offset)
      __THROW;
 extern int inet6_opt_set_val (void *__databuf, int __offset, void *__val,