Re: building i386 world on amd64 host: failed @svn

2013-08-16 Thread Dimitry Andric
On Aug 15, 2013, at 21:38, Jung-uk Kim j...@freebsd.org wrote:
 On 2013-08-15 15:30:49 -0400, Konstantin Belousov wrote:
 On Thu, Aug 15, 2013 at 09:12:52PM +0200, Dimitry Andric wrote:
 On Aug 15, 2013, at 20:36, Konstantin Belousov
 kostik...@gmail.com wrote:
 Does the linux box defaults to pentium or higher for -march ? 
 64 bit atomics cannot be implemented in usermode on i386 on 
 processors which do not have cmpxchg8b instruction.
 
 Ah yes, you are totally right, with -v it gives:
 
 COLLECT_GCC_OPTIONS='-O2' '-S' '-v' '-mtune=generic'
 '-march=i586'
 
 So we should really disable atomics for i486 and lower?  Though I
 have understood that there also some pentiums without
 cmpxchg8b...
 
 I do not think that there was any Pentium-branded CPU which did
 not implemented cmpxchg8b.  Some late 486 did provided cpuid, but I
 am almost certain that they did not have cmpxchg8b (cannot check
 anyway).
 
 It is actually little complicated.
 
 http://www.geoffchappell.com/studies/windows/km/cpu/cx8.htm


In contrast, gcc's rules (in contrib/gcc/config/i386/i386.c) are pretty
straightforward:

  /* Compare and exchange was added for 80486.  */
  const int x86_cmpxchg = ~m_386;
  /* Compare and exchange 8 bytes was added for pentium.  */
  const int x86_cmpxchg8b = ~(m_386 | m_486);

So maybe the following is a safe enough solution for now:

Index: usr.bin/svn/svn_private_config.h
===
--- usr.bin/svn/svn_private_config.h(revision 254300)
+++ usr.bin/svn/svn_private_config.h(working copy)
@@ -153,7 +153,9 @@
 #define SVN_FS_WANT_DB_PATCH 14

 /* Define if compiler provides atomic builtins */
+#if !defined(__i386__) || !defined(__i486__)
 #define SVN_HAS_ATOMIC_BUILTINS 1
+#endif

 /* Is GNOME Keyring support enabled? */
 /* #undef SVN_HAVE_GNOME_KEYRING */

Those rules can be extended for other arches or CPUs that don't support
64-bit atomic operations.

-Dimitry

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: building i386 world on amd64 host: failed @svn

2013-08-16 Thread Konstantin Belousov
On Fri, Aug 16, 2013 at 02:33:29PM +0200, Dimitry Andric wrote:
 On Aug 15, 2013, at 21:38, Jung-uk Kim j...@freebsd.org wrote:
  On 2013-08-15 15:30:49 -0400, Konstantin Belousov wrote:
  On Thu, Aug 15, 2013 at 09:12:52PM +0200, Dimitry Andric wrote:
  On Aug 15, 2013, at 20:36, Konstantin Belousov
  kostik...@gmail.com wrote:
  Does the linux box defaults to pentium or higher for -march ? 
  64 bit atomics cannot be implemented in usermode on i386 on 
  processors which do not have cmpxchg8b instruction.
  
  Ah yes, you are totally right, with -v it gives:
  
  COLLECT_GCC_OPTIONS='-O2' '-S' '-v' '-mtune=generic'
  '-march=i586'
  
  So we should really disable atomics for i486 and lower?  Though I
  have understood that there also some pentiums without
  cmpxchg8b...
  
  I do not think that there was any Pentium-branded CPU which did
  not implemented cmpxchg8b.  Some late 486 did provided cpuid, but I
  am almost certain that they did not have cmpxchg8b (cannot check
  anyway).
  
  It is actually little complicated.
  
  http://www.geoffchappell.com/studies/windows/km/cpu/cx8.htm
 
 
 In contrast, gcc's rules (in contrib/gcc/config/i386/i386.c) are pretty
 straightforward:
 
   /* Compare and exchange was added for 80486.  */
   const int x86_cmpxchg = ~m_386;
   /* Compare and exchange 8 bytes was added for pentium.  */
   const int x86_cmpxchg8b = ~(m_386 | m_486);
 
 So maybe the following is a safe enough solution for now:
 
 Index: usr.bin/svn/svn_private_config.h
 ===
 --- usr.bin/svn/svn_private_config.h(revision 254300)
 +++ usr.bin/svn/svn_private_config.h(working copy)
 @@ -153,7 +153,9 @@
  #define SVN_FS_WANT_DB_PATCH 14
 
  /* Define if compiler provides atomic builtins */
 +#if !defined(__i386__) || !defined(__i486__)
  #define SVN_HAS_ATOMIC_BUILTINS 1
 +#endif
I do not understand this.  Isn't __i386__ defined always when compiling
for 32bit x86 ?  

The !defined(__i486__) part assumes that any other cpu variation supported
by compiler has cmpxchg8b.


pgpsCcg5MpQ3O.pgp
Description: PGP signature


Re: building i386 world on amd64 host: failed @svn

2013-08-16 Thread Dimitry Andric
On Aug 16, 2013, at 17:02, Konstantin Belousov kostik...@gmail.com wrote:
 On Fri, Aug 16, 2013 at 02:33:29PM +0200, Dimitry Andric wrote:
...
 In contrast, gcc's rules (in contrib/gcc/config/i386/i386.c) are pretty
 straightforward:
 
  /* Compare and exchange was added for 80486.  */
  const int x86_cmpxchg = ~m_386;
  /* Compare and exchange 8 bytes was added for pentium.  */
  const int x86_cmpxchg8b = ~(m_386 | m_486);
 
 So maybe the following is a safe enough solution for now:
 
 Index: usr.bin/svn/svn_private_config.h
 ===
 --- usr.bin/svn/svn_private_config.h(revision 254300)
 +++ usr.bin/svn/svn_private_config.h(working copy)
 @@ -153,7 +153,9 @@
 #define SVN_FS_WANT_DB_PATCH 14
 
 /* Define if compiler provides atomic builtins */
 +#if !defined(__i386__) || !defined(__i486__)
 #define SVN_HAS_ATOMIC_BUILTINS 1
 +#endif
 I do not understand this.  Isn't __i386__ defined always when compiling
 for 32bit x86 ?  
 
 The !defined(__i486__) part assumes that any other cpu variation supported
 by compiler has cmpxchg8b.


Yes, that was the intention.  So if it is i386 arch, but the CPU isn't
i486, the builtins can be enabled.  This is the same logic that gcc
itself uses.

It only breaks down when compiling with -mcpu=i386 though, but I don't
think we support that anymore?

The ifdef was just the negation of:

#if defined(__i386__)  defined(__i486__)
#undef SVN_HAS_ATOMIC_BUILTINS
#endif

-Dimitry

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: building i386 world on amd64 host: failed @svn

2013-08-15 Thread Dimitry Andric
On Jul 28, 2013, at 15:15, Dmitry Morozovsky ma...@rinet.ru wrote:
...
 on my builder I have consistent error:
 
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  
 In function `svn_named_atomic__cmpxchg':
 named_atomic.c:(.text+0xed): undefined reference to 
 `__sync_val_compare_and_swap_8'
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  
 In function `svn_named_atomic__add':
 named_atomic.c:(.text+0x193): undefined reference to `__sync_add_and_fetch_8'
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  
 In function `svn_named_atomic__write':
 named_atomic.c:(.text+0x1f3): undefined reference to 
 `__sync_lock_test_and_set_8'

After a bit of private conversation with Dmitry, it turned out he was
building using WITHOUT_CLANG, e.g. gcc is used for everything.  Now,
this is *not* a problem specific to cross-building: head will not build
on i386 with gcc at all!  It results in exactly the same error shown
above.

This is because Subversion has a few wrapper routines for atomic
operations, and these are implemented in terms of the __sync_xxx
compiler builtins, since usr.bin/svn/svn_private_config.h has
SVN_HAS_ATOMIC_BUILTINS defined.  On i386, gcc apparently cannot inline
the 64 bit versions of these builtins, so it inserts a call to an
external function instead, leading to a link error.

Eventually, we could put such functions in libc, but for now it might be
better to turn off the SVN_HAS_ATOMIC_BUILTINS define in case of !clang
 i386, e.g.:

Index: usr.bin/svn/svn_private_config.h
===
--- usr.bin/svn/svn_private_config.h(revision 254300)
+++ usr.bin/svn/svn_private_config.h(working copy)
@@ -153,7 +153,9 @@
 #define SVN_FS_WANT_DB_PATCH 14

 /* Define if compiler provides atomic builtins */
+#if defined(__i386__)  !defined(__clang__)
 #define SVN_HAS_ATOMIC_BUILTINS 1
+#endif

 /* Is GNOME Keyring support enabled? */
 /* #undef SVN_HAVE_GNOME_KEYRING */

Alternatively, we could attempt to figure out why gcc doesn't want to
inline those 64 bit builtins on FreeBSD.  It seems to have no problem
doing so on the first Linux box I tried...

-Dimitry

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: building i386 world on amd64 host: failed @svn

2013-08-15 Thread Adrian Chadd
Oh, _this_ is the cause! Cool. I wondered about it.

Thanks for chasing this down!



-adrian


On 15 August 2013 11:13, Dimitry Andric d...@freebsd.org wrote:

 On Jul 28, 2013, at 15:15, Dmitry Morozovsky ma...@rinet.ru wrote:
 ...
  on my builder I have consistent error:
 
 
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  In function `svn_named_atomic__cmpxchg':
  named_atomic.c:(.text+0xed): undefined reference to
  `__sync_val_compare_and_swap_8'
 
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  In function `svn_named_atomic__add':
  named_atomic.c:(.text+0x193): undefined reference to
 `__sync_add_and_fetch_8'
 
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  In function `svn_named_atomic__write':
  named_atomic.c:(.text+0x1f3): undefined reference to
  `__sync_lock_test_and_set_8'

 After a bit of private conversation with Dmitry, it turned out he was
 building using WITHOUT_CLANG, e.g. gcc is used for everything.  Now,
 this is *not* a problem specific to cross-building: head will not build
 on i386 with gcc at all!  It results in exactly the same error shown
 above.

 This is because Subversion has a few wrapper routines for atomic
 operations, and these are implemented in terms of the __sync_xxx
 compiler builtins, since usr.bin/svn/svn_private_config.h has
 SVN_HAS_ATOMIC_BUILTINS defined.  On i386, gcc apparently cannot inline
 the 64 bit versions of these builtins, so it inserts a call to an
 external function instead, leading to a link error.

 Eventually, we could put such functions in libc, but for now it might be
 better to turn off the SVN_HAS_ATOMIC_BUILTINS define in case of !clang
  i386, e.g.:

 Index: usr.bin/svn/svn_private_config.h
 ===
 --- usr.bin/svn/svn_private_config.h(revision 254300)
 +++ usr.bin/svn/svn_private_config.h(working copy)
 @@ -153,7 +153,9 @@
  #define SVN_FS_WANT_DB_PATCH 14

  /* Define if compiler provides atomic builtins */
 +#if defined(__i386__)  !defined(__clang__)
  #define SVN_HAS_ATOMIC_BUILTINS 1
 +#endif

  /* Is GNOME Keyring support enabled? */
  /* #undef SVN_HAVE_GNOME_KEYRING */

 Alternatively, we could attempt to figure out why gcc doesn't want to
 inline those 64 bit builtins on FreeBSD.  It seems to have no problem
 doing so on the first Linux box I tried...

 -Dimitry

 ___
 freebsd-current@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-current
 To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: building i386 world on amd64 host: failed @svn

2013-08-15 Thread Konstantin Belousov
On Thu, Aug 15, 2013 at 08:13:34PM +0200, Dimitry Andric wrote:
 Alternatively, we could attempt to figure out why gcc doesn't want to
 inline those 64 bit builtins on FreeBSD.  It seems to have no problem
 doing so on the first Linux box I tried...

Does the linux box defaults to pentium or higher for -march ?
64 bit atomics cannot be implemented in usermode on i386 on
processors which do not have cmpxchg8b instruction.


pgpE81b6JMcjE.pgp
Description: PGP signature


Re: building i386 world on amd64 host: failed @svn

2013-08-15 Thread Dimitry Andric
On Aug 15, 2013, at 20:36, Konstantin Belousov kostik...@gmail.com wrote:
 On Thu, Aug 15, 2013 at 08:13:34PM +0200, Dimitry Andric wrote:
 Alternatively, we could attempt to figure out why gcc doesn't want to
 inline those 64 bit builtins on FreeBSD.  It seems to have no problem
 doing so on the first Linux box I tried...
 
 Does the linux box defaults to pentium or higher for -march ?
 64 bit atomics cannot be implemented in usermode on i386 on
 processors which do not have cmpxchg8b instruction.

Ah yes, you are totally right, with -v it gives:

  COLLECT_GCC_OPTIONS='-O2' '-S' '-v' '-mtune=generic' '-march=i586'

So we should really disable atomics for i486 and lower?  Though I have
understood that there also some pentiums without cmpxchg8b...

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: building i386 world on amd64 host: failed @svn

2013-08-15 Thread Konstantin Belousov
On Thu, Aug 15, 2013 at 09:12:52PM +0200, Dimitry Andric wrote:
 On Aug 15, 2013, at 20:36, Konstantin Belousov kostik...@gmail.com wrote:
  Does the linux box defaults to pentium or higher for -march ?
  64 bit atomics cannot be implemented in usermode on i386 on
  processors which do not have cmpxchg8b instruction.
 
 Ah yes, you are totally right, with -v it gives:
 
   COLLECT_GCC_OPTIONS='-O2' '-S' '-v' '-mtune=generic' '-march=i586'
 
 So we should really disable atomics for i486 and lower?  Though I have
 understood that there also some pentiums without cmpxchg8b...

