Skip to content

Commit 7e093ed

Browse files
committed
Better error message if a needed TSan flag is missing
1 parent c2b87d8 commit 7e093ed

File tree

4 files changed

+109
-10
lines changed

4 files changed

+109
-10
lines changed

aclocal.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ m4_include([build-aux/ltoptions.m4])
2626
m4_include([build-aux/ltsugar.m4])
2727
m4_include([build-aux/ltversion.m4])
2828
m4_include([build-aux/lt~obsolete.m4])
29+
m4_include([build-aux/ax_check_compile_flag.m4])
2930

3031
# Macros from the autoconf macro archive
3132
m4_include([build-aux/ax_func_which_gethostbyname_r.m4])

build-aux/ax_check_compile_flag.m4

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8+
#
9+
# DESCRIPTION
10+
#
11+
# Check whether the given FLAG works with the current language's compiler
12+
# or gives an error. (Warnings, however, are ignored)
13+
#
14+
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15+
# success/failure.
16+
#
17+
# If EXTRA-FLAGS is defined, it is added to the current language's default
18+
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
19+
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
20+
# force the compiler to issue an error when a bad flag is given.
21+
#
22+
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23+
#
24+
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25+
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26+
#
27+
# LICENSE
28+
#
29+
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30+
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31+
#
32+
# Copying and distribution of this file, with or without modification, are
33+
# permitted in any medium without royalty provided the copyright notice
34+
# and this notice are preserved. This file is offered as-is, without any
35+
# warranty.
36+
37+
#serial 6
38+
39+
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
40+
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
41+
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
42+
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
43+
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
44+
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
45+
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
46+
[AS_VAR_SET(CACHEVAR,[yes])],
47+
[AS_VAR_SET(CACHEVAR,[no])])
48+
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
49+
AS_VAR_IF(CACHEVAR,yes,
50+
[m4_default([$2], :)],
51+
[m4_default([$3], :)])
52+
AS_VAR_POPDEF([CACHEVAR])dnl
53+
])dnl AX_CHECK_COMPILE_FLAGS

configure

Lines changed: 45 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ oc_dll_ldflags=""
5555
oc_exe_ldflags=""
5656

5757
tsan=false
58-
oc_tsan_cflags="-fsanitize=thread"
59-
6058
# Passed to the linker by ocamlopt when tsan is enabled
61-
59+
oc_tsan_cflags="-fsanitize=thread"
6260
oc_tsan_cppflags="-DWITH_THREAD_SANITIZER"
61+
tsan_distinguish_volatile_cflags=""
6362

6463
# The C# compiler and its flags
6564
CSC=""
@@ -1657,9 +1656,15 @@ AS_IF([$tsan],
16571656
[oc_tsan_cflags="$oc_tsan_cflags -Wno-tsan"])
16581657
AS_CASE([$ocaml_cv_cc_vendor],
16591658
[gcc*],
1660-
[oc_tsan_cflags="$oc_tsan_cflags --param=tsan-distinguish-volatile=1"],
1659+
[tsan_distinguish_volatile_cflags="--param=tsan-distinguish-volatile=1"],
16611660
[clang*],
1662-
[oc_tsan_cflags="$oc_tsan_cflags -mllvm -tsan-distinguish-volatile"])
1661+
[tsan_distinguish_volatile_cflags="-mllvm -tsan-distinguish-volatile"])
1662+
AX_CHECK_COMPILE_FLAG([-fsanitize=thread $tsan_distinguish_volatile_cflags],
1663+
[],
1664+
[AC_MSG_ERROR(m4_normalize([The C compiler does not support the
1665+
`$tsan_distinguish_volatile_cflags' flag. Try upgrading to GCC >= 11, or
1666+
to Clang >= 11.]))], [$warn_error_flag])
1667+
oc_tsan_cflags="$oc_tsan_cflags $tsan_distinguish_volatile_cflags"
16631668
common_cppflags="$common_cppflags $oc_tsan_cppflags"
16641669
native_cflags="$native_cflags $oc_tsan_cflags"
16651670
ocamlc_cflags="$ocamlc_cflags $oc_tsan_cflags"

0 commit comments

Comments
 (0)