Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: use of unknown builtin '__builtin_ia32_pause' #9058

Closed
ryandesign opened this issue Jun 28, 2022 · 3 comments
Closed

error: use of unknown builtin '__builtin_ia32_pause' #9058

ryandesign opened this issue Jun 28, 2022 · 3 comments
Labels

Comments

@ryandesign
Copy link
Contributor

ryandesign commented Jun 28, 2022

I did this

Compile curl

I expected the following

Successful compile

curl/libcurl version

7.84.0

operating system

OS X 10.10
Xcode 7.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)

In file included from easy.c:89:
../lib/easy_lock.h:52:7: error: use of unknown builtin '__builtin_ia32_pause' [-Wimplicit-function-declaration]
      __builtin_ia32_pause();
      ^

https://build.macports.org/builders/ports-10.10_x86_64-builder/builds/188168/steps/install-port/logs/stdio

This problem does not occur on later system such as:

OS X 10.11
Xcode 8.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)

@jay
Copy link
Member

jay commented Jun 28, 2022

Does this work:

diff --git a/lib/easy_lock.h b/lib/easy_lock.h
index 07c85c5..15c6c07 100644
--- a/lib/easy_lock.h
+++ b/lib/easy_lock.h
@@ -52,7 +52,11 @@ static inline void curl_simple_lock_lock(curl_simple_lock *lock)
     while(atomic_load_explicit(lock, memory_order_relaxed)) {
       /* Reduce load (not mandatory) */
 #if defined(__i386__) || defined(__x86_64__)
+#if defined(__GNUC__) && !defined(__llvm__)
       __builtin_ia32_pause();
+#else
+      __asm__ volatile("pause");
+#endif
 #elif defined(__aarch64__)
       __asm__ volatile("yield" ::: "memory");
 #elif defined(HAVE_SCHED_YIELD)

@jay jay added the build label Jun 28, 2022
@jmroot
Copy link

jmroot commented Jun 28, 2022

You could keep using the builtin with clang versions that support it by checking for it with __has_builtin, as described here: https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros

@bagder
Copy link
Member

bagder commented Jun 28, 2022

Then perhaps (also available as #9062)

diff --git a/lib/easy_lock.h b/lib/easy_lock.h
index 07c85c5ff..18d90a4dc 100644
--- a/lib/easy_lock.h
+++ b/lib/easy_lock.h
@@ -41,19 +41,29 @@
 #endif
 
 #define curl_simple_lock atomic_bool
 #define CURL_SIMPLE_LOCK_INIT false
 
+/* a clang-thing */
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
+#if (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) || \
+  __has_builtin(__builtin_ia32_pause)
+#define HAVE_BUILTIN_IA32_PAUSE
+#endif
+
 static inline void curl_simple_lock_lock(curl_simple_lock *lock)
 {
   for(;;) {
     if(!atomic_exchange_explicit(lock, true, memory_order_acquire))
       break;
     /* Reduce cache coherency traffic */
     while(atomic_load_explicit(lock, memory_order_relaxed)) {
       /* Reduce load (not mandatory) */
-#if defined(__i386__) || defined(__x86_64__)
+#ifdef HAVE_BUILTIN_IA32_PAUSE
       __builtin_ia32_pause();
 #elif defined(__aarch64__)
       __asm__ volatile("yield" ::: "memory");
 #elif defined(HAVE_SCHED_YIELD)
       sched_yield();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants