Discussion:
Documentation of __sync builtins unclear on external function callback behavior
Johan Tibell
2014-07-16 22:01:16 UTC
Permalink
The documentation of the __sync atomic builtins [1] state that
Not all operations are supported by all target processors. If a particular operation cannot be implemented on the target processor, a warning is generated and a call an external function is generated. The external function carries the same name as the built-in version, with an additional suffix ā€˜_nā€™ where n is the size of the data type.
I initial read this as a call to some function *defined by GCC* is
being emitted, but I now realize that this can be read as "the caller
is supposed to have defined such a fallback function". Which reading
is correct?

I have some code that fails to compile on i386 with the error

/usr/home/ghc-builder/work/builder/tempbuild/build/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.3.1.0-ghc7.9.20140716.so:
undefined reference to `__sync_fetch_and_add_8'

so I guess that means that GCC is not defining these external fallback
functions?

1. https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/_005f_005fsync-Builtins.html#_005f_005fsync-Builtins

-- Johan
Andrew Haley
2014-07-17 08:26:36 UTC
Permalink
Post by Johan Tibell
The documentation of the __sync atomic builtins [1] state that
Not all operations are supported by all target processors. If a
particular operation cannot be implemented on the target processor,
a warning is generated and a call an external function is
generated. The external function carries the same name as the
built-in version, with an additional suffix ā€˜_nā€™ where n is the
size of the data type.
I initial read this as a call to some function *defined by GCC* is
being emitted, but I now realize that this can be read as "the caller
is supposed to have defined such a fallback function". Which reading
is correct?
The latter. Hwever, in some cases in may not even be possible: the
hardware may be incapable of doing it.
Post by Johan Tibell
I have some code that fails to compile on i386 with the error
undefined reference to `__sync_fetch_and_add_8'
so I guess that means that GCC is not defining these external fallback
functions?
My guess is that you're building for an x86 that can't do it.
-march=i586 ought to work. i386 won't.

Andrew.

Loading...