https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90399
Bug ID: 90399 Summary: split-stack + shared library + static object construction (C++) Product: gcc Version: 8.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgcc Assignee: unassigned at gcc dot gnu.org Reporter: mkarsten at uwaterloo dot ca Target Milestone: --- Created attachment 46316 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46316&action=edit example code and gdb output I am building a shared library that internally uses split-stack and calls __splitstack_makecontext() during construction of a static object. At runtime, there seem to be two copies of split-stack code/variables (from libgcc.a) in play - one that is added to the shared libray and another one that is added to the executable. When the program is started, the following seems to happen: - shared library copy of '__morestack_load_mmap()' initializes its copy of 'static_pagesize' - however, the first call to '__splitstack_makecontext()' ends up in the other instance where 'static_pagesize' is not initialized, thus 0, thus the allocation fails and the program terminates with: unable to allocate additional stack space: errno 22 Interestingly, gdb disassembly claims that the correct version of __splitstack_makecontext() should be called. The stack backtrace shows that the (executable) version #3 0x0000555555556379 in __splitstack_makecontext () is called, despite the disassembly output claiming that the (shared library) version would be called: 0x00007ffff7fc71f5 <+107>: callq 0x7ffff7fc7040 <__splitstack_makecontext@plt> I am attaching a small example with Makefile and gdb output from triggering the error. The bug can only be reproduced with multiple files, so I am attaching a tgz archive. The same code works fine when avoiding the shared library (see 'make works' target in Makefile). I have seen this with various versions of gcc on various Linux platforms (Ubuntu and Arch). My most recent testing is with the packaged gcc 8.3.0 on Arch Linux: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gConfigured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=autocc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto Thread model: posix gcc version 8.3.0 (GCC) Please let me know, if you need further information.