Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLD: don't statically link to libstdc++ #97

Merged

Conversation

yut23
Copy link
Member

@yut23 yut23 commented May 22, 2024

Linking to libstdc++ statically causes weird memory errors when trying to import other extensions that link to it dynamically (e.g. matplotlib, contourpy). yt-project/yt#4910 is the same issue in yt.

This script should reproduce the crash:

#!/bin/sh
export CIBW_BUILD='cp39-*'
export CIBW_SKIP='*-musllinux_*'
export CIBW_ARCHS_LINUX='x86_64'
export CIBW_ENVIRONMENT="LDFLAGS='-static-libstdc++'"
export CIBW_BUILD_VERBOSITY=1
export CIBW_TEST_COMMAND=' \
python -m pip install -r {project}/test_requirements.txt contourpy \
&& python -c "import ewah_bool_utils.ewah_bool_wrap; import contourpy"'
cibuildwheel --output-dir dist

Running python under gdb gives the following backtrace:

Details

*** Error in `/tmp/tmp.SvMHbvY4MK/venv/bin/python': free(): invalid pointer: 0x00007f415618fc80 ***
...
Program received signal SIGABRT, Aborted.
0x00007f41964f7387 in raise () from /lib64/libc.so.6
#0  0x00007f41964f7387 in raise () from /lib64/libc.so.6
#1  0x00007f41964f8a78 in abort () from /lib64/libc.so.6
#2  0x00007f4196539f67 in __libc_message () from /lib64/libc.so.6
#3  0x00007f4196542329 in _int_free () from /lib64/libc.so.6
#4  0x00007f4155ef9192 in std::locale::_Impl::_M_install_facet(std::locale::id const*, std::locale::facet const*) () from /lib64/libstdc++.so.6
#5  0x00007f4155ef95e3 in std::locale::_Impl::_Impl(unsigned long) ()
   from /lib64/libstdc++.so.6
#6  0x00007f4155efa555 in ?? () from /lib64/libstdc++.so.6
#7  0x00007f4196f9e20b in __pthread_once_slow () from /lib64/libpthread.so.0
#8  0x00007f4155efa5a1 in ?? () from /lib64/libstdc++.so.6
#9  0x00007f4155efa5e3 in std::locale::locale() () from /lib64/libstdc++.so.6
#10 0x00007f4155ef743c in std::ios_base::Init::Init() ()
   from /lib64/libstdc++.so.6
#11 0x00007f418527f050 in _GLOBAL__sub_I_chunk_local.cpp ()
   from /tmp/tmp.SvMHbvY4MK/venv/lib/python3.9/site-packages/contourpy/_contourpy.cpython-39-x86_64-linux-gnu.so
#12 0x00007f41971c39c3 in _dl_init_internal ()
   from /lib64/ld-linux-x86-64.so.2
#13 0x00007f41971c859e in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
#14 0x00007f41971c37d4 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#15 0x00007f41971c7b8b in _dl_open () from /lib64/ld-linux-x86-64.so.2
#16 0x00007f4196d94fab in dlopen_doit () from /lib64/libdl.so.2
#17 0x00007f41971c37d4 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#18 0x00007f4196d955ad in _dlerror_run () from /lib64/libdl.so.2
#19 0x00007f4196d95041 in dlopen@@GLIBC_2.2.5 () from /lib64/libdl.so.2
#20 0x0000000000506f01 in ?? ()
...

As I understand it, the std::locale static initialization code runs a second time when libstdc++.so.6 is loaded by _contourpy, which breaks some assumptions about the global state. Here's some discussion on the gcc-help mailing list about what is probably the same issue: https://gcc.gnu.org/legacy-ml/gcc-help/2017-05/msg00164.html.

Linking to libstdc++ statically causes weird segfaults with other extensions that link to it dynamically (e.g. matplotlib, contourpy). See yt-project/yt#4910.
@neutrinoceros
Copy link
Member

Thank you ! do I understand correctly that this warrants a new release ?

@neutrinoceros neutrinoceros merged commit 86079d1 into yt-project:main May 22, 2024
17 checks passed
@yut23
Copy link
Member Author

yut23 commented May 22, 2024

Yes, although only the Linux wheels will be any different (aside from file modification times and such).

@yut23 yut23 deleted the build/libstdcxx_dynamic_linking branch May 22, 2024 18:04
@neutrinoceros
Copy link
Member

Not a problem, all this package ever gets is build time changes anyway. Thank you again. I'll cut the release out after dinner !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants