<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/15037">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">configure: Autodetect TLS bug on ARM with old gcc and apply workaround<br><br>Check if compiler being used contains the bug. GCC 7.3.0 is the oldest<br>version containing the fix, and version 6.3.0 is known to contain the<br>bug. Bug is only known to appear so far only on ARM32. If the bug is<br>present, gcc will generate a wrong binary which wil lend up segfaulting<br>when accessing TLS (__thread) variables under certain conditions.<br><br>Related: OS#4062<br>Related: SYS#4628<br>Change-Id: I8acc2cf41b73da0c3290f1cefd79f2bc68b0e77d<br>---<br>M configure.ac<br>A m4/check_tls_gcc_arm_bug.m4<br>2 files changed, 31 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/37/15037/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configure.ac b/configure.ac</span><br><span>index d717a0b..3764e29 100644</span><br><span>--- a/configure.ac</span><br><span>+++ b/configure.ac</span><br><span>@@ -122,6 +122,10 @@</span><br><span> </span><br><span> CHECK_TM_INCLUDES_TM_GMTOFF</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+dnl Check if We need to apply workaround for TLS bug on ARM platform for GCC < 7.3.0:</span><br><span style="color: hsl(120, 100%, 40%);">+CHECK_TLS_GCC_ARM_BUG</span><br><span style="color: hsl(120, 100%, 40%);">+CFLAGS="$CFLAGS $TLS_GCC_ARM_BUG_CFLAGS"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> dnl Generate the output</span><br><span> AC_CONFIG_HEADER(config.h)</span><br><span> </span><br><span>diff --git a/m4/check_tls_gcc_arm_bug.m4 b/m4/check_tls_gcc_arm_bug.m4</span><br><span>new file mode 100644</span><br><span>index 0000000..aa93edb</span><br><span>--- /dev/null</span><br><span>+++ b/m4/check_tls_gcc_arm_bug.m4</span><br><span>@@ -0,0 +1,27 @@</span><br><span style="color: hsl(120, 100%, 40%);">+# OS#4062 (https://osmocom.org/issues/4062)</span><br><span style="color: hsl(120, 100%, 40%);">+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81142</span><br><span style="color: hsl(120, 100%, 40%);">+# SYS#4628</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# Check if We need to apply workaround for TLS bug on ARM platform for GCC < 7.3.0.</span><br><span style="color: hsl(120, 100%, 40%);">+# TLS_GCC_ARM_BUG_CFLAGS is filled with required workaround bits if needed.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AC_DEFUN([CHECK_TLS_GCC_ARM_BUG], [</span><br><span style="color: hsl(120, 100%, 40%);">+  TLS_GCC_ARM_BUG_CFLAGS=""</span><br><span style="color: hsl(120, 100%, 40%);">+  AC_MSG_CHECKING([whether to workaround TLS bug in old gcc on ARM platforms])</span><br><span style="color: hsl(120, 100%, 40%);">+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(</span><br><span style="color: hsl(120, 100%, 40%);">+    [[</span><br><span style="color: hsl(120, 100%, 40%);">+    #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Check for ARM 32 bit and gcc smaller than 7.3.0 */</span><br><span style="color: hsl(120, 100%, 40%);">+    /* We need to explicitly exclude GNUC compatible compilers, since they also define GNUC related tokens */</span><br><span style="color: hsl(120, 100%, 40%);">+    #if __arm__ && !defined(__llvm__) && !defined(__INTEL_COMPILER) && GCC_VERSION < 70300</span><br><span style="color: hsl(120, 100%, 40%);">+    #error TLS bug present!</span><br><span style="color: hsl(120, 100%, 40%);">+    #endif</span><br><span style="color: hsl(120, 100%, 40%);">+    ]])],</span><br><span style="color: hsl(120, 100%, 40%);">+    [tls_bug_present=no],</span><br><span style="color: hsl(120, 100%, 40%);">+    [tls_bug_present=yes])</span><br><span style="color: hsl(120, 100%, 40%);">+  AS_IF([test "x$tls_bug_present" = "xyes"],[</span><br><span style="color: hsl(120, 100%, 40%);">+    TLS_GCC_ARM_BUG_CFLAGS="-mtls-dialect=gnu2"</span><br><span style="color: hsl(120, 100%, 40%);">+  ])</span><br><span style="color: hsl(120, 100%, 40%);">+  AC_SUBST([TLS_GCC_ARM_BUG_CFLAGS])</span><br><span style="color: hsl(120, 100%, 40%);">+  AC_MSG_RESULT([$TLS_GCC_ARM_BUG_CFLAGS])</span><br><span style="color: hsl(120, 100%, 40%);">+])</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/15037">change 15037</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/15037"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I8acc2cf41b73da0c3290f1cefd79f2bc68b0e77d </div>
<div style="display:none"> Gerrit-Change-Number: 15037 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>