Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 918934 - dev-python/cysignals-1.11.4 - [clang] build/.../implementation.c: error: cysignals must be compiled without _FORTIFY_SOURCE
Summary: dev-python/cysignals-1.11.4 - [clang] build/.../implementation.c: error: cysi...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Michael Orlitzky
URL: https://github.com/sagemath/cysignals...
Whiteboard:
Keywords:
Depends on:
Blocks: 847148
  Show dependency tree
 
Reported: 2023-12-01 09:21 UTC by Toralf Förster
Modified: 2024-07-10 15:17 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge-info.txt (emerge-info.txt,17.44 KB, text/plain)
2023-12-01 09:21 UTC, Toralf Förster
Details
dev-python:cysignals-1.11.4:20231130-214950.log (dev-python:cysignals-1.11.4:20231130-214950.log,17.36 KB, text/plain)
2023-12-01 09:21 UTC, Toralf Förster
Details
emerge-history.txt (emerge-history.txt,56.38 KB, text/plain)
2023-12-01 09:21 UTC, Toralf Förster
Details
environment (environment,165.00 KB, text/plain)
2023-12-01 09:21 UTC, Toralf Förster
Details
etc.clang.tar.xz (etc.clang.tar.xz,1.13 KB, application/x-xz)
2023-12-01 09:21 UTC, Toralf Förster
Details
etc.portage.tar.xz (etc.portage.tar.xz,20.55 KB, application/x-xz)
2023-12-01 09:21 UTC, Toralf Förster
Details
logs.tar.xz (logs.tar.xz,4.34 KB, application/x-xz)
2023-12-01 09:21 UTC, Toralf Förster
Details
qlist-info.txt (qlist-info.txt,131.50 KB, text/plain)
2023-12-01 09:21 UTC, Toralf Förster
Details
temp.tar.xz (temp.tar.xz,37.93 KB, application/x-xz)
2023-12-01 09:21 UTC, Toralf Förster
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Toralf Förster gentoo-dev 2023-12-01 09:21:46 UTC
too long lines were shrinked:

2023-11-30 21:50:03,044 root INFO clang -Wsign-compare -DNDEBUG -O2 -pipe -march=native -fno-diagnostics-color -Werror=implicit-function-declaration -Werror=implicit-int -DNDEBUG -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -U_FORTIFY_SOURCE -Isrc -Isrc/cysignals -I/usr/include/python3.11 -c build/src/cysign
2023-11-30 21:50:03,044 root INFO creating /var/tmp/portage/dev-python/cysignals-1.11.4/work/cysignals-1.11.4-python3_11/build/temp.linux-x86_64-cpython-311/build
2023-11-30 21:50:03,043 root INFO creating /var/tmp/portage/dev-python/cysignals-1.11.4/work/cysignals-1.11.4-python3_11/build/temp.linux-x86_64-cpython-311
2023-11-30 21:50:03,059 root INFO clang -Wsign-compare -DNDEBUG -O2 -pipe -march=native -fno-diagnostics-color -Werror=implicit-function-declaration -Werror=implicit-int -DNDEBUG -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -U_FORTIFY_SOURCE -Isrc/cysignals -Isrc -I/usr/include/python3.11 -c build/src/cysign
2023-11-30 21:50:03,061 root INFO clang -Wsign-compare -DNDEBUG -O2 -pipe -march=native -fno-diagnostics-color -Werror=implicit-function-declaration -Werror=implicit-int -DNDEBUG -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -U_FORTIFY_SOURCE -Isrc -Isrc/cysignals -I/usr/include/python3.11 -c build/src/cysign
In file included from build/src/cysignals/signals.c:2380:
build/src/cysignals/implementation.c:27:2: error: "cysignals must be compiled without _FORTIFY_SOURCE"
   27 | #error "cysignals must be compiled without _FORTIFY_SOURCE"
      |  ^

  -------------------------------------------------------------------

  This is an unstable amd64 chroot image at a tinderbox (==build bot)
  name: 17.1_desktop_systemd_merged_usr-20231128-203237

  -------------------------------------------------------------------

CC=clang
CXX=clang++
gcc-config -l:
 [1] x86_64-pc-linux-gnu-13 *
clang/llvm (if any):
clang version 17.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/17/bin
Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang.cfg
/usr/lib/llvm/17
17.0.6
Python 3.11.6
Available Ruby profiles:
  [1]   ruby31 (with Rubygems) *
Available Rust versions:
  [1]   rust-bin-1.73.0 *
The following VMs are available for generation-2:
1)	Eclipse Temurin JDK 17.0.8.1_p1 [openjdk-bin-17]
*)	Eclipse Temurin JDK 21.0.1_p12 [openjdk-bin-21]
Available Java Virtual Machines:
  [1]   openjdk-bin-17 
  [2]   openjdk-bin-21  system-vm

The Glorious Glasgow Haskell Compilation System, version 9.0.2
php cli (if any):
go version go1.21.4 linux/amd64

  HEAD of ::gentoo
commit ac6f927fcb8bc4ff2280f6cf9dd9e7f2fc11dfe1
Author: Repository mirror & CI <repomirrorci@gentoo.org>
Date:   Thu Nov 30 20:31:58 2023 +0000

    2023-11-30 20:31:57 UTC

emerge -qpvO dev-python/cysignals
[ebuild  N    ] dev-python/cysignals-1.11.4  USE="-debug" PYTHON_TARGETS="python3_11 -python3_10 -python3_12"
Comment 1 Toralf Förster gentoo-dev 2023-12-01 09:21:47 UTC
Created attachment 876039 [details]
emerge-info.txt
Comment 2 Toralf Förster gentoo-dev 2023-12-01 09:21:48 UTC
Created attachment 876040 [details]
dev-python:cysignals-1.11.4:20231130-214950.log
Comment 3 Toralf Förster gentoo-dev 2023-12-01 09:21:49 UTC
Created attachment 876041 [details]
emerge-history.txt
Comment 4 Toralf Förster gentoo-dev 2023-12-01 09:21:50 UTC
Created attachment 876042 [details]
environment
Comment 5 Toralf Förster gentoo-dev 2023-12-01 09:21:51 UTC
Created attachment 876043 [details]
etc.clang.tar.xz
Comment 6 Toralf Förster gentoo-dev 2023-12-01 09:21:52 UTC
Created attachment 876044 [details]
etc.portage.tar.xz
Comment 7 Toralf Förster gentoo-dev 2023-12-01 09:21:53 UTC
Created attachment 876045 [details]
logs.tar.xz
Comment 8 Toralf Förster gentoo-dev 2023-12-01 09:21:54 UTC
Created attachment 876046 [details]
qlist-info.txt
Comment 9 Toralf Förster gentoo-dev 2023-12-01 09:21:55 UTC
Created attachment 876047 [details]
temp.tar.xz
Comment 10 Michael Orlitzky gentoo-dev 2023-12-01 21:01:14 UTC
Reported upstream. We will probably have to pile on a third hack to disable FORTIFY_SOURCE unless someone understands the sketchy code well-enough to replace it.
Comment 11 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-12-01 21:03:45 UTC
do I even want to look at why they're doing this..
Comment 12 Michael Orlitzky gentoo-dev 2023-12-01 23:00:20 UTC
(In reply to Sam James from comment #11)
> do I even want to look at why they're doing this..

Naturally my first instinct is to blame overly-clever code, but in this case cysignals has its roots in the dark ages of cython. Basically we needed a way to handle Ctrl-C in the SageMath CLI if you were stuck in a long-running computation. In pure python, everything's great, but within a cdef function not so much.

Cysignals lets you wrap those (presumably tight) loops in some signal handling magic. It was later split out into this independent package, but considering its original purpose, saving a few ops here and there with clever code could easily be justified.
Comment 13 Michael Orlitzky gentoo-dev 2024-06-29 15:29:49 UTC
Does toolchain@ have any suggestions to work around this in Gentoo until the issue can be fixed upstream? I think that ultimately we need to disable source-fortification.
Comment 14 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-07-07 04:54:27 UTC
I'll take a look.
Comment 15 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-07-07 04:59:06 UTC
So:
```
2023-11-30 21:50:03,061 root INFO clang -Wsign-compare -DNDEBUG -O2 -pipe -march=native -fno-diagnostics-color -Werror=implicit-function-declaration -Werror=implicit-int -DNDEBUG -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -U_FORTIFY_SOURCE -Isrc -Isrc/cysignals -I/usr/include/python3.11 -c build/src/cysignals/alarm.c -o /var/tmp/portage/dev-python/cysignals-1.11.4/work/cysignals-1.11.4-python3_11/build/temp.linux-x86_64-cpython-311/build/src/cysignals/alarm.o -pthread -Wp,-U_FORTIFY_SOURCE
In file included from build/src/cysignals/signals.c:2380:
build/src/cysignals/implementation.c:27:2: error: "cysignals must be compiled without _FORTIFY_SOURCE"
   27 | #error "cysignals must be compiled without _FORTIFY_SOURCE"
      |  ^
build/src/cysignals/implementation.c:163:5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
  163 |     write(2, s, strlen(s));
      |     ^~~~~ ~~~~~~~~~~~~~~~
build/src/cysignals/implementation.c:422:29: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'long' [-Wsign-compare]
  422 |     if (trampolinestacksize < PTHREAD_STACK_MIN)
      |         ~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
2 warnings and 1 error generated.
```

-U_FORTIFY_SOURCE and the -Wp,-U* banged in for good measure.. should be enough?

I can't reproduce it with either GCC or Clang. For Clang, the situation is kind of more interesting because in clang-common, we have to do some hacks for it:

```
        # We have to do this because glibc's headers warn if F_S is set
        # without optimization and that would at the very least be very noisy
        # during builds and at worst trigger many -Werror builds.
        cat >> "${ED}/usr/include/gentoo/fortify.h" <<- EOF || die
        #ifdef __clang__
        # pragma clang system_header
        #endif
        #ifndef _FORTIFY_SOURCE
        # if defined(__has_feature)
        #  define __GENTOO_HAS_FEATURE(x) __has_feature(x)
        # else
        #  define __GENTOO_HAS_FEATURE(x) 0
        # endif
        #
        # if defined(__STDC_HOSTED__) && __STDC_HOSTED__ == 1
        #  define __GENTOO_NOT_FREESTANDING 1
        # else
        #  define __GENTOO_NOT_FREESTANDING 0
        # endif
        #
        # if defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 && __GENTOO_NOT_FREESTANDING > 0
        #  if !defined(__SANITIZE_ADDRESS__) && !__GENTOO_HAS_FEATURE(address_sanitizer) && !__GENTOO_HAS_FEATURE(memory_sanitizer)
        #   define _FORTIFY_SOURCE ${fortify_level}
        #  endif
        # endif
        # undef __GENTOO_HAS_FEATURE
        # undef __GENTOO_NOT_FREESTANDING
        #endif
        EOF
```

But it seems to respect the wishes of the file fine (the command line args take priority as the injected config file -include comes first).

My best guess is:
1) There was some Clang bug in order precedence with config files, or
2) There was some issue in clang-common we fixed a while ago and I forgot about it.

If you can reproduce it now, I'll look more, of course.
Comment 16 Michael Orlitzky gentoo-dev 2024-07-09 17:47:15 UTC
It still fails for me with the stable clang-17.0.6:

  $ CC=clang emerge -v1 cysignals
  ...
  In file included from build/src/cysignals/signals.c:2399:
  build/src/cysignals/implementation.c:27:2: error: "cysignals must be compiled
  without _FORTIFY_SOURCE"
     27 | #error "cysignals must be compiled without _FORTIFY_SOURCE"
        |  ^

If it's fixed with a later clang, though, then maybe it's fine to pretend it's not a problem for a little while.
Comment 17 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-07-10 15:17:44 UTC
I'm not sure what I was doing before, because I can reproduce it with Clang 17 and 18. Maybe I was forgetting optimisation.

```
$ cat /tmp/z.c
#ifdef _FORTIFY_SOURCE
#error Uh oh!!!!!!
#endif

int main() {
        return 0;
}

$ clang-17 /tmp/z.c -O2 -U_FORTIFY_SOURCE
/tmp/z.c:2:2: error: Uh oh!!!!!!
    2 | #error Uh oh!!!!!!
      |  ^
1 error generated.

$ clang-18 /tmp/z.c -O2 -U_FORTIFY_SOURCE
/tmp/z.c:2:2: error: Uh oh!!!!!!
    2 | #error Uh oh!!!!!!
      |  ^
1 error generated.
```

And indeed:
```
$ clang --no-default-config -include /usr/include/gentoo/fortify.h /tmp/z.c -O2 -U_FORTIFY_SOURCE
/tmp/z.c:2:2: error: Uh oh!!!!!!
    2 | #error Uh oh!!!!!!
      |  ^
1 error generated.
```

I feel like this is pretty unexpected given the point of the config file mechanism is to let us do this kind of thing without patching Clang.

We can add an escape hatch macro into fortify.h for now (like GENTOO_NO_FORTIFY_SOURCE) but we need to file a bug for Clang about the weird behaviour with the config files.