Bug 51258 - 64-bit gcc.dg/atomic-compare-exchange-5.c link failure on 32-bit Solaris/x86
Summary: 64-bit gcc.dg/atomic-compare-exchange-5.c link failure on 32-bit Solaris/x86
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: testsuite (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Rainer Orth
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-21 17:52 UTC by Rainer Orth
Modified: 2012-03-22 12:25 UTC (History)
3 users (show)

See Also:
Host: i386-pc-solaris2.1[01]
Target: i386-pc-solaris2.1[01]
Build: i386-pc-solaris2.1[01]
Known to work:
Known to fail:
Last reconfirmed: 2011-11-23 00:00:00


Attachments
log of FAIL: gcc.dg/simulate-thread/atomic-load-int128.c -O1 -g thread simulation test failure on x86_64-apple-darwin11 (2.43 KB, text/plain)
2011-12-06 19:13 UTC, Jack Howarth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Orth 2011-11-21 17:52:53 UTC
Several 64-bit atomic-* tests fail to link with a 32-bit Solaris/x86 gcc:

Running target unix/-m64
FAIL: gcc.dg/atomic-compare-exchange-5.c (test for excess errors)
WARNING: gcc.dg/atomic-compare-exchange-5.c compilation failed to produce executable
FAIL: gcc.dg/atomic-exchange-5.c (test for excess errors)
WARNING: gcc.dg/atomic-exchange-5.c compilation failed to produce executable
FAIL: gcc.dg/atomic-load-5.c execution test
FAIL: gcc.dg/atomic-op-5.c (test for excess errors)
WARNING: gcc.dg/atomic-op-5.c compilation failed to produce executable
FAIL: gcc.dg/atomic-store-5.c (test for excess errors)
WARNING: gcc.dg/atomic-store-5.c compilation failed to produce executable

E.g. 

FAIL: gcc.dg/atomic-compare-exchange-5.c (test for excess errors)
Excess errors:
Undefined			first referenced
 symbol  			    in file
__atomic_compare_exchange_16        /var/tmp//ccSEaa.G.o

FAIL: gcc.dg/atomic-exchange-5.c (test for excess errors)
Excess errors:
Undefined			first referenced
 symbol  			    in file
__atomic_exchange_16                /var/tmp//cci5aWbI.o

FAIL: gcc.dg/atomic-op-5.c (test for excess errors)
Excess errors:
Undefined			first referenced
 symbol  			    in file
__atomic_fetch_nand_16              /var/tmp//ccnFaOtM.o
__atomic_fetch_or_16                /var/tmp//ccnFaOtM.o
__atomic_fetch_add_16               /var/tmp//ccnFaOtM.o
__atomic_fetch_and_16               /var/tmp//ccnFaOtM.o
__atomic_fetch_xor_16               /var/tmp//ccnFaOtM.o
__atomic_fetch_sub_16               /var/tmp//ccnFaOtM.o

FAIL: gcc.dg/atomic-store-5.c (test for excess errors)
Excess errors:
Undefined			first referenced
 symbol  			    in file
__atomic_store_16                   /var/tmp//ccV8ayIN.o
Comment 1 Andrew Macleod 2011-11-21 19:21:30 UTC
32 bit targets don't usually support 128 bit atomic operations natively, and leave calls to be resolved by an external atomic library.   There was some issue with X32 support where 32 bit could support it under some circumstances.

Now gcc/testsuite/lib/target-supports.exp defines the testsuite check for whether 128 bit is supported as:

proc check_effective_target_sync_int_128 { } {
    if { ([istarget x86_64-*-*] || [istarget i?86-*-*])
         && ![is-effective-target ia32] } {
        return 1
    } else {
        return 0
    }
}

I presume if 32 bit solaris isn't supporting 128 bit operations then this needs to be tweaked...
Comment 2 Richard Henderson 2011-11-21 19:41:16 UTC
The quoted test ought to have worked for i386-solaris.
If one of those predicates is wrong (e.g. is-effective-target ia32)
then there are other tests in the testsuite that are going to be
failing unnecessarily.
Comment 3 ro@CeBiTec.Uni-Bielefeld.DE 2011-11-22 15:05:13 UTC
> --- Comment #1 from Andrew Macleod <amacleod at redhat dot com> 2011-11-21 19:21:30 UTC ---
> 32 bit targets don't usually support 128 bit atomic operations natively, and
> leave calls to be resolved by an external atomic library.   There was some
> issue with X32 support where 32 bit could support it under some circumstances.
>
> Now gcc/testsuite/lib/target-supports.exp defines the testsuite check for
> whether 128 bit is supported as:
>
> proc check_effective_target_sync_int_128 { } {
>     if { ([istarget x86_64-*-*] || [istarget i?86-*-*])
>          && ![is-effective-target ia32] } {
>         return 1
>     } else {
>         return 0
>     }
> }
>
> I presume if 32 bit solaris isn't supporting 128 bit operations then this needs
> to be tweaked...

There's nothing Solaris-specific here, as I'm seeing the same issue on a
bi-arch i386-apple-darwin9.8.0 compiler for the 64-bit multilib.  It
seems the 32-bit compiler doesn't generate the 128-bit atomic insns when
generating 64-bit code.

	Rainer
Comment 4 Andrew Macleod 2011-11-22 16:07:52 UTC
I built a compiler in my linux box with a target of i386-apple-darwin.

during expanding an atomic_exchange it fails the call to can_compare_and_swap_p(TImode, true).

It returns CODE_FOR_nothing for both cases:

icode = direct_optab_handler (atomic_compare_and_swap_optab, mode);
if (icode != CODE_FOR_nothing)
  return true;

icode = optab_handler (sync_compare_and_swap_optab, mode);
if (icode != CODE_FOR_nothing)
  return true;

so something in the config/i386/sync.md file must be wrong for a 32 bit compiler which specifies -m64.  It does not set up the optab table for a TI mode compare_and_swap.
Comment 5 Uroš Bizjak 2011-11-22 18:52:56 UTC
(In reply to comment #4)

> so something in the config/i386/sync.md file must be wrong for a 32 bit
> compiler which specifies -m64.  It does not set up the optab table for a TI
> mode compare_and_swap.

-mcx16 ?
Comment 6 Uroš Bizjak 2011-11-22 19:22:54 UTC
It is a testsuite problem:

/* { dg-options "-mcx16" { target { x86_64-*-* } } } */

Something is missing there ... ;)
Comment 7 Uroš Bizjak 2011-11-22 19:29:20 UTC
Can somebody please test following change:

--cut here--
Index: atomic-exchange-5.c
===================================================================
--- atomic-exchange-5.c (revision 181628)
+++ atomic-exchange-5.c (working copy)
@@ -2,7 +2,7 @@
    values with each valid memory model.  */
 /* { dg-do run } */
 /* { dg-require-effective-target sync_int_128 } */
-/* { dg-options "-mcx16" { target { x86_64-*-* } } } */
+/* { dg-options "-mcx16" { target { i?86-*-* x86_64-*-* } } } */
 
 /* Test the execution of the __atomic_X builtin for a 16 byte value.  */
 
--cut here--
Comment 8 Andrew Macleod 2011-11-22 19:34:03 UTC
yes, presuming that it works, which I think it will, that will have to be applied to all the gcc.dg/atomic*-5.c files, as well as the gcc.dg/simulate-thread/atomic-*-int128.c files.
Comment 9 Rainer Orth 2011-11-23 15:16:47 UTC
Should have looked more closely ;-)  Patch posted.

  Rainer