I do not think that there was any Pentium-branded CPU which did not
implemented cmpxchg8b.  Some late 486 did provided cpuid, but I am
almost certain that they did not have cmpxchg8b (cannot check anyway).


pgpOufNR4tNaM.pgp
Description: PGP signature


Re: building i386 world on amd64 host: failed @svn

2013-08-15 Thread Jung-uk Kim
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2013-08-15 15:30:49 -0400, Konstantin Belousov wrote:
 On Thu, Aug 15, 2013 at 09:12:52PM +0200, Dimitry Andric wrote:
 On Aug 15, 2013, at 20:36, Konstantin Belousov
 kostik...@gmail.com wrote:
 Does the linux box defaults to pentium or higher for -march ? 
 64 bit atomics cannot be implemented in usermode on i386 on 
 processors which do not have cmpxchg8b instruction.
 
 Ah yes, you are totally right, with -v it gives:
 
 COLLECT_GCC_OPTIONS='-O2' '-S' '-v' '-mtune=generic'
 '-march=i586'
 
 So we should really disable atomics for i486 and lower?  Though I
 have understood that there also some pentiums without
 cmpxchg8b...
 
 I do not think that there was any Pentium-branded CPU which did
 not implemented cmpxchg8b.  Some late 486 did provided cpuid, but I
 am almost certain that they did not have cmpxchg8b (cannot check
 anyway).

It is actually little complicated.

http://www.geoffchappell.com/studies/windows/km/cpu/cx8.htm

Jung-uk Kim
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.20 (FreeBSD)

iQEcBAEBAgAGBQJSDS5AAAoJECXpabHZMqHOGkMIAKEXxd9G0cTwjnMuQFt6D0VP
ba2ZLJa2wXWzYVeelXnRxYtt2BRU8xUzc7YUC86E7pW1AdN1geR0EOt1ggTAVpX4
t1W9k2PsBCfURW+6560m3ze0xfyH66SwLuadyeyQJ0G11XWbAigTRx56j2BLZRth
ghmcOqQS4tfjyDd3uKnU4JTGzRo2irmKlzsoHWuAJJ5R2qoUsr/3cxnRUU2lSBXv
UHx6Ml6VM1OQgEzZkLuLD30JLAYJoCK1n7IKXdUx1cRAs1ZO8uZuMBddp8sLaymB
zdn0bSjBB+vutm4/lhQA38BVZlls1O287rhwb51/3RS3Db1zTDXKw1BYf2Q5YNE=
=wwyz
-END PGP SIGNATURE-
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: building i386 world on amd64 host: failed @svn

2013-07-29 Thread Dmitry Morozovsky
On Sun, 28 Jul 2013, Dmitry Morozovsky wrote:

 on my builder I have consistent error:

Followup on different build environments:

 
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  
 In function `svn_named_atomic__cmpxchg':
 named_atomic.c:(.text+0xed): undefined reference to 
 `__sync_val_compare_and_swap_8'
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  
 In function `svn_named_atomic__add':
 named_atomic.c:(.text+0x193): undefined reference to `__sync_add_and_fetch_8'
 /usr/obj/i386.i386/FreeBSD/pristine/src.current/usr.bin/svn/svn/../lib/libsvn_subr/libsvn_subr.a(named_atomic.o):
  
 In function `svn_named_atomic__write':
 named_atomic.c:(.text+0x1f3): undefined reference to 
 `__sync_lock_test_and_set_8'
 *** Error code 1
 
 Stop.
 bmake: stopped in /FreeBSD/pristine/src.current/usr.bin/svn/svn
 *** Error code 1
 
 host is at contemporary stable/9:
 
 FreeBSD castor.rinet.ru 9.1-STABLE FreeBSD 9.1-STABLE #1 r252026: Thu Jun 20 
 15:04:35 MSK 2013 ma...@castor.rinet.ru:/usr/obj/usr/src/sys/CASTOR  amd64
 
 the build line is
 
 make buildworld __MAKE_CONF=/dev/null TARGET=i386
 
 and no, cleaning /usr/obj/i386.i386 does not help.
 
 On the same time, tinderbox.freebsd.org does not see this.
 
 Any hints?  Thanks!

The problem does not manifest itself on
- TARGET=i386 build on ref10-amd64 box
- build on 9-i386 jail on my 9-amd64 builder

(while now there is watchdog' breakage with signedness, usr.bin/svn builds 
there without nasty atomics error)

-- 
Sincerely,
D.Marck [DM5020, MCK-RIPE, DM3-RIPN]
[ FreeBSD committer: ma...@freebsd.org ]

*** Dmitry Morozovsky --- D.Marck --- Wild Woozle --- ma...@rinet.ru ***

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org