Linking against a shared library silently injects TLS by enabling morestack gcc feature
"johann.pfefferl--- via Gcc-help" <[email protected]> Wed, 3 Jun 2026 13:18:35 +0200
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
--RUNbNZ5/1OVxW5Qf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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=3Dgcc
COLLECT_LTO_WRAPPER=3D/usr/libexec/gcc/x86_64-linux-gnu/14/lto-wrapper
OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=3D1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion=3D'Debian 14.2.0-19'=
--with-bugurl=3Dfile:///usr/share/doc/gcc-14/README.Bugs --enable-language=
s=3Dc,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=3D/usr --with-gcc-=
major-version-only --program-suffix=3D-14 --program-prefix=3Dx86_64-linux-g=
nu- --enable-shared --enable-linker-build-id --libexecdir=3D/usr/libexec --=
without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --ena=
ble-nls --enable-bootstrap --enable-clocale=3Dgnu --enable-libstdcxx-debug =
--enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-l=
ibstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --ena=
ble-plugin --enable-default-pie --with-system-zlib --enable-libphobos-check=
ing=3Drelease --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --en=
able-multiarch --disable-werror --enable-cet --with-arch-32=3Di686 --with-a=
bi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=
=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/reproducible-path=
/gcc-14-14.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/reproducible-pat=
h/gcc-14-14.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cud=
a-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx8=
6_64-linux-gnu --target=3Dx86_64-linux-gnu --with-build-config=3Dbootstrap-=
lto-lean --enable-link-serialization=3D3
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 moresta=
ck
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_cr=
eate()
the issue is gone. So it is (very likely) somehow related to the __wrap_pth=
read_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_crea=
te 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 =3D> [snip]./libmy.so (0x00007fdb5c8c0000)
libgcc_s.so.1 =3D> /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fdb5=
c87c000)
libc.so.6 =3D> /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdb5c688000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdb5c8d3000)
libmywrap.so =3D> [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
--=20
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: [email protected]
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
--RUNbNZ5/1OVxW5Qf
Content-Type: application/gzip
Content-Disposition: attachment;
filename="gcc-split-stack-reproducer.tar.gz"
Content-Transfer-Encoding: base64
H4sIAAAAAAAAA+1Ye2+jRhD3v+ynmCZRZSyw8QNb8jVV71z1Gsl3V/WhqlIki8AC28PgLuukUdXv
3tldwNhJTNVESU/HT1Hw7g7DzOw8difyfTvfJEzYufD8jzanG54FW5/yQeep4CBmM1c+R2NnVn+W
6Azd0RCf46kz7DjD6Xgy7YD7ZBIcwRb15gCdTUjDkPLkIbqm9U8U0cP7n7Cr9e0N9zZ9/3HfkBs8
nU4e2v8hQu6/47iuO5PzI8cdTzrgPI2Kx/GZ7/8pS/1kG1D4aiNiTr2gH39NdpO5CFgmpwhLBaxW
0h1WBeXKx/+CdsuhgN5qxWkuOPMlbUpv9IpFDMMA8LM0F1BSe0LwO6/IyYL6OmMB9Lq4LjdIrHi2
FSylZlcvmHtk+0x4ZJK/iLHhKHPYPUE/lmLPYV9ukJMbysH3koQGl+mJ+YoQY9AjBvSgcn5gIqdJ
CCyHqy1LArhhIkZZINymvmBZqvmwNLJAxEh1w5JE8VR8REyBrTcJXdNUeIo+5Nla8i/EkWQDYnAq
tjw9kLFb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