atomic builtin test uses C compiler instead of C++ compiler
| 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
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!
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.
Nah, I've got everything set up to regen with 2.60 so we can keep everything the same. I'll do that now.
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?
This ever get committed?
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.
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?
/me averts eyes from a configure patch :)
See patch below.
The atomic builtin test was previously using gcc, it is now using g++.
This fixes this problem:
- gcc and g++ defaults to -march=i386 (for example SuSE Linux)
- CFLAGS=-march=i686 CXXFLAGS= (mismatching flags)
- configure detects that atomic builtins are available
- C++ (!) files in lib/System are built that refer to _sync* builtins
- 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)
even better, thanks
I still don't get it. Please explain what the problem is better, thanks.
I think I'll rather just attach a patch here :)
I still don't get it. Please explain what the problem is better, thanks.
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.
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? :)
assigned to @echristo