problem compiling 64-bit application that uses posix threads

Hello,

I have some code that I compile and build on Linux IA32 and AMD64. It compiles and works with GCC 4.1.1, Intel 9.1. WIth Sun Studio Express 2 I can build it and test it on IA32 but when I try to compile on AMD64 I get this error:

suncc -xMMD -xO1 -fast -m64 -xc99=all -xCC -Xc -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include-Kpic -Delement_t=uint16_t -DELEMENT_MAX=UINT16_MAX -DELEMENT_MIN=0-c -o graph_metrics.o graph_metrics.c

"/usr/include/pthread.h", line 660: syntax error before or at: __attribute

"/usr/include/pthread.h", line 662: identifier redefined: __attribute

current : function() returning int

previous: function() returning int : "/usr/include/pthread.h", line 660

cc: acomp failed for graph_metrics.c

The IA32 box is using Ubuntu 6.10 and the AMD64 box is using Debian Testing/Unstable 4.0 .

The compilation flags for suncc are identical except "-m64".

The pthread.h relevant lines:

658 /* Internal interface to initiate cleanup. */

659 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)

660__cleanup_fct_attribute __attribute ((__noreturn__))

661 # ifndef SHARED

662__attribute ((__weak__))

663 # endif

664;

665 #endif

The version number is:

$ dpkg -S /usr/include/pthread.h

libc6-dev: /usr/include/pthread.h

$ dpkg -l libc6-dev

Desired=Unknown/Install/Remove/Purge/Hold

| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed

|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)

||/ NameVersionDescription

+++-==============-==============-============================================

ii libc6-dev2.3.6.ds1-8GNU C Library: Development Libraries and Hea

[1851 byte] By [theMAGE] at [2007-11-26 11:48:33]
# 1

Try to get preprocessed files by gcc and suncc. Use -E command line option for that. Then find __pthread_unwind_next declaration and check __cleanup_fct_attribute. I'm not sure but maybe under gcc it's an empty macro or substituted by some attributes. And under suncc it lefts unchanged by preprocessor so compiler get confused.

Atanasyan at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

On the Debian AMD64 box...

Source pre-processed with GCC 4.1.1:

# 608 "/usr/include/pthread.h" 3 4

extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)

;

# 619 "/usr/include/pthread.h" 3 4

extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)

;

# 659 "/usr/include/pthread.h" 3 4

extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)

__attribute ((__noreturn__))

__attribute ((__weak__))

;

Source pre-processed with Sun Studio Express 2

# 608

extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)

;

# 619

extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)

;

# 657

extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)

__attribute ((__noreturn__))

# 662

__attribute ((__weak__))

# 664

;

# 666

Neither of the pre-processed files contains any reference to __cleanup_fct_attribute since it is defined to nothing on line 463:

461 /* No special attributes by default. */

462 #ifndef __cleanup_fct_attribute

463 # define __cleanup_fct_attribute

464 #endif

I will check the contents of the /usr/include/pthread.h on the Ubuntu 32 bit box later.

theMAGE at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
You have found a bug in the compiler. It's surprise for me too - Sun C++ understand __attribute__ but does not understand __attribute.Could you file a bug at http://bugs.sun.com/services/bugreport/index.jsp?
Atanasyan at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
Internal review ID: 854516Indeed, defining __attribute as __attribute__ allowed the compiler to continue.Thanks!
theMAGE at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

> I will check the contents of the

> /usr/include/pthread.h on the Ubuntu 32 bit box later.

Ubuntu 6.10 comes with glibc 2.4 which has __attribute__ everywhere in /usr/include/pthread.h .

I suppose this patch was applied: http://sources.redhat.com/ml/libc-hacker/2005-11/msg00030.html

I don't have a reference to the standard handy to check if both variants should be accepted or not.

theMAGE at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6

__attribute and __attribute__ are gcc language extensions. There is no standard that covers the keyword. (That is, the keyword is not part of Standard C, C++ or Unix.)

We have already added support for __attribute in the C compiler, and it will appear in the next Studio Express update, which should be in the next 2 or 3 weeks. (Due to a dropped ball, it won't appear in the C++ compiler until the update following this one.)

clamage45 at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7

> We have already added support for __attribute in the

> C compiler, and it will appear in the next Studio

> Express update, which should be in the next 2 or 3

> weeks. (Due to a dropped ball, it won't appear in the

> C++ compiler until the update following this one.)

Or maybe later again :-(

(still not there for C++ in express 4)

Marc_Glisse at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 8
Yep. Only in final release, together with numerous improvements in standard headers handling.regards,__Fedor.
SFV at 2007-7-7 12:01:03 > top of Java-index,Development Tools,Solaris and Linux Development Tools...