9.0/i386 build failure

Dimitry Andric dim at FreeBSD.org
Sat Nov 5 19:06:26 UTC 2011

On 2011-11-05 14:28, Kostik Belousov wrote:
> On Sat, Nov 05, 2011 at 02:20:03PM +0100, Dimitry Andric wrote:
>> On 2011-11-04 20:09, Michael W. Lucas wrote:
>>> : undefined reference to `__sync_add_and_fetch_4'
> The system gcc was changed to assume march=486 some time ago.
> I suppose that the current-9 system is before the change, see r198344.

Yes, that is most likely the cause of this problem.  It is reproducible
if you set CC to 'gcc -march=i386' and CXX to 'g++ -march=i386'.

At first, I thought it would be easily fixable, since when you use
-march=i386, the macro __tune_i386__ is defined, so you can disable
LLVM's use of atomic builtins.

However, since r212286, libstdc++ is also configured to use atomic
builtins, and any non-trivial C++ program will encounter this linking
issue when compiling with -march=i386.

A workaround could be this:

Index: gnu/lib/libstdc++/config.h
--- gnu/lib/libstdc++/config.h  (revision 227112)
+++ gnu/lib/libstdc++/config.h  (working copy)
@@ -671,7 +671,7 @@
 /* #undef VERSION */

 /* Define if builtin atomic operations are supported on this host. */
-#if defined(__amd64__) || defined(__i386__)
+#if defined(__amd64__) || (defined(__i386__) && !defined(__tune_i386__))

but unfortunately during the bootstrap stage, the system includes are
used, not those in the source tree...

At the moment I don't know a clean way out of this, except setting CC to
'gcc -march=i486' and CXX to 'g++ -march=i486', and then building the
bootstrap-tools stage should at least complete successfully.

More information about the freebsd-current mailing list