[PATCH] D30025: [compiler-rt] [builtins] Fix building atomic.c with GCC

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 15 23:14:10 PST 2017


mgorny created this revision.
Herald added a subscriber: dberris.

Make the use of #pragma redefine_extname and appropriate renames of
builtins conditional to using clang. GCC used not to support it outside
Solaris and currently seems to be very restrictive on applying it.
In other words, it does not work for me with GCC 5.4.0 and the built
libraries use the 'internal' names.

On the other hand, GCC does not have any restrictions on redefining
builtins. So instead of trying to figure out how to make the #pragma
work, it is simpler to make the rename conditional to clang.


Repository:
  rL LLVM

https://reviews.llvm.org/D30025

Files:
  lib/builtins/atomic.c


Index: lib/builtins/atomic.c
===================================================================
--- lib/builtins/atomic.c
+++ lib/builtins/atomic.c
@@ -30,12 +30,17 @@
 
 #include "assembly.h"
 
+#ifdef __clang__
 // Clang objects if you redefine a builtin.  This little hack allows us to
 // define a function with the same name as an intrinsic.
-#pragma redefine_extname __atomic_load_c SYMBOL_NAME(__atomic_load)
-#pragma redefine_extname __atomic_store_c SYMBOL_NAME(__atomic_store)
-#pragma redefine_extname __atomic_exchange_c SYMBOL_NAME(__atomic_exchange)
-#pragma redefine_extname __atomic_compare_exchange_c SYMBOL_NAME(__atomic_compare_exchange)
+#define ATOMIC_IMPL_SYMBOL(x) x##_c
+#pragma redefine_extname ATOMIC_IMPL_SYMBOL(__atomic_load) SYMBOL_NAME(__atomic_load)
+#pragma redefine_extname ATOMIC_IMPL_SYMBOL(__atomic_store) SYMBOL_NAME(__atomic_store)
+#pragma redefine_extname ATOMIC_IMPL_SYMBOL(__atomic_exchange) SYMBOL_NAME(__atomic_exchange)
+#pragma redefine_extname ATOMIC_IMPL_SYMBOL(__atomic_compare_exchange) SYMBOL_NAME(__atomic_compare_exchange)
+#else
+#define ATOMIC_IMPL_SYMBOL(x) SYMBOL_NAME(x)
+#endif
 
 /// Number of locks.  This allocates one page on 32-bit platforms, two on
 /// 64-bit.  This can be specified externally if a different trade between
@@ -159,7 +164,7 @@
 
 /// An atomic load operation.  This is atomic with respect to the source
 /// pointer only.
-void __atomic_load_c(int size, void *src, void *dest, int model) {
+void ATOMIC_IMPL_SYMBOL(__atomic_load)(int size, void *src, void *dest, int model) {
 #define LOCK_FREE_ACTION(type) \
     *((type*)dest) = __c11_atomic_load((_Atomic(type)*)src, model);\
     return;
@@ -173,7 +178,7 @@
 
 /// An atomic store operation.  This is atomic with respect to the destination
 /// pointer only.
-void __atomic_store_c(int size, void *dest, void *src, int model) {
+void ATOMIC_IMPL_SYMBOL(__atomic_store)(int size, void *dest, void *src, int model) {
 #define LOCK_FREE_ACTION(type) \
     __c11_atomic_store((_Atomic(type)*)dest, *(type*)dest, model);\
     return;
@@ -190,7 +195,7 @@
 /// they  are not, then this stores the current value from *ptr in *expected.
 ///
 /// This function returns 1 if the exchange takes place or 0 if it fails. 
-int __atomic_compare_exchange_c(int size, void *ptr, void *expected,
+int ATOMIC_IMPL_SYMBOL(__atomic_compare_exchange)(int size, void *ptr, void *expected,
     void *desired, int success, int failure) {
 #define LOCK_FREE_ACTION(type) \
   return __c11_atomic_compare_exchange_strong((_Atomic(type)*)ptr, (type*)expected,\
@@ -211,7 +216,7 @@
 
 /// Performs an atomic exchange operation between two pointers.  This is atomic
 /// with respect to the target address.
-void __atomic_exchange_c(int size, void *ptr, void *val, void *old, int model) {
+void ATOMIC_IMPL_SYMBOL(__atomic_exchange)(int size, void *ptr, void *val, void *old, int model) {
 #define LOCK_FREE_ACTION(type) \
     *(type*)old = __c11_atomic_exchange((_Atomic(type)*)ptr, *(type*)val,\
         model);\


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30025.88658.patch
Type: text/x-patch
Size: 3030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170216/0dcfbcb4/attachment.bin>


More information about the cfe-commits mailing list