https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120870

            Bug ID: 120870
           Summary: CPython without GIL ("free-threaded") miscompiled with
                    preserve_none and PGO
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
                CC: hjl.tools at gmail dot com
  Target Milestone: ---

```
$ git clone https://github.com/python/cpython
$ git rev-parse HEAD
698bab5a4031c8f54e04e1dd42bcbe3e4564eba5
$ ./configure --with-tail-call-interp --disable-gil --enable-optimizations
CFLAGS="-O2 -march=znver2 -ggdb3"
$ make -j$(nproc) -l$(nproc)
[...]
./_bootstrap_python ./Programs/_freeze_module.py runpy ./Lib/runpy.py
Python/frozen_modules/runpy.h
make[2]: *** [Makefile:1948: Python/frozen_modules/runpy.h] Segmentation fault
make[2]: Leaving directory '/tmp/cpython'                                      
                                                                               
                          make[2]: *** Waiting for unfinished jobs....
```

Fortunately, it fails in the instrumentation stage with -fprofile-generate.

```
$ gdb --args ./_bootstrap_python ./Programs/_freeze_module.py runpy
./Lib/runpy.py Python/frozen_modules/runpy.h
Reading symbols from ./_bootstrap_python...
(gdb) r
Starting program: /tmp/cpython/_bootstrap_python ./Programs/_freeze_module.py
runpy ./Lib/runpy.py Python/frozen_modules/runpy.h
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00005555558b277c in _Py_Check_ArgsIterable
(tstate=tstate@entry=0x55555603d858 <_PyRuntime+346200>,
func=func@entry=0x7fffffffccf0, args=args@entry=0x7ffff7f91410)
    at Python/ceval.c:3266
3266        if (Py_TYPE(args)->tp_iter == NULL && !PySequence_Check(args)) {
(gdb) bt
#0  0x00005555558b277c in _Py_Check_ArgsIterable
(tstate=tstate@entry=0x55555603d858 <_PyRuntime+346200>,
func=func@entry=0x7fffffffccf0, args=args@entry=0x7ffff7f91410)
    at Python/ceval.c:3266
#1  0x00005555558e6382 in _TAIL_CALL_CALL_FUNCTION_EX (frame=0x7ffff7f91388,
stack_pointer=<optimized out>, tstate=0x55555603d858 <_PyRuntime+346200>,
next_instr=0x32f623c03f8, oparg=0)
    at ./Include/internal/pycore_stackref.h:364
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)
```

Reply via email to