Comment 10 Rainer Orth 2011-11-24 16:34:16 UTC
Author: ro
Date: Thu Nov 24 16:34:09 2011
New Revision: 181697

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181697
Log:
Fix several atomic tests on 32-bit x86 (PR testsuite/51258)

	PR testsuite/51258
	* gcc.dg/atomic-compare-exchange-5.c: Add -mcx16 on i?86-*-*.
	* gcc.dg/atomic-exchange-5.c: Likewise.
	* gcc.dg/atomic-load-5.c: Likewise.
	* gcc.dg/atomic-op-5.c: Likewise.
	* gcc.dg/atomic-store-5.c: Likewise.
	* gcc.dg/simulate-thread/atomic-other-int128.c: Fix typo.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/atomic-compare-exchange-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-exchange-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-load-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-op-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-store-5.c
    trunk/gcc/testsuite/gcc.dg/simulate-thread/atomic-other-int128.c
Comment 11 Uroš Bizjak 2011-11-25 16:26:41 UTC
I have additional patch that checks cpuid bit_CMPXCHG16B (and bit_CMPXCHG8B fwiw) for runtime support.
Comment 12 ro@CeBiTec.Uni-Bielefeld.DE 2011-11-25 16:35:43 UTC
> --- Comment #11 from Uros Bizjak <ubizjak at gmail dot com> 2011-11-25 16:26:41 UTC ---
> I have additional patch that checks cpuid bit_CMPXCHG16B (and bit_CMPXCHG8B
> fwiw) for runtime support.

