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

undefined reference to `__builtin_ia32_pause' with icc #9081

Closed
mathomp4 opened this issue Jul 1, 2022 · 22 comments
Closed

undefined reference to `__builtin_ia32_pause' with icc #9081

mathomp4 opened this issue Jul 1, 2022 · 22 comments
Assignees
Labels

Comments

@mathomp4
Copy link
Contributor

mathomp4 commented Jul 1, 2022

I did this

Build curl with Intel compilers

I expected the following

Successful compile

curl/libcurl version

curl 7.84.0

operating system

SLES 12 SP5

$ uname -a
Linux borgi037 4.12.14-122.121-default #1 SMP Wed May 4 10:35:25 UTC 2022 (a686fdb) x86_64 x86_64 x86_64 GNU/Linux

Intel oneAPI 2021.3.0 using the "classic" compilers (icc, icpc, ifort)

What happened

When I tried to build curl with icc I got some errors at the curl link step:

make[4]: Entering directory '/gpfsm/dswdev/gmao_SIteam/Baselibs/ESMA-Baselibs-7.4.0/src/curl/src'
  CCLD     curl
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_cleanup':
easy.c:(.text+0x24): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_sslset':
easy.c:(.text+0xb2): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_easy_init':
easy.c:(.text+0x1138): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_init_mem':
easy.c:(.text+0x1279): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_init':
easy.c:(.text+0x1369): undefined reference to `__builtin_ia32_pause'
Makefile:914: recipe for target 'curl' failed
make[4]: *** [curl] Error 1
make[4]: Leaving directory '/gpfsm/dswdev/gmao_SIteam/Baselibs/ESMA-Baselibs-7.4.0/src/curl/src'
Makefile:1396: recipe for target 'install-recursive' failed

I did see there was a similar issue reported in #9058, so I tried grabbing the changes from #9062 but nothing changed. I think I might need a similar workaround for Intel C.

@mathomp4
Copy link
Contributor Author

mathomp4 commented Jul 1, 2022

And here is the config.log that came from the configure of curl with the #9062 patch:

config.log

@bagder
Copy link
Member

bagder commented Jul 1, 2022

Stupid compilers trying to look like gcc but isn't compatible with gcc...

So something like this?

diff --git a/lib/easy_lock.h b/lib/easy_lock.h
index a4db9fe47..bcd4353b3 100644
--- a/lib/easy_lock.h
+++ b/lib/easy_lock.h
@@ -47,11 +47,13 @@
 #ifndef __has_builtin
 #define __has_builtin(x) 0
 #endif
 
 /* if GCC on i386/x86_64 or if the built-in is present */
-#if ( (defined(__GNUC__) && !defined(__clang__)) &&     \
+#if ( (defined(__GNUC__) &&                             \
+       !defined(__clang__) &&                           \
+       !defined(__INTEL_COMPILER)) &&                   \
       (defined(__i386__) || defined(__x86_64__))) ||    \
   __has_builtin(__builtin_ia32_pause)
 #define HAVE_BUILTIN_IA32_PAUSE
 #endif

@mathomp4
Copy link
Contributor Author

mathomp4 commented Jul 1, 2022

Hmm. Nope:

  CCLD     curl
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_cleanup':
easy.c:(.text+0x24): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_sslset':
easy.c:(.text+0xb2): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_easy_init':
easy.c:(.text+0x1138): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_init_mem':
easy.c:(.text+0x1279): undefined reference to `__builtin_ia32_pause'
ld: ../lib/.libs/libcurl.a(libcurl_la-easy.o): in function `curl_global_init':
easy.c:(.text+0x1369): undefined reference to `__builtin_ia32_pause'
Makefile:914: recipe for target 'curl' failed
make[4]: *** [curl] Error 1
make[4]: Leaving directory '/gpfsm/dswdev/gmao_SIteam/Baselibs/ESMA-Baselibs-7.4.0/src/curl/src'

but maybe I have the patch wrong. Here is what I have versus 7.84.0:

diff --git a/lib/easy_lock.h b/lib/easy_lock.h
index 819f50ce8..16c7110fb 100644
--- a/lib/easy_lock.h
+++ b/lib/easy_lock.h
@@ -40,6 +40,20 @@
 #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 GCC on i386/x86_64 or if the built-in is present */
+#if ( (defined(__GNUC__) &&                             \
+       !defined(__clang__) &&                           \
+       !defined(__INTEL_COMPILER)) &&                   \
+      (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(;;) {
@@ -48,7 +62,7 @@ static inline void curl_simple_lock_lock(curl_simple_lock *lock)
     /* 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");

@bagder
Copy link
Member

bagder commented Jul 1, 2022

I suppose then that your compiler doesn't define __INTEL_COMPILER ? According to the predef docs the Intel compiler generally does...

@mathomp4
Copy link
Contributor Author

mathomp4 commented Jul 5, 2022

I suppose then that your compiler doesn't define __INTEL_COMPILER ? According to the predef docs the Intel compiler generally does...

No, it does:

❯ cat helloworld.c
#include <stdio.h>
int main() {
   printf("Hello, World!\n");
#ifdef __INTEL_COMPILER
   printf("I run Intel!\n");
#endif
   return 0;
}
❯ icc helloworld.c && ./a.out
Hello, World!
I run Intel!
❯ clang helloworld.c && ./a.out
Hello, World!

@bagder
Copy link
Member

bagder commented Jul 5, 2022

Ok, but can you understand then why my proposed #ifdef-thing didn't work?

@mathomp4
Copy link
Contributor Author

mathomp4 commented Jul 5, 2022

Ok, but can you understand then why my proposed #ifdef-thing didn't work?

Well, it looks like icc defines a lot:

❯ cat curl_c_oddity.c
#include <stdio.h>

int main() {

#ifndef __has_builtin
#define __has_builtin(x) 0
#endif

#if defined(__INTEL_COMPILER)
   printf("__INTEL_COMPILER\n");
#endif

#if defined(__GNUC__)
   printf("__GNUC__\n");
#endif

#if defined(__clang__)
   printf("__clang__\n");
#endif

#if __has_builtin(__builtin_ia32_pause)
   printf("__builtin_ia32_pause: %d\n", __has_builtin(__builtin_ia32_pause));
#endif

#if ( (defined(__GNUC__) &&                             \
       !defined(__clang__) &&                           \
       !defined(__INTEL_COMPILER)) &&                   \
      (defined(__i386__) || defined(__x86_64__))) ||    \
  __has_builtin(__builtin_ia32_pause)
   printf("HAVE_BUILTIN_IA32_PAUSE\n");
#else
   printf("Nope\n");
#endif

   return 0;
}
$ icc curl_c_oddity.c && ./a.out
__INTEL_COMPILER
__GNUC__
__builtin_ia32_pause: 1
HAVE_BUILTIN_IA32_PAUSE

And on macOS:

❯ icc curl_c_oddity.c&& ./a.out
__INTEL_COMPILER
__GNUC__
__clang__
__builtin_ia32_pause: 1
HAVE_BUILTIN_IA32_PAUSE

I think Intel C/C++ define a lot of GNU like macros underneath.

Weird thing is it's saying that __builtin_ia32_pause is defined. 🤷🏼

When/If you run Intel C locally, do you see this odd behavior (not sure if you have an Intel oneAPI test in your CI)? Or is it somehow due to how it's installed on my machines?

@gvanem
Copy link
Contributor

gvanem commented Jul 5, 2022

This can split out all the built-ins: icc -Xclang -dM -E - < /dev/null | sort

@mathomp4
Copy link
Contributor Author

mathomp4 commented Jul 6, 2022

@gvanem Well, icc on my machines weren't happy with -Xclang. On my mac:

❯ icc -Xclang -dM -E - < /dev/null | sort
icc: command line warning #10148: option '-Xclang -dM' not supported
# 1 "-"

and Linux was much the same. If I remove -Xclang I get:

$ icc -dM -E - < /dev/null | sort
#define _GLIBCXX_NO_BUILTIN_HAS_UNIQ_OBJ_REP 1
#define _GLIBCXX_NO_BUILTIN_LAUNDER 1
#define _LP64 1
#define _STDC_PREDEF_H 1
#define __ATOMIC_ACQUIRE 2
#define __ATOMIC_ACQ_REL 4
#define __ATOMIC_CONSUME 1
#define __ATOMIC_HLE_ACQUIRE 65536
#define __ATOMIC_HLE_RELEASE 131072
#define __ATOMIC_RELAXED 0
#define __ATOMIC_RELEASE 3
#define __ATOMIC_SEQ_CST 5
#define __BIGGEST_ALIGNMENT__ 64
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __CHAR16_TYPE__ unsigned short
#define __CHAR32_TYPE__ unsigned int
#define __CHAR_BIT__ 8
#define __DATE__ "Jul  6 2022"
#define __DBL_DECIMAL_DIG__ 17
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __DBL_DIG__ 15
#define __DBL_EPSILON__ 2.2204460492503131e-16
#define __DBL_HAS_DENORM__ 1
#define __DBL_HAS_INFINITY__ 1
#define __DBL_HAS_QUIET_NAN__ 1
#define __DBL_MANT_DIG__ 53
#define __DBL_MAX_10_EXP__ 308
#define __DBL_MAX_EXP__ 1024
#define __DBL_MAX__ 1.7976931348623157e+308
#define __DBL_MIN_10_EXP__ -307
#define __DBL_MIN_EXP__ -1021
#define __DBL_MIN__ 2.2250738585072014e-308
#define __DEC128_EPSILON__ 1E-33DL
#define __DEC128_MANT_DIG__ 34
#define __DEC128_MAX_EXP__ 6145
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __DEC128_MIN_EXP__ -6142
#define __DEC128_MIN__ 1E-6143DL
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __DEC32_EPSILON__ 1E-6DF
#define __DEC32_MANT_DIG__ 7
#define __DEC32_MAX_EXP__ 97
#define __DEC32_MAX__ 9.999999E96DF
#define __DEC32_MIN_EXP__ -94
#define __DEC32_MIN__ 1E-95DF
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define __DEC64_EPSILON__ 1E-15DD
#define __DEC64_MANT_DIG__ 16
#define __DEC64_MAX_EXP__ 385
#define __DEC64_MAX__ 9.999999999999999E384DD
#define __DEC64_MIN_EXP__ -382
#define __DEC64_MIN__ 1E-383DD
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __DECIMAL_BID_FORMAT__ 1
#define __DECIMAL_DIG__ 21
#define __DEC_EVAL_METHOD__ 2
#define __EDG_PTRDIFF_TYPE__ long
#define __EDG_SIZE_TYPE__ unsigned long
#define __EDG_VERSION__ 501
#define __EDG__ 1
#define __ELF__ 1
#define __FINITE_MATH_ONLY__ 0
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __FLT128_DECIMAL_DIG__ 36
#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L
#define __FLT128_DIG__ 33
#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34L
#define __FLT128_HAS_DENORM__ 1
#define __FLT128_HAS_INFINITY__ 1
#define __FLT128_HAS_QUIET_NAN__ 1
#define __FLT128_MANT_DIG__ 113
#define __FLT128_MAX_10_EXP__ 4932
#define __FLT128_MAX_EXP__ 16384
#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932L
#define __FLT128_MIN_10_EXP__ -4931
#define __FLT128_MIN_EXP__ -16381
#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932L
#define __FLT_DECIMAL_DIG__ 9
#define __FLT_DENORM_MIN__ 1.40129846e-45F
#define __FLT_DIG__ 6
#define __FLT_EPSILON__ 1.19209290e-7F
#define __FLT_HAS_DENORM__ 1
#define __FLT_HAS_INFINITY__ 1
#define __FLT_HAS_QUIET_NAN__ 1
#define __FLT_MANT_DIG__ 24
#define __FLT_MAX_10_EXP__ 38
#define __FLT_MAX_EXP__ 128
#define __FLT_MAX__ 3.40282347e+38F
#define __FLT_MIN_10_EXP__ -37
#define __FLT_MIN_EXP__ -125
#define __FLT_MIN__ 1.17549435e-38F
#define __FLT_RADIX__ 2
#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
#define __GCC_ATOMIC_INT_LOCK_FREE 2
#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
#define __GCC_ATOMIC_LONG_LOCK_FREE 2
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __GNUC_GNU_INLINE__ 1
#define __GNUC_MINOR__ 1
#define __GNUC_PATCHLEVEL__ 0
#define __GNUC_STDC_INLINE__ 1
#define __GNUC__ 10
#define __GXX_ABI_VERSION 1010
#define __ICC 2021
#define __INT16_MAX__ 32767
#define __INT16_TYPE__ short
#define __INT32_MAX__ 2147483647
#define __INT32_TYPE__ int
#define __INT64_MAX__ 9223372036854775807L
#define __INT64_TYPE__ long
#define __INT8_MAX__ 127
#define __INT8_TYPE__ signed char
#define __INTEL_COMPILER 2021
#define __INTEL_COMPILER_BUILD_DATE 20210609
#define __INTEL_COMPILER_UPDATE 3
#define __INTEL_OFFLOAD 1
#define __INTEL_RTTI__ 1
#define __INTMAX_MAX__ 0x7fffffffffffffff
#define __INTMAX_TYPE__ long int
#define __INTPTR_MAX__ 9223372036854775807L
#define __INTPTR_TYPE__ long
#define __INT_FAST16_MAX__ 9223372036854775807L
#define __INT_FAST16_TYPE__ long
#define __INT_FAST32_MAX__ 9223372036854775807L
#define __INT_FAST32_TYPE__ long
#define __INT_FAST64_MAX__ 9223372036854775807L
#define __INT_FAST64_TYPE__ long
#define __INT_FAST8_MAX__ 127
#define __INT_FAST8_TYPE__ char
#define __INT_LEAST16_MAX__ 32767
#define __INT_LEAST16_TYPE__ short
#define __INT_LEAST32_MAX__ 2147483647
#define __INT_LEAST32_TYPE__ int
#define __INT_LEAST64_MAX__ 9223372036854775807L
#define __INT_LEAST64_TYPE__ long
#define __INT_LEAST8_MAX__ 127
#define __INT_LEAST8_TYPE__ char
#define __INT_MAX__ 2147483647
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
#define __LDBL_DIG__ 18
#define __LDBL_EPSILON__ 1.08420217248550443401e-19L
#define __LDBL_HAS_DENORM__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __LDBL_HAS_QUIET_NAN__ 1
#define __LDBL_MANT_DIG__ 64
#define __LDBL_MAX_10_EXP__ 4932
#define __LDBL_MAX_EXP__ 16384
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __LDBL_MIN_10_EXP__ -4931
#define __LDBL_MIN_EXP__ -16381
#define __LDBL_MIN__ 3.36210314311209350626e-4932L
#define __LONG_DOUBLE_SIZE__ 80
#define __LONG_LONG_MAX__ 0x7fffffffffffffff
#define __LONG_MAX__ 9223372036854775807L
#define __LP64__ 1
#define __MMX__ 1
#define __NO_MATH_INLINES 1
#define __NO_STRING_INLINES 1
#define __OPTIMIZE__ 1
#define __ORDER_BIG_ENDIAN__ 4321
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __ORDER_PDP_ENDIAN__ 3412
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __PTRDIFF_MAX__ 9223372036854775807L
#define __PTRDIFF_TYPE__ long
#define __QMSPP_ 1
#define __REGISTER_PREFIX__
#define __SCHAR_MAX__ 127
#define __SHRT_MAX__ 32767
#define __SIGNED_CHARS__ 1
#define __SIG_ATOMIC_MAX__ 2147483647
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define __SIG_ATOMIC_TYPE__ int
#define __SIZEOF_DOUBLE__ 8
#define __SIZEOF_FLOAT128__ 16
#define __SIZEOF_FLOAT80__ 12
#define __SIZEOF_FLOAT__ 4
#define __SIZEOF_INT128__ 16
#define __SIZEOF_INT__ 4
#define __SIZEOF_LONG_DOUBLE__ 16
#define __SIZEOF_LONG_LONG__ 8
#define __SIZEOF_LONG__ 8
#define __SIZEOF_POINTER__ 8
#define __SIZEOF_PTRDIFF_T__ 8
#define __SIZEOF_SHORT__ 2
#define __SIZEOF_SIZE_T__ 8
#define __SIZEOF_WCHAR_T__ 4
#define __SIZEOF_WINT_T__ 4
#define __SIZE_MAX__ 18446744073709551615UL
#define __SIZE_TYPE__ unsigned long
#define __SSE2_MATH__ 1
#define __SSE2__ 1
#define __SSE_MATH__ 1
#define __SSE__ 1
#define __STDC_DEC_FP__ 200704L
#define __STDC_HOSTED__ 1
#define __STDC_IEC_559_COMPLEX__ 1
#define __STDC_IEC_559__ 1
#define __STDC_ISO_10646__ 201304L
#define __STDC_NO_THREADS__ 1
#define __STDC_UTF_16__ 1
#define __STDC_UTF_32__ 1
#define __STDC_VERSION__ 201112L
#define __STDC__ 1
#define __TIME__ "08:15:46"
#define __UINT16_MAX__ 65535
#define __UINT16_TYPE__ unsigned short
#define __UINT32_MAX__ 4294967295U
#define __UINT32_TYPE__ unsigned int
#define __UINT64_MAX__ 18446744073709551615UL
#define __UINT64_TYPE__ unsigned long
#define __UINT8_MAX__ 255
#define __UINT8_TYPE__ unsigned char
#define __UINTMAX_MAX__ 0xffffffffffffffff
#define __UINTMAX_TYPE__ long unsigned int
#define __UINTPTR_MAX__ 18446744073709551615UL
#define __UINTPTR_TYPE__ unsigned long
#define __UINT_FAST16_MAX__ 18446744073709551615UL
#define __UINT_FAST16_TYPE__ unsigned long
#define __UINT_FAST32_MAX__ 18446744073709551615UL
#define __UINT_FAST32_TYPE__ unsigned long
#define __UINT_FAST64_MAX__ 18446744073709551615UL
#define __UINT_FAST64_TYPE__ unsigned long
#define __UINT_FAST8_MAX__ 255
#define __UINT_FAST8_TYPE__ unsigned char
#define __UINT_LEAST16_MAX__ 65535
#define __UINT_LEAST16_TYPE__ unsigned short
#define __UINT_LEAST32_MAX__ 4294967295U
#define __UINT_LEAST32_TYPE__ unsigned int
#define __UINT_LEAST64_MAX__ 18446744073709551615UL
#define __UINT_LEAST64_TYPE__ unsigned long
#define __UINT_LEAST8_MAX__ 255
#define __UINT_LEAST8_TYPE__ unsigned char
#define __USER_LABEL_PREFIX__
#define __VERSION__ "Intel(R) C++ gcc 10.1 mode"
#define __WCHAR_MAX__ 2147483647
#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)
#define __WCHAR_TYPE__ int
#define __WINT_MAX__ 4294967295U
#define __WINT_MIN__ 0U
#define __WINT_TYPE__ unsigned int
#define __amd64 1
#define __amd64__ 1
#define __cilk 200
#define __gnu_linux__ 1
#define __linux 1
#define __linux__ 1
#define __pentium4 1
#define __pentium4__ 1
#define __tune_pentium4__ 1
#define __unix 1
#define __unix__ 1
#define __x86_64 1
#define __x86_64__ 1
#define linux 1
#define unix 1

@gvanem
Copy link
Contributor

gvanem commented Jul 6, 2022

My Intel Compiler is clang/LLVM based, so no #define __llvm__ 1 could be important to your issue.

@mathomp4
Copy link
Contributor Author

mathomp4 commented Jul 6, 2022

@gvanem Ah. Yes, I'm not using icx at all. Still using the "classic" icc. (The main reason is that "new" ifx Fortran compiler still doesn't work with our Fortran code. Fun compiler errors!)

@bagder
Copy link
Member

bagder commented Jul 10, 2022

When/If you run Intel C locally, do you see this odd behavior (not sure if you have an Intel oneAPI test in your CI)? Or is it somehow due to how it's installed on my machines?

We don't have any Intel compilers in the CI builds and I don't have it installed anywhere locally either. Clearly this problem is either a problem in your install or a bug in the compiler. If the latter, I presume we should work around it.

Maybe like this?

--- a/lib/easy_lock.h
+++ b/lib/easy_lock.h
@@ -59,17 +59,23 @@ typedef PVOID SRWLOCK, *PSRWLOCK;
 /* a clang-thing */
 #ifndef __has_builtin
 #define __has_builtin(x) 0
 #endif
 
+#ifndef __INTEL_COMPILER
+/* The Intel compiler tries to look like GCC *and* clang *and* lies in its
+   __has_builtin() function, so override it. */
+
 /* if GCC on i386/x86_64 or if the built-in is present */
 #if ( (defined(__GNUC__) && !defined(__clang__)) &&     \
       (defined(__i386__) || defined(__x86_64__))) ||    \
   __has_builtin(__builtin_ia32_pause)
 #define HAVE_BUILTIN_IA32_PAUSE
 #endif
 
+#endif
+
 static inline void curl_simple_lock_lock(curl_simple_lock *lock)
 {
   for(;;) {
     if(!atomic_exchange_explicit(lock, true, memory_order_acquire))
       break;

@mathomp4
Copy link
Contributor Author

Well...something happened, but maybe I did things wrong. I have this difference from 7.84.0:

--- a/lib/easy_lock.h
+++ b/lib/easy_lock.h
@@ -40,6 +40,24 @@
 #define curl_simple_lock atomic_bool
 #define CURL_SIMPLE_LOCK_INIT false

+/* a clang-thing */
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
+#ifndef __INTEL_COMPILER
+/* The Intel compiler tries to look like GCC *and* clang *and* lies in its
+   __has_builtin() function, so override it. */
+
+/* if GCC on i386/x86_64 or if the built-in is present */
+#if ( (defined(__GNUC__) && !defined(__clang__)) &&     \
+      (defined(__i386__) || defined(__x86_64__))) ||    \
+  __has_builtin(__builtin_ia32_pause)
+#define HAVE_BUILTIN_IA32_PAUSE
+#endif
+
+#endif
+
 static inline void curl_simple_lock_lock(curl_simple_lock *lock)
 {
   for(;;) {
@@ -48,7 +66,7 @@ static inline void curl_simple_lock_lock(curl_simple_lock *lock)
     /* 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");

and now the error is:

  CC       libcurl_la-ftp.lo
In file included from easy.c(89):
easy_lock.h(74): error #266: function "sched_yield" declared implicitly
        sched_yield();
        ^

compilation aborted for easy.c (code 2)
Makefile:1911: recipe for target 'libcurl_la-easy.lo' failed

Did I maybe miss something in my changes?

@mathomp4
Copy link
Contributor Author

Note at the end of my config.log I do see:

#define HAVE_SCHED_YIELD 1

so it's like configure was happy to say we have it.

@mathomp4
Copy link
Contributor Author

Hmm. And I see a similar issue in #9136

@jay
Copy link
Member

jay commented Jul 11, 2022

Hmm. And I see a similar issue in #9136

FYI I just updated that:

Try curl from master. I think this was fixed in #9054.

@mathomp4
Copy link
Contributor Author

Try curl from master. I think this was fixed in #9054.

Ahhh. That got it!

With this:

--- a/lib/easy_lock.h
+++ b/lib/easy_lock.h
@@ -36,10 +36,31 @@

 #elif defined (HAVE_ATOMIC)
 #include <stdatomic.h>
+#if defined(HAVE_SCHED_YIELD)
+#include <sched.h>
+#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
+
+#ifndef __INTEL_COMPILER
+/* The Intel compiler tries to look like GCC *and* clang *and* lies in its
+   __has_builtin() function, so override it. */
+
+/* if GCC on i386/x86_64 or if the built-in is present */
+#if ( (defined(__GNUC__) && !defined(__clang__)) &&     \
+      (defined(__i386__) || defined(__x86_64__))) ||    \
+  __has_builtin(__builtin_ia32_pause)
+#define HAVE_BUILTIN_IA32_PAUSE
+#endif
+
+#endif
+
 static inline void curl_simple_lock_lock(curl_simple_lock *lock)
 {
   for(;;) {
@@ -48,7 +69,7 @@ static inline void curl_simple_lock_lock(curl_simple_lock *lock)
     /* 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");

I have a curl! Moreover, I have a curl that can download a tarball, so it's a curl that does something!

Thanks!

(NB: If it would be useful to add Intel to your CI system, I've done that in projects before and it's helped us out with weird Intel things. That said, the curl CI seems to be pretty comprehensive, so I'm not sure where to start without some guidance. 😄 )

@bagder
Copy link
Member

bagder commented Jul 12, 2022

If it would be useful to add Intel to your CI system, I've done that in projects before

Oh yes, I think it would indeed be very useful! Would you like to make an attempt?

bagder added a commit that referenced this issue Jul 12, 2022
The Intel compiler tries to look like GCC *and* clang *and* it lies in
its __has_builtin() function (returns true when it should return false),
so override it.

Fixes #9081
Reported-by: Matthew Thompson
@bagder bagder self-assigned this Jul 12, 2022
@mathomp4
Copy link
Contributor Author

If it would be useful to add Intel to your CI system, I've done that in projects before

Oh yes, I think it would indeed be very useful! Would you like to make an attempt?

I'll give it a go!

@mathomp4
Copy link
Contributor Author

@bagder Well, good news is I am close. Bad news is the CI build is dying. Weird thing is, it's dying before the part where I'd expect (aka at link since #9144 isn't in). Namely it is doing:

libtool: compile:  icc -DHAVE_CONFIG_H -I../include -I../lib -I../lib -DBUILDING_LIBCURL -DCURL_HIDDEN_SYMBOLS -we140,147,165,266 -wd279,981,1469 -Wall -w2 -Wcheck -Wcomment -Wdeprecated -Wmissing-prototypes -Wp64 -Wpointer-arith -Wreturn-type -Wshadow -Wuninitialized -Wunused-function -fvisibility=hidden -std=gnu89 -g -O0 -fno-omit-frame-pointer -fno-strict-aliasing -fp-model precise -shared-intel -pthread -Werror -MT libcurl_la-asyn-thread.lo -MD -MP -MF .deps/libcurl_la-asyn-thread.Tpo -c asyn-thread.c  -fPIC -DPIC -o .libs/libcurl_la-asyn-thread.o
icc: command line remark #10010: option '-we140,147,165,266' is deprecated and will be removed in a future release. See '-help deprecated'
icc: command line remark #10010: option '-wd279,981,1469' is deprecated and will be removed in a future release. See '-help deprecated'
asyn-thread.c(505): error #188: enumerated type mixed with another type
        result = getaddrinfo_complete(data);
               ^
compilation aborted for asyn-thread.c (code 2)

https://github.com/mathomp4/curl/runs/7306769953?check_suite_focus=true

I have a new job in the queue that should die the same way (I didn't quite follow the curl CI style, so I just renamed some things).

bagder added a commit that referenced this issue Jul 12, 2022
... as the only caller that cares about what it returns assumes that
anyway. This caused icc to warn:

asyn-thread.c(505): error #188: enumerated type mixed with another type
        result = getaddrinfo_complete(data);

Repoorted-by: Matthew Thompson
Bug: #9081 (comment)
@bagder
Copy link
Member

bagder commented Jul 12, 2022

I filed #9146 for that.

@bagder bagder closed this as completed in e0c68f0 Jul 12, 2022
@mathomp4
Copy link
Contributor Author

I filed #9146 for that.

@bagder Thanks. Once it gets in main I'll sync up my fork and branch and try again :)

bagder added a commit that referenced this issue Jul 13, 2022
... as the only caller that cares about what it returns assumes that
anyway. This caused icc to warn:

asyn-thread.c(505): error #188: enumerated type mixed with another type
        result = getaddrinfo_complete(data);

Repoorted-by: Matthew Thompson
Bug: #9081 (comment)
Closes #9146
tldahlgren pushed a commit to spack/spack that referenced this issue Sep 2, 2022
Adding a new version of curl. This addresses issue [9081](curl/curl#9081).
climbfuji pushed a commit to climbfuji/spack that referenced this issue Sep 7, 2022
Adding a new version of curl. This addresses issue [9081](curl/curl#9081).
ma595 pushed a commit to ma595/spack that referenced this issue Sep 13, 2022
Adding a new version of curl. This addresses issue [9081](curl/curl#9081).
climbfuji pushed a commit to climbfuji/spack that referenced this issue Sep 13, 2022
Adding a new version of curl. This addresses issue [9081](curl/curl#9081).
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