blob: cee20e65499c2fadbea2a0967ecc24ea631d29e2 [file] [log] [blame]
Pau Espin Pedrole188b8c2019-08-05 13:46:33 +02001# OS#4062 (https://osmocom.org/issues/4062)
2# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81142
3# SYS#4628
4
5# Check if We need to apply workaround for TLS bug on ARM platform for GCC < 7.3.0.
6# TLS_GCC_ARM_BUG_CFLAGS is filled with required workaround bits if needed.
7
8AC_DEFUN([CHECK_TLS_GCC_ARM_BUG], [
9 TLS_GCC_ARM_BUG_CFLAGS=""
10 AC_MSG_CHECKING([whether to workaround TLS bug in old gcc on ARM platforms])
11 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
12 [[
13 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
14 /* Check for ARM 32 bit and gcc smaller than 7.3.0 */
15 /* We need to explicitly exclude GNUC compatible compilers, since they also define GNUC related tokens */
16 #if __arm__ && \
17 !defined(__clang__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && \
18 defined(__GNUC__) && GCC_VERSION < 70300
19 #error TLS bug present!
20 #endif
21 ]])],
22 [tls_bug_present=no],
23 [tls_bug_present=yes])
24 AS_IF([test "x$tls_bug_present" = "xyes"],[
25 TLS_GCC_ARM_BUG_CFLAGS="-mtls-dialect=gnu2"
26 ])
27 AC_SUBST([TLS_GCC_ARM_BUG_CFLAGS])
28 AC_MSG_RESULT([$TLS_GCC_ARM_BUG_CFLAGS])
29])
Pau Espin Pedrolafce89d2019-08-06 12:46:46 +020030
31# Allow disabling the check in order to workaround bug by letting user pass
32# CFLAGS="-O0" on toolchains that crash when "-mtls-dialect=gnu2" is used.
33# CFLAGS is updated with workaround if detection is enabled and workaround is needed.
34AC_DEFUN([ARG_ENABLE_DETECT_TLS_GCC_ARM_BUG], [
35 AC_ARG_ENABLE(detect_tls_gcc_arm_bug,
36 [AS_HELP_STRING(
37 [--disable-detect-tls-gcc-arm-bug],
38 [Disable detecting and applying workaround for TLS bug on ARM platform for GCC < 7.3.0]
39 )],
40 [detect_tls_gcc_arm_bug=$enableval], [detect_tls_gcc_arm_bug="yes"])
41 if test x"$detect_tls_gcc_arm_bug" = x"yes"; then
42 CHECK_TLS_GCC_ARM_BUG
43 if test "x$TLS_GCC_ARM_BUG_CFLAGS" != "x"; then
44 CFLAGS="$CFLAGS $TLS_GCC_ARM_BUG_CFLAGS"
45 AC_MSG_WARN([Applying workaround for TLS bug on ARM platform for GCC < 7.3.0
46 ($TLS_GCC_ARM_BUG_CFLAGS). On some toolchain versions, ld may
47 crash. In that case you must build with CFLAGS='-O0' and run
48 ./configure with --disable-detect-tls-gcc-arm-bug])
49 fi
50fi
51])