Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 201596 - GCC 4.2.x and ICC up to 10.1.008 are incompatible
Summary: GCC 4.2.x and ICC up to 10.1.008 are incompatible
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Sébastien Fabbro (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-07 16:55 UTC by Eric Thibodeau
Modified: 2008-08-20 22:40 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Thibodeau 2007-12-07 16:55:56 UTC
ICC is compatible with most current GCC versions (in portage) up to 4.1.x . 4.2.x series GCC breaks this compatibility and there should be some sort of warning surrounding this (icpc is rendered useless in the presence of 4.2 as the main compiler).

Reproducible: Always

Steps to Reproduce:
Attempt to compile a simple CPP test program fails.
kyron@kyron ~/_________temp $ cat test.cpp
#include <string>
int
main ()
{
std::string foo = "Hello, world"
  ;
  return 0;
}


Actual Results:  
kyron@kyron ~/_________temp $ icpc test.cpp -o test
/usr/lib/gcc/i686-pc-linux-gnu/4.2.2/include/g++-v4/ext/atomicity.h(51): error: identifier "__sync_fetch_and_add" is undefined
    { return __sync_fetch_and_add(__mem, __val); }
             ^

/usr/lib/gcc/i686-pc-linux-gnu/4.2.2/include/g++-v4/ext/atomicity.h(55): error: identifier "__sync_fetch_and_add" is undefined
    { __sync_fetch_and_add(__mem, __val); }
      ^

compilation aborted for test.cpp (code 2)


Expected Results:  
Hello, world


I was unable to find information either on Intel's site nor GCC's site relating to this problem and/or expected time to fix of this issue.
Comment 1 SpanKY gentoo-dev 2007-12-07 17:32:37 UTC
not a gcc issue ... assign to whoever watches icc
Comment 2 Eric Thibodeau 2007-12-07 21:26:21 UTC
Bug#: 194513 has a proposed workaround which is:

[...snip...]
The solution is to commend out the line:
#define _GLIBCXX_ATOMIC_BUILTINS 1
in
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.2.1/include/g++-v4/x86_64-pc-linux-gnu/bits/c++config.h
[...snip...]

The impact of unsetting _GLIBCXX_ATOMIC_BUILTINS is seen in /usr/lib/gcc/i686-pc-linux-gnu/4.2.2/include/g++-v4/ext/atomicity.h (of course...hence the error message ;) )
From atomicity.h:

#ifdef _GLIBCXX_ATOMIC_BUILTINS
  static inline _Atomic_word
  __exchange_and_add(volatile _Atomic_word* __mem, int __val)
  { return __sync_fetch_and_add(__mem, __val); }

  static inline void
  __atomic_add(volatile _Atomic_word* __mem, int __val)
  { __sync_fetch_and_add(__mem, __val); }
#else
  _Atomic_word
  __attribute__ ((__unused__))
  __exchange_and_add(volatile _Atomic_word*, int);

  void
  __attribute__ ((__unused__))
  __atomic_add(volatile _Atomic_word*, int);
#endif

The following is also impacted:
/usr/lib/gcc/i686-pc-linux-gnu/4.2.2/include/g++-v4/ext/concurrence.h

[...snip...]
#ifdef _GLIBCXX_ATOMIC_BUILTINS
  _S_atomic;
#else
  _S_mutex;
#endif
[...snip...]

So, un-setting _GLIBCXX_ATOMIC_BUILTINS is an "solution" but it remains unclear as to the performance impact.
Comment 3 Eric Thibodeau 2007-12-07 21:27:33 UTC
...Ok, so obviously, there shouldn't be any output when executing `test`, that was me out of coffee and sleep ;)
Comment 4 Jakub Moc (RETIRED) gentoo-dev 2007-12-07 22:41:18 UTC
Yeah, so don't use ICC.
Comment 5 Andreas Arens 2007-12-08 09:07:05 UTC
I think it still could be a gcc regression, at least with respect to this
gcc-bugzilla bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28671

