The Ubuntu GCC turns on -fstack-protector by default. You get the same
results when turning this off.
However building and running your program with -fsanitize=address
suggests that your program is wrong.
** Changed in: gcc-defaults (Ubuntu)
Status: New => Invalid
--
You received this
Update: this does not involve threads (see new minimal version below).
Also, adding -O2 to the above version (with threading) gives no output,
but creates a SEGV with the version below. Finally, the bug occurs at
compile-time, not link time, since the object file (".o") created from
this also