| Issue |
185112
|
| Summary |
[BOLT] CPython build with BOLT segfaults when backtrace called
|
| Labels |
BOLT
|
| Assignees |
|
| Reporter |
jjhelmus
|
In the [`python-build-standalone` project](https://github.com/astral-sh/python-build-standalone) we build CPython using LLVM 21 and optimize using BOLT.
Recently it was reported (astral-sh/python-build-standalone#991) that NumPy segfaults under this interpreter in a block of code that calls `backtrace`.
A smaller reproducer was made ([jjhelmus/example-backtrace-pbs-segfault](https://github.com/jjhelmus/example-backtrace-pbs-segfault)) which exhibits the behavior when `backtrace` is called within an in-place or operation.
Capturing this segfault in GDB gives a call stack that is missing a number of frames (6-10):
```
#0 0x00007ffff7bf3a10 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#1 0x00007ffff7bf591e in _Unwind_Backtrace () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#2 0x00007ffff7d35eb3 in __GI___backtrace (array=array@entry=0x7fffffffd3e0, size=size@entry=50) at ./debug/backtrace.c:78
#3 0x00007ffff7fac297 in boom () at example_module.c:10
#4 0x00007ffff7fac2ef in Thing_inplace_or (self=0x7ffff7519b30, other=<optimized out>) at example_module.c:34
#5 0x0000000001ada8a2 in PyNumber_InPlaceOr.warm ()
#6 0x0000000000000014 in ?? ()
#7 0x0000000000000014 in ?? ()
#8 0x00007ffff7408e30 in ?? ()
#9 0x00007ffff7519b30 in ?? ()
#10 0x00007ffff7fb0020 in ?? ()
#11 0x0000000001801394 in _TAIL_CALL_BINARY_OP.llvm.10362591704542007599 ()
#12 0x00000000018890ed in _PyEval_Vector ()
#13 0x0000000001888de7 in PyEval_EvalCode ()
#14 0x00000000018e4c73 in run_mod.llvm ()
#15 0x0000000001a3b9c7 in pyrun_file ()
#16 0x0000000001a3979b in _PyRun_SimpleFileObject ()
#17 0x0000000001a39682 in _PyRun_AnyFileObject ()
#18 0x0000000001a391f6 in pymain_run_file_obj ()
#19 0x0000000001a390f4 in pymain_run_file ()
#20 0x00000000019b0f91 in Py_RunMain ()
#21 0x00000000019ae9c3 in pymain_main.llvm ()
#22 0x00000000019ae7ad in main ()
```
This only occurs when BOLT optimization is done on CPython and is also dependent on the BOLT options.
The options that reproduce the issue are:
```
-update-debug-sections -skip-funcs=RC4_options/1 -reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions -split-strategy=cdsplit -icf=safe -inline-all -split-eh -reorder-functions-use-hot-size -peepholes=none -jump-tables=aggressive -inline-ap -indirect-call-promotion=all -dyno-stats -use-gnu-stack -frame-opt=hot
```
Changing `-split-strategy=cdsplit` to `-split-strategy=profile2` resolves the segfault. As does compiling with frame pointers, `-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs