llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

atomic builtin test uses C compiler instead of C++ compiler

Open edwintorok opened this issue 16 years ago • 15 comments

Bugzilla Link 6711
Resolution FIXED
Resolved on Jul 29, 2010 01:35
Version unspecified
OS Linux
CC @lattner,@echristo

Extended Description

It uses the C compiler to do the test, and succeeds (atomic builtins available). At build time it fails to link with missing symbols for __sync_val_compare_and_swap_4, because it uses the C++ compiler for linking (and that is not what configure tested).

This happens if you build with CFLAGS != CXXFLAGS, and CFLAGS sets the target architecture to something that supports atomic builtins, while CXXFLAGS stays at the default (i386?) that doesn't support it.

See here for more details: http://lurker.clamav.net/message/20100326.084547.051ffb52.en.html

edwintorok avatar Mar 26 '10 10:03 edwintorok

Committed thusly:

[yendi:Data/sources/llvm] echristo% svn ci autoconf/configure.ac Sending autoconf/configure.ac Transmitting file data . Committed revision 109646. [yendi:Data/sources/llvm] echristo% svn ci configure Sending configure Transmitting file data . Committed revision 109647.

Thanks!

edwintorok avatar Jul 29 '10 08:07 edwintorok

Committed thusly:

[yendi:Data/sources/llvm] echristo% svn ci autoconf/configure.ac Sending autoconf/configure.ac Transmitting file data . Committed revision 109646. [yendi:Data/sources/llvm] echristo% svn ci configure Sending configure Transmitting file data . Committed revision 109647.

echristo avatar Jul 28 '10 22:07 echristo

Nah, I've got everything set up to regen with 2.60 so we can keep everything the same. I'll do that now.

echristo avatar Jul 28 '10 22:07 echristo

This ever get committed?

No, I think I didn't have the proper version of autoconf installed, and didn't want to regen configure with 2.65 just prior to 2.7 release.

Should I commit + regen with 2.65 now?

edwintorok avatar Jul 28 '10 08:07 edwintorok

This ever get committed?

echristo avatar Jul 28 '10 01:07 echristo

Looks good. Please go ahead and commit and regenerate configure. Do add a comment though explaining why we need to verify the link with C++.

Will do.

FWIW this may, in fact, be the lamest thing I've ever seen. Why on earth would someone do such a thing?

By mistake, because they used a build script meant for ClamAV 0.95.3 to build ClamAV 0.96. ClamAV 0.95 obviously didn't include any C++ code, so it has only set CFLAGS, not CXXFLAGS.

edwintorok avatar Apr 05 '10 21:04 edwintorok

Looks good. Please go ahead and commit and regenerate configure. Do add a comment though explaining why we need to verify the link with C++.

FWIW this may, in fact, be the lamest thing I've ever seen. Why on earth would someone do such a thing?

echristo avatar Apr 05 '10 20:04 echristo

/me averts eyes from a configure patch :)

lattner avatar Mar 31 '10 06:03 lattner

See patch below.

The atomic builtin test was previously using gcc, it is now using g++.

This fixes this problem:

  1. gcc and g++ defaults to -march=i386 (for example SuSE Linux)
  2. CFLAGS=-march=i686 CXXFLAGS= (mismatching flags)
  3. configure detects that atomic builtins are available
  4. C++ (!) files in lib/System are built that refer to _sync* builtins
  5. It fails to link, because CXXFLAGS didn't contain a >i386 arch, hence no atomic builtins are available when compiled with g++.

The fix is to actually use the C++ compiler for this test, since we'll be using these atomic builtins in C++ files.

Hopefully this is clearer now.

Index: autoconf/configure.ac

--- autoconf/configure.ac (revision 99881) +++ autoconf/configure.ac (working copy) @@ -1315,6 +1315,7 @@

dnl atomic builtins are required for threading support. AC_MSG_CHECKING(for GCC atomic builtins) +AC_LANG_PUSH([C++]) AC_LINK_IFELSE( AC_LANG_SOURCE( [[int main() { @@ -1326,6 +1327,7 @@ return 0; } ]]),

  • AC_LANG_POP([C++]) AC_MSG_RESULT(yes) AC_DEFINE(LLVM_MULTITHREADED, 1, Build multithreading support into LLVM), AC_MSG_RESULT(no)

edwintorok avatar Mar 30 '10 22:03 edwintorok

even better, thanks

lattner avatar Mar 30 '10 19:03 lattner

I still don't get it. Please explain what the problem is better, thanks.

I think I'll rather just attach a patch here :)

edwintorok avatar Mar 30 '10 14:03 edwintorok

I still don't get it. Please explain what the problem is better, thanks.

lattner avatar Mar 30 '10 08:03 lattner

Edwin, I have no idea what you're saying is broken. Is this a configure issue, a testsuite issue, a compiler issue, a clang issue? :)

A configure issue, this breaks: CFLAGS="-O2 -march=i686" CXXFLAGS=

On some systems gcc defaults to i386, so LLVM's configure will detect that atomic builtins are present (due to i686 in CFLAGS), however at build time it'll fail with a missing symbol (since CXXFLAGS didn't have i686, and thus it got compiled for i386).

Configure should use the C++ compiler to do the atomic builtin test.

edwintorok avatar Mar 27 '10 11:03 edwintorok

Edwin, I have no idea what you're saying is broken. Is this a configure issue, a testsuite issue, a compiler issue, a clang issue? :)

lattner avatar Mar 27 '10 02:03 lattner

assigned to @echristo

edwintorok avatar Mar 26 '10 10:03 edwintorok