Thanks for the heads up.  I've already committed my patch and meant to
work on this part over the weekend.

	Rainer
Comment 13 uros 2011-11-25 17:41:49 UTC
Author: uros
Date: Fri Nov 25 17:41:44 2011
New Revision: 181727

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181727
Log:
	PR testsuite/51258
	* lib/target-supports.exp
	(check_effective_target_sync_int_128_runtime): New procedure.
	(check_effective_target_sync_long_long_runtime): Ditto.
	(check_effective_target_sync_long_long): Add arm*-*-*.
	(check_effective_target_sync_longlong): Remove.

	* gcc.dg/atomic-op-5.c: Require sync_int_128_runtime effective target.
	* gcc.dg/atomic-compare-exchange-5.c: Ditto.
	* gcc.dg/atomic-exchange-5.c: Ditto.
	* gcc.dg/atomic-load-5.c: Ditto.
	* gcc.dg/atomic-store-5.c: Ditto.
	* gcc.dg/simulate-thread/atomic-load-int128.c: Ditto.
	* gcc.dg/simulate-thread/atomic-other-int128.c: Ditto.
	* gcc.dg/atomic-op-4.c: Require sync_long_long_runtime
	effective target.
	* gcc.dg/atomic-compare-exchange-4.c: Ditto.
	* gcc.dg/atomic-exchange-4.c: Ditto.
	* gcc.dg/atomic-load-4.c: Ditto.
	* gcc.dg/atomic-store-4.c: Ditto.
	* gcc.dg/di-longlong64-sync-1.c: Ditto.
	* gcc.dg/di-sync-multithread.c: Ditto.
	* gcc.dg/simulate-thread/atomic-load-longlong.c: Ditto.
	* gcc.dg/simulate-thread/atomic-other-longlong.c: Ditto.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/atomic-compare-exchange-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-compare-exchange-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-exchange-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-exchange-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-load-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-load-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-op-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-op-5.c
    trunk/gcc/testsuite/gcc.dg/atomic-store-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-store-5.c
    trunk/gcc/testsuite/gcc.dg/di-longlong64-sync-1.c
    trunk/gcc/testsuite/gcc.dg/di-sync-multithread.c
    trunk/gcc/testsuite/gcc.dg/simulate-thread/atomic-load-int128.c
    trunk/gcc/testsuite/gcc.dg/simulate-thread/atomic-load-longlong.c
    trunk/gcc/testsuite/gcc.dg/simulate-thread/atomic-other-int128.c
    trunk/gcc/testsuite/gcc.dg/simulate-thread/atomic-other-longlong.c
    trunk/gcc/testsuite/lib/target-supports.exp
