Skip to content

Commit

Permalink
Better fix for when CFLAGS includes -D_FORTIFY_SOURCE
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
tornaria committed Feb 9, 2025
1 parent fbfc559 commit 0e5b29d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 0 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/cysignals/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0e5b29d

Please sign in to comment.