BUG: string.h, (FC4 x86_64)

Hello, I think I've got a bug with c2hs 0.14.5. I have a program that compiles neatly on FC4 but fails when tried on x86_64 FC4. c2hs fails on string.h. Attached are the string.h of the system and relevant .i file. ----------- [aleator@thoth HopenCV]$ c2hs -k --cppopts='-I/usr/include/opencv' cvWrapLEO.h Image.chs c2hs: Error in C header file. /usr/include/string.h:270: (column 99) [FATAL]
Syntax error! The symbol `__attribute__' does not fit here.
-- The previous produces rather lot of output, but -- the following might be enough? [aleator@thoth HopenCV]$ c2hs -k string.h Image.chs c2hs: Error in C header file. /usr/include/string.h:270: (column 99) [FATAL]
Syntax error! The symbol `__attribute__' does not fit here.
[aleator@thoth HopenCV]$ uname -s -r Linux 2.6.16-1.2108_FC4smp [aleator@thoth HopenCV]$ /lib/libc.so.6 GNU C Library development release version 2.3.6, by Roland McGrath et al. Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 4.0.2 20051125 (Red Hat 4.0.2-8). Compiled on a Linux 2.4.20 system on 2006-03-14. Available extensions: GNU libio by Per Bothner crypt add-on version 2.1 by Michael Glad and others Native POSIX Threads Library by Ulrich Drepper et al The C stubs add-on version 2.1.2. BIND-8.2.3-T5B NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk Glibc-2.0 compatibility add-on by Cristian Gafton GNU Libidn by Simon Josefsson Thread-local storage support included. For bug reporting instructions, please see: http://www.gnu.org/software/libc/bugs.html. -- Ville Tirronen, University Of Jyväskylä # 1 "Image.h" # 1 "<built-in>" # 1 "<command line>" # 1 "Image.h" # 1 "/usr/include/string.h" 1 3 4 # 26 "/usr/include/string.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 319 "/usr/include/features.h" 3 4 # 1 "/usr/include/sys/cdefs.h" 1 3 4 # 320 "/usr/include/features.h" 2 3 4 # 342 "/usr/include/features.h" 3 4 # 1 "/usr/include/gnu/stubs.h" 1 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 5 "/usr/include/gnu/stubs.h" 2 3 4 # 1 "/usr/include/gnu/stubs-64.h" 1 3 4 # 10 "/usr/include/gnu/stubs.h" 2 3 4 # 343 "/usr/include/features.h" 2 3 4 # 27 "/usr/include/string.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.0.2/include/stddef.h" 1 3 4 # 214 "/usr/lib/gcc/x86_64-redhat-linux/4.0.2/include/stddef.h" 3 4 typedef long unsigned int size_t; # 34 "/usr/include/string.h" 2 3 4 extern void *memcpy (void *__restrict __dest, __const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memmove (void *__dest, __const void *__src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memccpy (void *__restrict __dest, __const void *__restrict __src, int __c, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memset (void *__s, int __c, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int memcmp (__const void *__s1, __const void *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memchr (__const void *__s, int __c, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 82 "/usr/include/string.h" 3 4 extern char *strcpy (char *__restrict __dest, __const char *__restrict __src) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strncpy (char *__restrict __dest, __const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strcat (char *__restrict __dest, __const char *__restrict __src) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strncat (char *__restrict __dest, __const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcmp (__const char *__s1, __const char *__s2) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncmp (__const char *__s1, __const char *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcoll (__const char *__s1, __const char *__s2) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strxfrm (char *__restrict __dest, __const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); # 130 "/usr/include/string.h" 3 4 extern char *strdup (__const char *__s) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); # 165 "/usr/include/string.h" 3 4 extern char *strchr (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strrchr (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 181 "/usr/include/string.h" 3 4 extern size_t strcspn (__const char *__s, __const char *__reject) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strspn (__const char *__s, __const char *__accept) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strpbrk (__const char *__s, __const char *__accept) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strstr (__const char *__haystack, __const char *__needle) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strtok (char *__restrict __s, __const char *__restrict __delim) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern char *__strtok_r (char *__restrict __s, __const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 3))); extern char *strtok_r (char *__restrict __s, __const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 3))); # 240 "/usr/include/string.h" 3 4 extern size_t strlen (__const char *__s) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 254 "/usr/include/string.h" 3 4 extern char *strerror (int __errnum) __attribute__ ((__nothrow__)); # 270 "/usr/include/string.h" 3 4 extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); # 288 "/usr/include/string.h" 3 4 extern void __bzero (void *__s, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void bcopy (__const void *__src, void *__dest, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void bzero (void *__s, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int bcmp (__const void *__s1, __const void *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *index (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *rindex (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern int ffs (int __i) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); # 325 "/usr/include/string.h" 3 4 extern int strcasecmp (__const char *__s1, __const char *__s2) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncasecmp (__const char *__s1, __const char *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 348 "/usr/include/string.h" 3 4 extern char *strsep (char **__restrict __stringp, __const char *__restrict __delim) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); # 426 "/usr/include/string.h" 3 4 # 1 "Image.h" 2