Comment 14 uros 2011-11-25 19:31:02 UTC
Author: uros
Date: Fri Nov 25 19:30:58 2011
New Revision: 181728

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181728
Log:
	PR testsuite/51258
	* lib/target-supports.exp
	(check_effective_target_sync_long_long): Also supported on 32bit
	x86 targets.  Add comment about required dg-options.
	Add alpha*-*-* targets.
	(check_effective_target_sync_long_long_runtime): Ditto.

	* gcc.dg/atomic-op-4.c (dg-options): Add -march=pentium for
	32bit x86 targets.
	* gcc.dg/atomic-compare-exchange-4.c: Ditto.
	* gcc.dg/atomic-exchange-4.c: Ditto.
	* gcc.dg/atomic-load-4.c: Ditto.
	* gcc.dg/atomic-store-4.c: Ditto.
	* gcc.dg/di-longlong64-sync-1.c: Ditto.
	* gcc.dg/di-sync-multithread.c: Ditto.
	* gcc.dg/simulate-thread/atomic-load-longlong.c: Ditto.
	* gcc.dg/simulate-thread/atomic-other-longlong.c: Ditto.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/atomic-compare-exchange-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-exchange-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-load-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-op-4.c
    trunk/gcc/testsuite/gcc.dg/atomic-store-4.c
    trunk/gcc/testsuite/gcc.dg/di-longlong64-sync-1.c
    trunk/gcc/testsuite/gcc.dg/di-sync-multithread.c
    trunk/gcc/testsuite/gcc.dg/simulate-thread/atomic-load-longlong.c
    trunk/gcc/testsuite/gcc.dg/simulate-thread/atomic-other-longlong.c
    trunk/gcc/testsuite/lib/target-supports.exp
Comment 15 Jack Howarth 2011-12-06 19:08:22 UTC
On x86_64-apple-darwin11, we are seeing the following failures at -m64 (but not -m32)...

Running /sw/src/fink.build/gcc47-4.7.0-1/gcc-4.7-20111206/gcc/testsuite/gcc.dg/simulate-thread/simulate-thread.exp ...
FAIL: gcc.dg/simulate-thread/atomic-load-int128.c  -O1 -g  thread simulation test
FAIL: gcc.dg/simulate-thread/atomic-load-int128.c  -O2 -g  thread simulation test
FAIL: gcc.dg/simulate-thread/atomic-load-int128.c  -O3 -g  thread simulation test
FAIL: gcc.dg/simulate-thread/atomic-load-int128.c  -Os -g  thread simulation test

The output for the first failure is attached.
Comment 16 Jack Howarth 2011-12-06 19:13:59 UTC
Created attachment 26009 [details]
log of FAIL: gcc.dg/simulate-thread/atomic-load-int128.c  -O1 -g  thread simulation test failure on x86_64-apple-darwin11
Comment 17 Uroš Bizjak 2011-12-06 19:29:09 UTC
(In reply to comment #16)
> Created attachment 26009 [details]
> log of FAIL: gcc.dg/simulate-thread/atomic-load-int128.c  -O1 -g  thread
> simulation test failure on x86_64-apple-darwin11

Can you try with increased timeout value?

In testsuite/lib/gcc-simulate-thread.exp find following line:

    # Set timeout to 10 seconds due to huge amount of generated log.
    remote_expect target 10 {

and increase 10.

If this fails, you should check if generated executable runs OK outside of the debugger.
Comment 18 Jack Howarth 2011-12-06 20:53:35 UTC
The actual binaries for atomic-load-int128.c  at -O1 and higher run fine on x86_64-apple-darwin64 at -m64. However they take around 16 seconds to execute on a...

      Model Name: Mac Pro
      Model Identifier: MacPro3,1
      Processor Name: Quad-Core Intel Xeon
      Processor Speed: 2.8 GHz
      Number of Processors: 2
      Total Number of Cores: 8
      L2 Cache (per Processor): 12 MB
      Memory: 12 GB
      Bus Speed: 1.6 GHz

Increasing the timeout to 20 seconds allows all of the gcc.dg/simulate-thread/atomic-load-int128.c tests to pass.
Comment 19 Richard Biener 2012-03-22 08:27:23 UTC
GCC 4.7.0 is being released, adjusting target milestone.
Comment 20 Andrew Macleod 2012-03-22 12:10:45 UTC
Is this not resolved in 4.7?  I thought we had changed the timeouts back to normal and added other mechanisms to avoid large infinite loops
Comment 21 Rainer Orth 2012-03-22 12:25:26 UTC
Indeed, so closing.

  Rainer