Page MenuHomeFreeBSD

compiler-rt: fix compiler rt with CROSS_TOOLCHAIN
AbandonedPublic

Authored by brooks on May 24 2022, 9:48 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 22 2023, 11:23 PM
Unknown Object (File)
Dec 19 2023, 5:01 PM
Unknown Object (File)
Nov 3 2023, 12:13 AM
Unknown Object (File)
Jun 22 2023, 6:29 PM
Unknown Object (File)
May 3 2023, 10:35 PM
Unknown Object (File)
Apr 4 2023, 8:13 PM
Unknown Object (File)
Feb 27 2023, 9:55 PM
Unknown Object (File)
Feb 10 2023, 7:35 PM
Subscribers

Details

Summary

Always fall back to the locked version of atomic_fetch_nand when the
__c11_atomic_fetch_nand builtin isn't available (LLVM prior to 14).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 45710
Build 42598: arc lint + arc unit

Event Timeline

This seems a bit problematic in that the set of available symbols depends on the compiler building the tree. It may be that we want to generate them and emit the function without the if (lockfree(ptr) path instead.

Adding downstream patches is not great but I think in this case it's reasonable. Although maybe upstream would be happy with this too, I'm not sure what the supported compilers for compiler-rt are.

Adding downstream patches is not great but I think in this case it's reasonable. Although maybe upstream would be happy with this too, I'm not sure what the supported compilers for compiler-rt are.

I can submit what ever we decide is the right approach upstream.

This seems a bit problematic in that the set of available symbols depends on the compiler building the tree. It may be that we want to generate them and emit the function without the if (lockfree(ptr) path instead.

An alternative version also compiles:

diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c b/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c
index b8c7f4b0511c..333429751f24 100644
--- a/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c
+++ b/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c
@@ -336,6 +336,7 @@ OPTIMISED_CASES
     return tmp;                                                                \
   }
 
+#if __has_builtin(__c11_atomic_fetch_nand)
 #define ATOMIC_RMW_NAND(n, lockfree, type)                                     \
   type __atomic_fetch_nand_##n(type *ptr, type val, int model) {               \
     if (lockfree(ptr))                                                         \
@@ -347,6 +348,17 @@ OPTIMISED_CASES
     unlock(l);                                                                 \
     return tmp;                                                                \
   }
+#else
+#define ATOMIC_RMW_NAND(n, lockfree, type)                                     \
+  type __atomic_fetch_nand_##n(type *ptr, type val, int model) {               \
+    Lock *l = lock_for_pointer(ptr);                                           \
+    lock(l);                                                                   \
+    type tmp = *ptr;                                                           \
+    *ptr = ~(tmp & val);                                                       \
+    unlock(l);                                                                 \
+    return tmp;                                                                \
+  }
+#endif
 
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, add, +)
 OPTIMISED_CASES
  • Switch to building the locked version

Seems OK to me. I was wondering about trying to reuse the lock version body in the other but I guess the duplication is actually clearer/more maintainable.

This revision is now accepted and ready to land.May 25 2022, 5:42 PM

This LGTM, provided upstream accepts the same patch. :)

Upstream accepted the first version of this patch as https://reviews.llvm.org/D126710