On Tue, 2006-05-23 at 09:00 +0300, Ville Tirronen wrote:
Hello, I think I've got a bug with c2hs 0.14.5. I have a program that compiles neatly on FC4 but fails when tried on x86_64 FC4.
c2hs fails on string.h. Attached are the string.h of the system and relevant .i file.
-----------
[aleator@thoth HopenCV]$ c2hs -k --cppopts='-I/usr/include/opencv' cvWrapLEO.h Image.chs c2hs: Error in C header file.
/usr/include/string.h:270: (column 99) [FATAL]
Syntax error! The symbol `__attribute__' does not fit here.
So the bug here is in parsing this bit: extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); In particular the current c2hs C parser only allows __asm__ decorations after __attribute__ decorations, not mixed as in this example. The reason it happened on one machine and not another might be to do with this __REDIRECT_NTH define: # ifdef __REDIRECT_NTH extern int __REDIRECT_NTH (strerror_r, (int __errnum, char *__buf, size_t __buflen), __xpg_strerror_r) __nonnull ((2)); # else extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen) __THROW __nonnull ((2)); # define strerror_r __xpg_strerror_r # endif Presumably on FC4 x86_64 it defines __REDIRECT_NTH and so gets the extra asm bit. We should try and find some clearer spec on the GNU C grammar. I was working from a yacc parser in gcc 3.3.x when I added some support for the __asm__ annotations. Duncan

Duncan Coutts:
On Tue, 2006-05-23 at 09:00 +0300, Ville Tirronen wrote: So the bug here is in parsing this bit:
extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
In particular the current c2hs C parser only allows __asm__ decorations after __attribute__ decorations, not mixed as in this example. [..] We should try and find some clearer spec on the GNU C grammar. I was working from a yacc parser in gcc 3.3.x when I added some support for the __asm__ annotations.
In the meantime, as a stop gap measure, we can use the C pre-processor to get rid of the pesky __asm__ and __attribute__ annotations by passing the following additional arguments to the pre-processor: -D__asm__(A)= -D__attribute__(A)= (Don't forget quotes if using from a shell.) c2hs can be instructed to pass extra options to the C pre-processor using the --cppopts=CPPOPTS command line option. Manuel

to get rid of the pesky __asm__ and __attribute__ annotations by passing the following additional arguments to the pre-processor: -D__asm__(A)= -D__attribute__(A)=
Most obliged. However, this leads me to: -- [thoth]$ c2hs --cppopts='-I/usr/include/opencv -D"__asm__(A)= " -D"__attribute__(A)= "' cvWrapLEO.h Image.chs c2hs: Error in C header file. /usr/lib/gcc/x86_64-redhat-linux/4.0.2/include/xmmintrin.h:93: (column 10) [FATAL]
Syntax error! The symbol `__extension__' does not fit here. --
And the bit from xmmintrin.h: -- static __inline __m128 _mm_setzero_ps (void) { return __extension__ (__m128){ 0.0f, 0.0f, 0.0f, 0.0f }; } -- Any similar trick that is applicable here? -- Ville Tirronen, University Of Jyväskylä

