From 0e5b29d59c88bfa1c062fb22db2ad1a8a1d506c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sun, 9 Feb 2025 16:58:10 -0300 Subject: [PATCH] Better fix for when CFLAGS includes -D_FORTIFY_SOURCE The module signals.pyx has to be built with fortify disabled, because of a false positive in one of the `longjmp()`, more precisely in the call ``` cylongjmp(trampoline_setup, 1) ``` which appears in `setup_trampoline()`. Often distributions will add `-D_FORTIFY_SOURCE=2` to `CFLAGS`, and so this has to be overridden when compiling `signals.pyx` by adding `-U_FORTIFY_SOURCE` to the compiler arguments. The former solution, using `add_project_arguments()` doesn't work since it will add flags *before* the ones provided in `CFLAGS`. Instead, add `-U_FORTIFY_SOURCE` to the arguments in the definition of the extension module `signal`, which will add it to the command line *after* the ones provided in `CFLAGS`. In addition, fortify is disabled only for building `signal.pyx`. --- meson.build | 3 --- src/cysignals/meson.build | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 9bbdb47..74820e6 100644 --- a/meson.build +++ b/meson.build @@ -19,9 +19,6 @@ is_mingw = cc.get_id()=='gcc' and host_machine.system()=='windows' # Set preprocessor macros # Disable .c line numbers in exception tracebacks add_project_arguments('-DCYTHON_CLINE_IN_TRACEBACK=0', language: 'c') -# Disable sanity checking in GNU libc -# This is required because of false positives in the longjmp() check -add_project_arguments('-U_FORTIFY_SOURCE', language: 'c') # Platform-specific settings if is_cygwin diff --git a/src/cysignals/meson.build b/src/cysignals/meson.build index 062ebfe..1032dd0 100644 --- a/src/cysignals/meson.build +++ b/src/cysignals/meson.build @@ -31,6 +31,9 @@ foreach name, pyx : extensions cython_args: ['-Wextra'], dependencies: [py_dep, threads_dep], install: true, - subdir: 'cysignals' + subdir: 'cysignals', + # Disable sanity checking in GNU libc + # This is required because of false positives in the longjmp() check + c_args: name == 'signals' ? ['-U_FORTIFY_SOURCE'] : [], ) endforeach