Skip to content

Commit d2de0bb

Browse files
XrXrnikic
authored andcommittedNov 20, 2024
[compiler-rt] Stop using x86 builtin on AArch64 with GCC (llvm#93890)
Previously, building `multc3.c` on A64 with GCC 7 or up but 9 and lower will attempt to reference `__builtin_copysignq`, an [x86-specific intrinsic][1]: ``` $ gcc -c multc3.c In file included from fp_lib.h:24, from multc3.c:14: multc3.c: In function '__multc3': int_math.h:71:32: warning: implicit declaration of function '__builtin_copysignq'; did you mean '__builtin_copysign'? [-Wimplicit-function-declaration] #define crt_copysignf128(x, y) __builtin_copysignq((x), (y)) ^~~~~~~~~~~~~~~~~~~ ``` This is because `__has_builtin` is from GCC 10, and defined to 0 at the top of int_math.h for affected GCC versions, so the fallback definition is used. But `__builtin_copysignq` is unavailable on A64. Use version detection to find `__builtin_copysignf128` instead. It's available since GCC 7 and [available][2] on both x86 and A64, given this macro is only used when `CRT_HAS_IEEE_TF`. --- I realize this is fixing a problem for an out-of-tree build configuration, but help would be greatly appreciated. Rust [builds](https://github.com/rust-lang/compiler-builtins) `multc3.c` with GCC 8 and this mis-selection is causing [build issues](rust-lang/rust#125619) way downstream. ref: d2ce3e9 [1]: https://gcc.gnu.org/onlinedocs/gcc/x86-Built-in-Functions.html [2]: https://gcc.gnu.org/gcc-7/changes.html (cherry picked from commit 8aa9d62)
1 parent eaa41a3 commit d2de0bb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

‎compiler-rt/lib/builtins/int_math.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@
6565
#define crt_copysign(x, y) __builtin_copysign((x), (y))
6666
#define crt_copysignf(x, y) __builtin_copysignf((x), (y))
6767
#define crt_copysignl(x, y) __builtin_copysignl((x), (y))
68-
#if __has_builtin(__builtin_copysignf128)
68+
// We define __has_builtin to always return 0 for GCC versions below 10,
69+
// but __builtin_copysignf128 is available since version 7.
70+
#if __has_builtin(__builtin_copysignf128) || \
71+
(defined(__GNUC__) && __GNUC__ >= 7)
6972
#define crt_copysignf128(x, y) __builtin_copysignf128((x), (y))
70-
#elif __has_builtin(__builtin_copysignq) || (defined(__GNUC__) && __GNUC__ >= 7)
73+
#elif __has_builtin(__builtin_copysignq)
7174
#define crt_copysignf128(x, y) __builtin_copysignq((x), (y))
7275
#endif
7376
#endif
@@ -80,9 +83,11 @@
8083
#define crt_fabs(x) __builtin_fabs((x))
8184
#define crt_fabsf(x) __builtin_fabsf((x))
8285
#define crt_fabsl(x) __builtin_fabsl((x))
83-
#if __has_builtin(__builtin_fabsf128)
86+
// We define __has_builtin to always return 0 for GCC versions below 10,
87+
// but __builtin_fabsf128 is available since version 7.
88+
#if __has_builtin(__builtin_fabsf128) || (defined(__GNUC__) && __GNUC__ >= 7)
8489
#define crt_fabsf128(x) __builtin_fabsf128((x))
85-
#elif __has_builtin(__builtin_fabsq) || (defined(__GNUC__) && __GNUC__ >= 7)
90+
#elif __has_builtin(__builtin_fabsq)
8691
#define crt_fabsf128(x) __builtin_fabsq((x))
8792
#endif
8893
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.