I got this weird bug while developing the __future__
imports.
A commit demonstrating the issue is at https://github.com/tjhance/pyston/tree/weird_segfault
When I run make dbg_map ARGS=-csrq
, I get the following backtrace from gdb
:
Program received signal SIGSEGV, Segmentation fault.
0x00002aaaac3b5e08 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#0 0x00002aaaac3b5e08 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00002aaaac3b6b89 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00000000007b4a60 in __gnu_cxx::new_allocator<long>::deallocate (this=0x1c5aba0 <pyston::Stats::getStatId(std::string const&)::counts>, __p=0x1d83de0) at /home/tjhance/pyston_deps/gcc-4.8.2-install/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/ext/new_allocator.h:110
#3 0x00000000007b4a2e in std::_Vector_base<long, std::allocator<long> >::_M_deallocate (this=0x1c5aba0 <pyston::Stats::getStatId(std::string const&)::counts>, __p=0x1d83de0, __n=64) at /home/tjhance/pyston_deps/gcc-4.8.2-install/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/bits/stl_vector.h:174
#4 0x00000000007b6259 in std::_Vector_base<long, std::allocator<long> >::~_Vector_base (this=0x1c5aba0 <pyston::Stats::getStatId(std::string const&)::counts>) at /home/tjhance/pyston_deps/gcc-4.8.2-install/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/bits/stl_vector.h:160
#5 0x00000000007b15c8 in std::vector<long, std::allocator<long> >::~vector (this=0x1c5aba0 <pyston::Stats::getStatId(std::string const&)::counts>) at /home/tjhance/pyston_deps/gcc-4.8.2-install/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/bits/stl_vector.h:416
#6 0x00002aaaac372901 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#7 0x00002aaaac372985 in exit () from /lib/x86_64-linux-gnu/libc.so.6
#8 0x00002aaaac358774 in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#9 0x00000000006535e9 in _start ()
Looks like it's segfaulting when it tries to destruct the local static variable
static std::vector<long> counts;
from core/stats.cpp
I valgrind'ed and gdb'ed but couldn't figure this out - it doesn't seem like the destructor is being called more than once. My best guess is that we're running into some undefined behavior here, but I can't figure out where it is coming from or how it's manifesting.
For my future diff, I resolved the issue by moving around some totally unrelated stuff (namely I moved the definitions of FutureOption
and future_options
from codegen/irgen/future.h
to codegen/irgen/future.cpp
. Notably, core/stats.cpp
does not include (not even indirectly) future.h
!) So this is more evidence that there is some undefined behavior going on.
But I have no idea where it's coming from. The use of of the variable counts
, while hacky, looks fine as far as I can tell. I'm just throwing this issue up here in case anybody has any idea what's going on, because I'd like to know, and it might be an issue that shows up again later.