Quantcast

How to disable built-in?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to disable built-in?

Dmitri Shubin
Hello!

When building Berkeley DB (checked 4.8.30 and 5.1.25) with clang (trunk)
I got the following error:

In file included from
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/mutex/mut_pthread.c:11:
In file included from ./db_int.h:999:
In file included from
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/mutex.h:15:
In file included from
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/mutex_int.h:12:
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/atomic.h:179:19:
error: definition of builtin function '__atomic_compare_exchange'
static inline int __atomic_compare_exchange(
                   ^
1 error generated.

AFAIU this built-in was added rather recently since I was able to build
it with clang a month or so ago.

Is there any way to disable this built-in?
'-fno-builtin' doesn't help.

(Yes, I know that it's bad idea to start identifiers with underscores)
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to disable built-in?

David Chisnall-2
This builtin is also present in GCC 4.7.  I suspect that the code brackets it in a version check that tests for a GCC version >= 4.7.  Since clang reports the GCC version 4.2, this will fail.  

The correct fix is to wrap the check in !__has_builtin(__atomic_compare_exchange), rather than a specific compiler version.  A more hacky work-around would be to #undef the GCC version macros before including this header and re#define them as gcc 4.7.  

David

On 24 Apr 2012, at 10:21, Dmitri Shubin wrote:

> Hello!
>
> When building Berkeley DB (checked 4.8.30 and 5.1.25) with clang (trunk)
> I got the following error:
>
> In file included from
> /export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/mutex/mut_pthread.c:11:
> In file included from ./db_int.h:999:
> In file included from
> /export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/mutex.h:15:
> In file included from
> /export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/mutex_int.h:12:
> /export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/atomic.h:179:19:
> error: definition of builtin function '__atomic_compare_exchange'
> static inline int __atomic_compare_exchange(
>                   ^
> 1 error generated.
>
> AFAIU this built-in was added rather recently since I was able to build
> it with clang a month or so ago.
>
> Is there any way to disable this built-in?
> '-fno-builtin' doesn't help.
>
> (Yes, I know that it's bad idea to start identifiers with underscores)
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to disable built-in?

Dmitri Shubin
On 24.04.2012 15:48, David Chisnall wrote:
> This builtin is also present in GCC 4.7.  I suspect that the code brackets it in a version check that tests for a GCC version>= 4.7.  Since clang reports the GCC version 4.2, this will fail.
No, in fact it has brackets for (X86 AND GCC):

#if defined(HAVE_ATOMIC_X86_GCC_ASSEMBLY)
/* x86/x86_64 gcc  */
...
/*
  * x86/gcc Compare exchange for shared latches. i486+
  *      Returns 1 for success, 0 for failure
  *
  * GCC 4.1+ has an equivalent  __sync_bool_compare_and_swap() as well as
  * __sync_val_compare_and_swap() which returns the value read from *dest
  * http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
  * which configure could be changed to use.
  */
static inline int __atomic_compare_exchange(
         db_atomic_t *p, atomic_value_t oldval, atomic_value_t newval)
{
...
}
#endif

And check for x86/gcc looks like:

if test "$db_cv_atomic" = no; then
         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
{

         #if ((defined(i386) || defined(__i386__)) && defined(__GNUC__))
                 exit(0);
         #elif ((defined(x86_64) || defined(__x86_64__)) &&
defined(__GNUC__))
                 exit(0);
         #else
                 FAIL TO COMPILE/LINK
         #endif

   ;
   return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
   db_cv_atomic="x86/gcc-assembly"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi


> The correct fix is to wrap the check in !__has_builtin(__atomic_compare_exchange), rather than a specific compiler version.  A more hacky work-around would be to #undef the GCC version macros before including this header and re#define them as gcc 4.7.
I think __has_builtin() itself should be bracketed by ifdef __GNUC__
(probably with specific version?).

So looks like the easiest way is to rename the function.

Thanks!
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to disable built-in?

Francois Pichet
In reply to this post by Dmitri Shubin



On Tue, Apr 24, 2012 at 5:21 AM, Dmitri Shubin <[hidden email]> wrote:
Hello!

When building Berkeley DB (checked 4.8.30 and 5.1.25) with clang (trunk)
I got the following error:

In file included from
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/mutex/mut_pthread.c:11:
In file included from ./db_int.h:999:
In file included from
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/mutex.h:15:
In file included from
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/mutex_int.h:12:
/export/home/sbn/thd/25/src/thirdparty/BerkeleyDB/5.1.25/src/src/dbinc/atomic.h:179:19:
error: definition of builtin function '__atomic_compare_exchange'
static inline int __atomic_compare_exchange(
                   ^
1 error generated.

AFAIU this built-in was added rather recently since I was able to build
it with clang a month or so ago.

Is there any way to disable this built-in?
'-fno-builtin' doesn't help.

(Yes, I know that it's bad idea to start identifiers with underscores)


So what is the solution to this?
I have out of tree backend with: 
  setOperationAction(ISD::ATOMIC_LOAD_SUB,  MVT::i32, Expand);

Now i am trying to compile the actual implementation with clang :

int32_t __sync_fetch_and_sub_4 (volatile int32_t *ptr, int32_t value, ...)
{
...
}

I get: 
    definition of builtin function '__sync_fetch_and_sub_4'

'-fno-builtin' doesn't help..

How is it possible to compile the builtins implementation with clang?
 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to disable built-in?

Dmitri Shubin
On 05/31/2013 12:40 AM, Francois Pichet wrote:



On Tue, Apr 24, 2012 at 5:21 AM, Dmitri Shubin <[hidden email]> wrote:

...

error: definition of builtin function '__atomic_compare_exchange'
static inline int __atomic_compare_exchange(
                   ^
1 error generated.

...
Is there any way to disable this built-in?
'-fno-builtin' doesn't help.


So what is the solution to this?

Well, I go the easy way and just renamed this function, but AFAIU this won't work in your case.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Loading...