Ville Tirronen:
to get rid of the pesky __asm__ and __attribute__ annotations by passing the following additional arguments to the pre-processor: -D__asm__(A)= -D__attribute__(A)=
Most obliged. However, this leads me to:
-- [thoth]$ c2hs --cppopts='-I/usr/include/opencv -D"__asm__(A)= " -D"__attribute__(A)= "' cvWrapLEO.h Image.chs
c2hs: Error in C header file.
/usr/lib/gcc/x86_64-redhat-linux/4.0.2/include/xmmintrin.h:93: (column 10) [FATAL]
Syntax error! The symbol `__extension__' does not fit here. --
And the bit from xmmintrin.h:
-- static __inline __m128 _mm_setzero_ps (void) { return __extension__ (__m128){ 0.0f, 0.0f, 0.0f, 0.0f }; } --
Any similar trick that is applicable here?
Add -D"__extension__(A)=". Manuel

Most obliged. Any similar trick that is applicable here? Add -D"__extension__(A)=".
I thought as much, but this leads to something more weird: [thoth]$ c2hs --cppopts='-I/usr/include/opencv -D"__asm__(A)= " -D"__attribute__(A)= " -D"__extension__(A)= "' cvWrapLEO.h Image.chs c2hs: Error in C header file. /usr/lib/gcc/x86_64-redhat-linux/4.0.2/include/xmmintrin.h:93: (column 10) [FATAL]
Syntax error! The symbol `{' does not fit here.
The code beeing referenced is: static __inline __m128 _mm_setzero_ps (void) { return __extension__ (__m128){ 0.0f, 0.0f, 0.0f, 0.0f }; } -- Ville Tirronen, University Of Jyväskylä

Manuel M T Chakravarty wrote:
In the meantime, as a stop gap measure, we can use the C pre-processor to get rid of the pesky __asm__ and __attribute__ annotations by passing the following additional arguments to the pre-processor
Another option is to call the preprocessor as "cpp", not as "gcc". This way cpp will only see standard code, without GNU extensions. Incidentally, I stumbled upon this in connection with libdb. It references types named u_int8_t, u_int32_t and so on, which are typedef'd as "unsigned int" with some obscure and afaict undocumented __attribute__. C2hs throws the __attribute__ away and consequently thinks sizeof(u_int8_t)==4. Ouch. Passing -c cpp to c2hs, I get more standard definitions and everything works, apart from u_int64_t going missing. I'm not sure how to fix this in general and whether we should try at all. Maybe these integer types need special treatment... and special cases are ugly. Udo. -- I guess it's time I learnt how to interface to foreign code, any pointers?

Udo Stenzel:
Manuel M T Chakravarty wrote:
In the meantime, as a stop gap measure, we can use the C pre-processor to get rid of the pesky __asm__ and __attribute__ annotations by passing the following additional arguments to the pre-processor
Another option is to call the preprocessor as "cpp", not as "gcc". This way cpp will only see standard code, without GNU extensions.
Incidentally, I stumbled upon this in connection with libdb. It references types named u_int8_t, u_int32_t and so on, which are typedef'd as "unsigned int" with some obscure and afaict undocumented __attribute__. C2hs throws the __attribute__ away and consequently thinks sizeof(u_int8_t)==4. Ouch.
Yes, c2hs should actually interpret the __attribute__ annotations, rather than just ignoring them. One problem is really that these gcc extensions are rather poorly documented - at least, I had a trouble finding something when I looked.
Passing
-c cpp
to c2hs, I get more standard definitions and everything works, apart from u_int64_t going missing. I'm not sure how to fix this in general and whether we should try at all. Maybe these integer types need special treatment... and special cases are ugly.
I guess, we'd be fine, if we actually interpret __attribute__ in c2hs. Manuel
participants (4)
-
Duncan Coutts
-
Manuel M T Chakravarty
-
Udo Stenzel
-
Ville Tirronen