This for example did break my 'emerge -e system' at least with gcc-4.2.0 without -march (so defaulting to -march=i386). Didn't recheck with gcc-4.2.2 p1.0 I currently use, but I suspect the regression is still there, since I'm not sure the final fix proposed there ever went into the 4.2 release branch.

Comment 6 Eric Thibodeau 2007-12-09 17:22:53 UTC
Re-opening. This issue should be at least addressed in icc's ebuild in the form of a warning message.

Furthermore, the addition of ATOMIC_BUILTINS is relatively recent and warrants some caution on it's actual use. One can expect more problems to arise from this in the near future as people will do the transition to 4.2.x series. For more details, please read: http://gcc.gnu.org/ml/libstdc++/2006-07/msg00013.html
Comment 7 Eric Thibodeau 2007-12-10 17:53:33 UTC
There might be a hint of another workaround (with less system-wide impact) at:

http://www.intel.com/software/products/compilers/docs/clin/main_cls/mergedprojects/bldaps_cls/common/bldaps_interop_options_comm.htm

By using -cxxlib (not -gcc-version 420, that obviously doesn't work). This would imply that we specify (a copy?) of the libstdc++ headers that don't include the Atomic ops. This way GCC compiled apps are optimized with these new features and ICC apps _can_ be compiled ;)
Comment 8 Brian Olsen 2007-12-17 16:39:26 UTC
For minimal impact I'd suggest adding -DICC to  icc compiles

and doing this inside 

/usr/lib64/gcc/x86_64-pc-linux-gnu/4.2.2/include/g++-v4/x86_64-pc-linux-gnu/bits/c++config.h

#if ! defined(ICC)
#define _GLIBCXX_ATOMIC_BUILTINS 1
#endif
Comment 9 Eric Thibodeau 2007-12-17 18:46:40 UTC
(In reply to comment #8)
> /usr/lib64/gcc/x86_64-pc-linux-gnu/4.2.2/include/g++-v4/x86_64-pc-linux-gnu/bits/c++config.h
> 
> #if ! defined(ICC)
> #define _GLIBCXX_ATOMIC_BUILTINS 1
> #endif
> 

I definitely vote for this workaround.
Comment 10 Sébastien Fabbro (RETIRED) gentoo-dev 2008-01-08 16:03:19 UTC
re-cc toolchain for advice on gcc. What's the future of the file c++config.h on future versions of gcc? Does the solution proposed in comment #8 seem reasonable to you?
Comment 11 SpanKY gentoo-dev 2008-01-08 18:35:21 UTC
no, such a change is not acceptable (to me).  maybe you can convince upstream on such a thing, but i'm not going for it.

presumably such a change would be a temporary solution ... maybe with gcc-4.2.x, such an addition is "new", but what are you going to do about gcc-4.3 ?  gcc-4.4 ?

googling shows that the icc guys are already dealing with this
Comment 12 Sébastien Fabbro (RETIRED) gentoo-dev 2008-02-01 19:37:59 UTC
icc-10.1.012 just made it to the tree. Could you test it? It seems that upstream put some work into it.

Comment 13 Matt Turner gentoo-dev 2008-02-17 14:24:10 UTC
Unable to reproduce original test. Using gcc-4.2.2 and icc-10.1.0.12. Is this bug still valid?
Comment 14 Sébastien Fabbro (RETIRED) gentoo-dev 2008-02-26 10:34:50 UTC
Seems fixed then. Re-open if the problem persists in versions >= 10.1.012
Thanks

Comment 15 Tomasz C. 2008-04-18 12:27:02 UTC
I've just checked it and icc-10.1.013 and gcc-4.2.3 still seem to be incompatible- I receive the same error (__sync_fetch_and_add undefined).
The line: "#define _GLIBCXX_ATOMIC_BUILTINS 1" is already in the c++config.h file.
Comment 16 Pau Garcia i Quiles 2008-08-20 22:40:15 UTC
This bug is present with gcc 4.2.3 and ICC 10.1.015. The aforementioned workaround is wrong, the right one is:

#ifndef __INTEL_COMPILER
#define _GLIBCXX_ATOMIC_BUILTINS 1
#endif

(look at http://predef.sf.net)