Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 07 Oct 2012 01:09:42 +0930
From:      Shane Ambler <FreeBSD@ShaneWare.Biz>
To:        Tijl Coosemans <tijl@coosemans.org>
Cc:        gerald@freebsd.org, FreeBSD-ports <freebsd-ports@freebsd.org>
Subject:   Re: Possible regression in i386 build with gcc 4.6
Message-ID:  <507050BE.4050905@ShaneWare.Biz>
In-Reply-To: <506EEA7C.2020307@coosemans.org>
References:  <506B3E9A.1000905@ShaneWare.Biz> <506EEA7C.2020307@coosemans.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 05/10/2012 23:41, Tijl Coosemans wrote:
> On 02-10-2012 21:20, Shane Ambler wrote:
>> I found a situation where gcc v4.2 compiles a i386 working binary and
>> v4.6 doesn't. (Currently 4.7 and 4.8 fail to build this code) I have
>> verified that this happens with 8.2/8.3/9.0 i386 systems. x86_64
>> versions build without issue as does clang i386/x86_64.

>> It appears that the x86_64 target of gcc offers gcc atomics while the
>> i386 target doesn't - and this appears to be a freebsd specific setup,
>> the i386 targets then fall back to using tbb atomics.
>>
>> inline long long
>> atomic_exchange_and_add (volatile long long *at, long long x)
>> {
>> #ifdef USE_GCC_ATOMICS
>>      return __sync_fetch_and_add (at, x);
>> #elif USE_TBB
>>      atomic<long long> *a = (atomic<long long> *)at;
>>      return a->fetch_and_add (x);
>> #elif defined(__APPLE__)
>>    <snip>
>> #endif
>> }
>
> Atomic operations on long long require cmpxchg8b instruction which was
> added to the i586, so if you add -march=i586 to CFLAGS you should be
> able to use gcc atomics on FreeBSD/i386 as well.
>

The arch setting isn't the issue - gcc compiled on freebsd for 32bit x86 
target doesn't provide gcc atomics. So __sync_fetch_and_add doesn't 
exist. While adding support for gcc atomics to the i386 target would be 
good, I would assume there is a reason that it is disabled on FreeBSD 
(that reason may or may not be resolved now).

The point I wanted to make in this email is that for some reason gcc46 
compiles the tbb alternative in a way that causes a seg fault when gcc42 
can compile it fine. And to maybe get the gcc atomics support re-evaluated.

But you did give me an idea or two - the first of adding some asm code 
is beyond me but I then went and found that go-semacquire.c from gcc46 
source has code for __sync_fetch_and_add_4 (using pthread mutex locks) 
so I used that to create a patch that gets the gcc46 build working.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?507050BE.4050905>