Change in ...libosmocore[master]: configure: Autodetect TLS bug on ARM with old gcc and apply workaround

pespin gerrit-no-reply at lists.osmocom.org
Tue Aug 6 08:10:48 UTC 2019


pespin has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/libosmocore/+/15037 )

Change subject: configure: Autodetect TLS bug on ARM with old gcc and apply workaround
......................................................................

configure: Autodetect TLS bug on ARM with old gcc and apply workaround

Check if compiler being used contains the bug. GCC 7.3.0 is the oldest
version containing the fix, and version 6.3.0 is known to contain the
bug. Bug is only known to appear so far only on ARM32. If the bug is
present, gcc will generate a wrong binary which wil lend up segfaulting
when accessing TLS (__thread) variables under certain conditions.

Related: OS#4062
Related: SYS#4628
Change-Id: I8acc2cf41b73da0c3290f1cefd79f2bc68b0e77d
---
M configure.ac
A m4/check_tls_gcc_arm_bug.m4
2 files changed, 33 insertions(+), 0 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Hoernchen: Looks good to me, but someone else must approve; Verified
  Jenkins Builder: Verified



diff --git a/configure.ac b/configure.ac
index d717a0b..3764e29 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,6 +122,10 @@
 
 CHECK_TM_INCLUDES_TM_GMTOFF
 
+dnl Check if We need to apply workaround for TLS bug on ARM platform for GCC < 7.3.0:
+CHECK_TLS_GCC_ARM_BUG
+CFLAGS="$CFLAGS $TLS_GCC_ARM_BUG_CFLAGS"
+
 dnl Generate the output
 AC_CONFIG_HEADER(config.h)
 
diff --git a/m4/check_tls_gcc_arm_bug.m4 b/m4/check_tls_gcc_arm_bug.m4
new file mode 100644
index 0000000..73b3e95
--- /dev/null
+++ b/m4/check_tls_gcc_arm_bug.m4
@@ -0,0 +1,29 @@
+# OS#4062 (https://osmocom.org/issues/4062)
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81142
+# SYS#4628
+
+# Check if We need to apply workaround for TLS bug on ARM platform for GCC < 7.3.0.
+# TLS_GCC_ARM_BUG_CFLAGS is filled with required workaround bits if needed.
+
+AC_DEFUN([CHECK_TLS_GCC_ARM_BUG], [
+  TLS_GCC_ARM_BUG_CFLAGS=""
+  AC_MSG_CHECKING([whether to workaround TLS bug in old gcc on ARM platforms])
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+    [[
+    #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+    /* Check for ARM 32 bit and gcc smaller than 7.3.0 */
+    /* We need to explicitly exclude GNUC compatible compilers, since they also define GNUC related tokens */
+    #if __arm__ && \
+        !defined(__clang__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && \
+	defined(__GNUC__) && GCC_VERSION < 70300
+    #error TLS bug present!
+    #endif
+    ]])],
+    [tls_bug_present=no],
+    [tls_bug_present=yes])
+  AS_IF([test "x$tls_bug_present" = "xyes"],[
+    TLS_GCC_ARM_BUG_CFLAGS="-mtls-dialect=gnu2"
+  ])
+  AC_SUBST([TLS_GCC_ARM_BUG_CFLAGS])
+  AC_MSG_RESULT([$TLS_GCC_ARM_BUG_CFLAGS])
+])

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15037
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I8acc2cf41b73da0c3290f1cefd79f2bc68b0e77d
Gerrit-Change-Number: 15037
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190806/d9ab1f65/attachment.html>


More information about the gerrit-log mailing list