Linking against a shared library silently injects TLS by enabling morestack gcc feature
johann.pfefferl@siemens.com
johann.pfefferl@siemens.com
Wed Jun 3 11:18:35 GMT 2026
Hello,
we habe a problem with the gcc/linker behaviour when wrapping the
function pthread_create in a shared library.
The compiler version is
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 14.2.0-19' --with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr --with-gcc-major-version-only --program-suffix=-14 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/reproducible-path/gcc-14-14.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/reproducible-path/gcc-14-14.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=3
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Debian 14.2.0-19)
Linking a shared library (libmy.so) against another shared library
(libmywrap.so) seems to silently activate a compiler feature called morestack
and by that silently injects TLS (thread local storage).
This injection causes trouble because we use this application in a real
time context. Therefore this morestack feature during runtime must be
avoided.
When we wrap ioctl() (as a random chosen alternative) instead of pthread_create()
the issue is gone. So it is (very likely) somehow related to the __wrap_pthread_create()
symbol provided by libgcc.
The library dependency looks like
app -> libmy.so -> libmywrap.so
In the error case the app binary is linked against libgcc.
Now the question is why? Because we provide already the __wrap_pthread_create function
in the library libmywrap.so. So normally there is no more need to link
in the libgcc library.
$ ldd app
linux-vdso.so.1 (0x00007fdb5c8d1000)
libmy.so => [snip]./libmy.so (0x00007fdb5c8c0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fdb5c87c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdb5c688000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdb5c8d3000)
libmywrap.so => [snip]./libmywrap.so (0x00007fdb5c683000)
$ nm app
[snip]
0000000000002370 T __splitstack_block_signals
0000000000002720 T __splitstack_block_signals_context
0000000000002200 T __splitstack_find
0000000000002750 T __splitstack_find_context
00000000000023e0 T __splitstack_getcontext
0000000000002500 T __splitstack_makecontext
0000000000002710 T __splitstack_releasecontext
00000000000026a0 T __splitstack_resetcontext
0000000000002480 T __splitstack_setcontext
0000000000001586 t __stack_split_initialize
[snip]
Is it possible to avoid this split-stack feature in this shared library.
Is this behaviour a gcc feature or is it more a bug which has to be
addressed?
A small example code can be found in the attachment to reproduce the
problem.
With best regards
Dr. Johann Pfefferl
--
Siemens AG -- Foundational Technologies
Research & Predevelopment
Connectivity & Edge
Open Source Embedded Systems
FT RPD CED OES-DE
Room 53.740
Otto-Hahn-Ring 6
81739 Muenchen, Germany
mailto: johann.pfefferl@siemens.com
phone: +49 1520 3450 138
fax: +49 89 636 33045
uri: https://linux.siemens.io/
_____________________________________________________
Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Jim Hagemann Snabe
Managing Board: Board: Roland Busch, Chairman, President and CEO
Veronika Bienert, Peter Koerte, Cedrik Neike,
Matthias Rebellius, Veronika Bienert, Judith Wiese;
Registered offices: Berlin and Munich, Germany
Commercial registries: Berlin-Charlottenburg, HRB 12300, Munich, HRB 6684
WEEE-Reg.-No. DE 23691322
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-split-stack-reproducer.tar.gz
Type: application/gzip
Size: 1222 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20260603/12cb376f/attachment.gz>
More information about the Gcc-help
mailing list