Skip to content

Setting b_sanitize=thread breaks for projects that have Fortran dependencies #15381

@ngoldbaum

Description

@ngoldbaum

Describe the bug

If you try to build a project like SciPy that has a meson build system and Fortran dependencies using gfortran with b_sanitize=thread, you will eventually see an error like:

  ERROR: Linker gfortran does not support sanitizer arguments ['-fsanitize=thread']

To Reproduce
Build SciPy from source using a sanitizer. On my Mac, I can trigger the error with this command inside a source checkout of the SciPy repository:

$ CC=/opt/homebrew/opt/llvm/bin/clang CXX=/opt/homebrew/opt/llvm/bin/clang++ PKG_CONFIG_PATH="/opt/homebrew/opt/openblas/lib/pkgconfig" python -m pip install -v . -C'setup-args=-Db_sanitize=thread'

After installing llvm, gfortran, and openblas via homebrew.

Details
  Running command Preparing metadata (pyproject.toml)
  + meson setup /Users/goldbaum/Documents/scipy /Users/goldbaum/Documents/scipy/.mesonpy-vh4wyhe9 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md -Db_sanitize=thread --native-file=/Users/goldbaum/Documents/scipy/.mesonpy-vh4wyhe9/meson-python-native-file.ini
  The Meson build system
  Version: 1.10.0
  Source dir: /Users/goldbaum/Documents/scipy
  Build dir: /Users/goldbaum/Documents/scipy/.mesonpy-vh4wyhe9
  Build type: native build
  Project name: scipy
  Project version: 1.17.0.dev0+git20250716.6ed0250
  C compiler for the host machine: /opt/homebrew/opt/llvm/bin/clang (clang 21.1.7 "Homebrew clang version 21.1.7")
  C linker for the host machine: /opt/homebrew/opt/llvm/bin/clang ld64 1230.1
  C++ compiler for the host machine: /opt/homebrew/opt/llvm/bin/clang++ (clang 21.1.7 "Homebrew clang version 21.1.7")
  C++ linker for the host machine: /opt/homebrew/opt/llvm/bin/clang++ ld64 1230.1
  Cython compiler for the host machine: cython (cython 3.2.2)
  Host machine cpu family: aarch64
  Host machine cpu: aarch64
  Program python found: YES (/Users/goldbaum/.pyenv/versions/3.14.2/bin/python)
  Found pkg-config: YES (/opt/homebrew/bin/pkg-config) 2.5.1
  Run-time dependency python found: YES 3.14
  Program cython found: YES (/private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/pip-build-env-02uwx2qw/overlay/bin/cython)
  Compiler for C supports arguments -Wno-unused-but-set-variable: YES
  Compiler for C supports arguments -Wno-unused-function: YES
  Compiler for C supports arguments -Wno-conversion: YES
  Compiler for C supports arguments -Wno-misleading-indentation: YES
  Library m found: YES
  Fortran compiler for the host machine: gfortran (gcc 15.2.0 "GNU Fortran (Homebrew GCC 15.2.0) 15.2.0")
  Fortran linker for the host machine: gfortran ld64 1230.1
  ../meson.build:94: WARNING: Consider using the built-in option for language standard version instead of using "-std=legacy".
  Compiler for Fortran supports arguments -Wno-conversion: YES
  Compiler for C supports link arguments -Wl,-dead_strip: YES
  Checking if "-Wl,--version-script" links: NO
  Program tools/generate_f2pymod.py found: YES (/Users/goldbaum/.pyenv/versions/3.14.2/bin/python /Users/goldbaum/Documents/scipy/tools/generate_f2pymod.py)
  Program scipy/_build_utils/tempita.py found: YES (/Users/goldbaum/.pyenv/versions/3.14.2/bin/python /Users/goldbaum/Documents/scipy/scipy/_build_utils/tempita.py)
  Program pythran found: YES 0.18.1 0.18.1 (/private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/pip-build-env-02uwx2qw/overlay/bin/pythran)
  Found pkg-config: YES (/opt/homebrew/bin/pkg-config) 2.5.1
  WARNING: Found CMake '/Users/goldbaum/.pyenv/versions/3.14.2/bin/cmake' but couldn't run it
  Found CMake: NO
  Run-time dependency xsimd found: NO (tried pkgconfig, framework and cmake)

  Executing subproject xsf

  xsf| Project name: xsf
  xsf| Project version: 0.1.0
  xsf| C++ compiler for the host machine: /opt/homebrew/opt/llvm/bin/clang++ (clang 21.1.7 "Homebrew clang version 21.1.7")
  xsf| C++ linker for the host machine: /opt/homebrew/opt/llvm/bin/clang++ ld64 1230.1
  xsf| Build targets in project: 0
  xsf| Subproject xsf finished.


  Executing subproject boost_math

  boost_math| Project name: boost-math
  boost_math| Project version: 1.88.0
  boost_math| Build targets in project: 0
  boost_math| Subproject boost_math finished.


  Executing subproject qhull_r

  qhull_r| Project name: qhull_r
  qhull_r| Project version: 8.0.2
  qhull_r| C compiler for the host machine: /opt/homebrew/opt/llvm/bin/clang (clang 21.1.7 "Homebrew clang version 21.1.7")
  qhull_r| C linker for the host machine: /opt/homebrew/opt/llvm/bin/clang ld64 1230.1
  qhull_r| Compiler for C supports arguments -Wno-unused-but-set-variable: YES (cached)
  qhull_r| Build targets in project: 1
  qhull_r| Subproject qhull_r finished.

  Run-time dependency threads found: YES
  numpy-config found: YES (/private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/pip-build-env-02uwx2qw/overlay/bin/numpy-config) 2.3.5
  Run-time dependency numpy found: YES 2.3.5
  Message: f2py free-threading enabled
  Library npymath found: YES
  pybind11-config found: YES (/private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/pip-build-env-02uwx2qw/overlay/bin/pybind11-config) 3.0.1
  Run-time dependency pybind11 found: YES 3.0.1
  Checking if "thread_local" compiles: NO
  Checking if "_Thread_local" compiles: YES
  Checking if "__thread" compiles: YES
  Configuring scipy_config.h using configuration
  Program f2py found: YES (/private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/pip-build-env-02uwx2qw/overlay/bin/f2py)
  Run-time dependency scipy-openblas found: NO (tried pkgconfig)
  Run-time dependency openblas found: YES 0.3.30
  Dependency openblas found: YES 0.3.30 (cached)
  Run-time dependency python found: YES 3.14
  Compiler for C supports arguments -Wno-maybe-uninitialized: NO
  Compiler for C supports arguments -Wno-discarded-qualifiers: NO
  Compiler for C supports arguments -Wno-empty-body: YES
  Compiler for C supports arguments -Wno-implicit-function-declaration: YES
  Compiler for C supports arguments -Wno-parentheses: YES
  Compiler for C supports arguments -Wno-switch: YES
  Compiler for C supports arguments -Wno-unused-label: YES
  Compiler for C supports arguments -Wno-unused-result: YES
  Compiler for C supports arguments -Wno-unused-variable: YES
  Compiler for C supports arguments -Wno-unused-but-set-variable: YES (cached)
  Compiler for C++ supports arguments -Wno-bitwise-instead-of-logical: YES
  Compiler for C++ supports arguments -Wno-cpp: YES
  Compiler for C++ supports arguments -Wno-class-memaccess: NO
  Compiler for C++ supports arguments -Wno-deprecated-declarations: YES
  Compiler for C++ supports arguments -Wno-deprecated-builtins: YES
  Compiler for C++ supports arguments -Wno-format-truncation: YES
  Compiler for C++ supports arguments -Wno-non-virtual-dtor: YES
  Compiler for C++ supports arguments -Wno-sign-compare: YES
  Compiler for C++ supports arguments -Wno-switch: YES
  Compiler for C++ supports arguments -Wno-terminate: NO
  Compiler for C++ supports arguments -Wno-unused-but-set-variable: YES
  Compiler for C++ supports arguments -Wno-unused-function: YES
  Compiler for C++ supports arguments -Wno-unused-local-typedefs: YES
  Compiler for C++ supports arguments -Wno-unused-variable: YES
  Compiler for C++ supports arguments -Wno-int-in-bool-context: YES
  Compiler for Fortran supports arguments -Wno-argument-mismatch: YES
  Compiler for Fortran supports arguments -Wno-conversion: YES (cached)
  Compiler for Fortran supports arguments -Wno-intrinsic-shadow: YES
  Compiler for Fortran supports arguments -Wno-maybe-uninitialized: YES
  Compiler for Fortran supports arguments -Wno-surprising: YES
  Compiler for Fortran supports arguments -Wno-uninitialized: YES
  Compiler for Fortran supports arguments -Wno-unused-dummy-argument: YES
  Compiler for Fortran supports arguments -Wno-unused-label: YES
  Compiler for Fortran supports arguments -Wno-unused-variable: YES
  Compiler for Fortran supports arguments -Wno-tabs: YES
  Compiler for Fortran supports arguments -Wno-argument-mismatch: YES (cached)
  Compiler for Fortran supports arguments -Wno-conversion: YES (cached)
  Compiler for Fortran supports arguments -Wno-maybe-uninitialized: YES (cached)
  Compiler for Fortran supports arguments -Wno-unused-dummy-argument: YES (cached)
  Compiler for Fortran supports arguments -Wno-unused-label: YES (cached)
  Compiler for Fortran supports arguments -Wno-unused-variable: YES (cached)
  Compiler for Fortran supports arguments -Wno-tabs: YES (cached)
  Checking if "Check atomic builtins without -latomic" links: YES
  Configuring __config__.py using configuration
  DEPRECATION: Variable substitution with boolean value 'CROSS_COMPILED' is deprecated.
  DEPRECATION: Variable substitution with boolean value 'BLAS_FOUND' is deprecated.
  DEPRECATION: Variable substitution with boolean value 'LAPACK_FOUND' is deprecated.
  Checking for function "open_memstream" : YES
  Configuring messagestream_config.h using configuration
  Program _generate_pyx.py found: YES (/Users/goldbaum/.pyenv/versions/3.14.2/bin/python /Users/goldbaum/Documents/scipy/scipy/special/_generate_pyx.py)
  Program _generate_pyx.py found: YES (/Users/goldbaum/.pyenv/versions/3.14.2/bin/python /Users/goldbaum/Documents/scipy/scipy/linalg/_generate_pyx.py)
  Program ../_generate_sparsetools.py found: YES (/Users/goldbaum/.pyenv/versions/3.14.2/bin/python /Users/goldbaum/Documents/scipy/scipy/sparse/sparsetools/../_generate_sparsetools.py)
  Checking for size of "void*" : 8
  Checking for size of "void*" : 8

  Executing subproject highs

  highs| Project name: highs
  highs| Project version: 1.8.0
  highs| C compiler for the host machine: /opt/homebrew/opt/llvm/bin/clang (clang 21.1.7 "Homebrew clang version 21.1.7")
  highs| C linker for the host machine: /opt/homebrew/opt/llvm/bin/clang ld64 1230.1
  highs| C++ compiler for the host machine: /opt/homebrew/opt/llvm/bin/clang++ (clang 21.1.7 "Homebrew clang version 21.1.7")
  highs| C++ linker for the host machine: /opt/homebrew/opt/llvm/bin/clang++ ld64 1230.1
  highs| Compiler for C++ supports arguments -Wno-invalid-offsetof: YES
  highs| Compiler for C++ supports arguments -Wno-maybe-uninitialized: NO
  highs| Compiler for C++ supports arguments -Wno-reorder: YES
  highs| Compiler for C++ supports arguments -Wno-reorder-ctor: YES
  highs| Compiler for C++ supports arguments -Wno-sometimes-uninitialized: YES
  highs| Compiler for C++ supports arguments -Wno-unused-but-set-variable: YES (cached)
  highs| Compiler for C++ supports arguments -Wno-unused-variable: YES (cached)
  highs| Compiler for C++ supports arguments -Wno-use-after-free: NO
  highs| Compiler for C++ supports arguments -Wno-comment: YES
  highs| Compiler for C supports arguments -Wno-comment: YES
  highs| Compiler for C supports arguments -Wno-invalid-offsetof: YES
  highs| Compiler for C supports arguments -Wno-maybe-uninitialized: NO (cached)
  highs| Compiler for C supports arguments -Wno-sometimes-uninitialized: YES
  highs| Compiler for C supports arguments -Wno-unused-label: YES (cached)
  highs| Compiler for C supports arguments -Wno-use-after-free: NO
  highs| Compiler for C supports arguments -Wno-unused-but-set-variable: YES (cached)
  highs| Compiler for C supports arguments -Wno-unused-variable: YES (cached)
  highs| Compiler for C supports arguments -Wno-use-after-free: NO (cached)
  highs| Dependency threads found: YES unknown (cached)
  highs| Checking if "Check atomic builtins without -latomic" links: YES (cached)
  highs| Dependency zlib skipped: feature use_zlib disabled
  highs| Checking if "mm_pause check" compiles: NO
  highs| Checking if "builtin_clz check" compiles: YES
  highs| Configuring HConfig.h.meson.interim using configuration
  highs| Found git repository at /Users/goldbaum/Documents/scipy/subprojects/highs
  highs| Build targets in project: 144
  highs| Subproject highs finished.

  Build targets in project: 194
  ../scipy/misc/meson.build:7: WARNING: Trying to use ['thread'] sanitizer on Clang with b_lundef.
  This will probably not work.
  Try setting b_lundef to false instead.

  scipy 1.17.0.dev0+git20250716.6ed0250

    Subprojects
      boost_math  : YES
      highs       : YES
      qhull_r     : YES
      xsf         : YES

    User defined options
      Native files: /Users/goldbaum/Documents/scipy/.mesonpy-vh4wyhe9/meson-python-native-file.ini
      b_ndebug    : if-release
      b_sanitize  : thread
      b_vscrt     : md
      buildtype   : release

  Found ninja-1.13.0.git.kitware.jobserver-pipe-1 at /private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/pip-build-env-02uwx2qw/normal/bin/ninja

  ERROR: Linker gfortran does not support sanitizer arguments ['-fsanitize=thread']

  A full log can be found at /Users/goldbaum/Documents/scipy/.mesonpy-vh4wyhe9/meson-logs/meson-log.txt

Expected behavior

Meson has some static knowledge that gfortran doesn't support sanitizers and doesn't even try to pass it to gfortran.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? native build
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) MacOS Sequoia
  • what Python version are you using e.g. 3.8.0 3.14.2
  • what meson --version 1.10.0
  • what ninja --version if it's a Ninja build 1.13.0.git.kitware.jobserver-pipe-1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions