BUG: After updating to numpy 2.0.0, scipy fails to build with LTO errors.
Author: eli-schwartzCreated Jun 27, 2024Updated Sep 18, 2026
Labelsdefectscipy.specialBuild issues
Describe your issue.
Discovered in https://bugs.gentoo.org/932721
Originally discovered with scipy 1.13.0, reproduced with 1.14.0. This bug report was generated after I tried building from git to triple-check it hasn't been fixed yet.
After updating to numpy 2.0.0, I tried to recompile scipy with the following *FLAGS to optimize the build: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing
Note the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.
I got the error in this exhaustive build log: build.log
(and reproduced below)
Reproducing Code Example
pip install
# or
emerge -1 scipyError message
[3/4] g++-14 -o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/meson-generated__ufuncs.c.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/_cosine.c.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/special_wrappers.cpp.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/sf_error.cc.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/dd_real_wrappers.cpp.o -flto -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999-python3_12/scipy/special -Wl,--start-group scipy/special/libcdflib.a scipy/libdummy_g77_abi_wrappers.a scipy/special/libsf_error_state.so -Wl,--version-script=/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999/scipy/_build_utils/link-version-pyinit.map /usr/lib64/liblapack.so /usr/lib/python3.12/site-packages/numpy/_core/include/../lib/libnpymath.a /usr/lib64/libblas.so -Wl,--end-group
FAILED: scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so
g++-14 -o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/meson-generated__ufuncs.c.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/_cosine.c.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/special_wrappers.cpp.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/sf_error.cc.o scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so.p/dd_real_wrappers.cpp.o -flto -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999-python3_12/scipy/special -Wl,--start-group scipy/special/libcdflib.a scipy/libdummy_g77_abi_wrappers.a scipy/special/libsf_error_state.so -Wl,--version-script=/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999/scipy/_build_utils/link-version-pyinit.map /usr/lib64/liblapack.so /usr/lib/python3.12/site-packages/numpy/_core/include/../lib/libnpymath.a /usr/lib64/libblas.so -Wl,--end-group
../scipy-9999/scipy/special/special_wrappers.h:111:13: error: type of ‘special_ccyl_bessel_i’ does not match original declaration [-Werror=lto-type-mismatch]
111 | npy_cdouble special_ccyl_bessel_i(double v, npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:361:13: note: return value type mismatch
361 | npy_cdouble special_ccyl_bessel_i(double v, npy_cdouble z) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:361:13: note: ‘special_ccyl_bessel_i’ was previously declared here
361 | npy_cdouble special_ccyl_bessel_i(double v, npy_cdouble z) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:361:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:99:13: error: type of ‘special_ccyl_bessel_j’ does not match original declaration [-Werror=lto-type-mismatch]
99 | npy_cdouble special_ccyl_bessel_j(double v, npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:337:13: note: return value type mismatch
337 | npy_cdouble special_ccyl_bessel_j(double v, npy_cdouble z) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:337:13: note: ‘special_ccyl_bessel_j’ was previously declared here
337 | npy_cdouble special_ccyl_bessel_j(double v, npy_cdouble z) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:337:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:178:13: error: type of ‘hyp2f1_complex_wrap’ does not match original declaration [-Werror=lto-type-mismatch]
178 | npy_cdouble hyp2f1_complex_wrap(double a, double b, double c, npy_cdouble zp);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:184:13: note: return value type mismatch
184 | npy_cdouble hyp2f1_complex_wrap(double a, double b, double c, npy_cdouble z) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:184:13: note: ‘hyp2f1_complex_wrap’ was previously declared here
184 | npy_cdouble hyp2f1_complex_wrap(double a, double b, double c, npy_cdouble z) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:184:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:33:13: error: type of ‘special_cexpi’ does not match original declaration [-Werror=lto-type-mismatch]
33 | npy_cdouble special_cexpi(npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:149:13: note: return value type mismatch
149 | npy_cdouble special_cexpi(npy_cdouble z) { return to_ccomplex(special::expi(to_complex(z))); }
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:149:13: note: ‘special_cexpi’ was previously declared here
149 | npy_cdouble special_cexpi(npy_cdouble z) { return to_ccomplex(special::expi(to_complex(z))); }
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:149:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
scipy/special/_ufuncs_defs.h:61:13: error: type of ‘chyp1f1_wrap’ does not match original declaration [-Werror=lto-type-mismatch]
61 | npy_cdouble chyp1f1_wrap(npy_double, npy_double, npy_cdouble);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:131:13: note: return value type mismatch
131 | npy_cdouble chyp1f1_wrap(double a, double b, npy_cdouble z) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:131:13: note: ‘chyp1f1_wrap’ was previously declared here
131 | npy_cdouble chyp1f1_wrap(double a, double b, npy_cdouble z) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:131:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
scipy/special/_ufuncs_defs.h:53:9: error: type of ‘cfresnl_wrap’ does not match original declaration [-Werror=lto-type-mismatch]
53 | npy_int cfresnl_wrap(npy_cdouble, npy_cdouble *, npy_cdouble *);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:196:5: note: type mismatch in parameter 1
196 | int cfresnl_wrap(npy_cdouble z, npy_cdouble *zfs, npy_cdouble *zfc) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘complex double’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:196:5: note: ‘cfresnl_wrap’ was previously declared here
196 | int cfresnl_wrap(npy_cdouble z, npy_cdouble *zfs, npy_cdouble *zfc) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:196:5: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
lto1: some warnings being treated as errors
lto-wrapper: fatal error: g++-14 returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
[4/4] g++-14 -o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/meson-generated_cython_special.c.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/_cosine.c.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/special_wrappers.cpp.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/sf_error.cc.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/dd_real_wrappers.cpp.o -flto -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999-python3_12/scipy/special -Wl,--start-group scipy/special/libcdflib.a scipy/special/libsf_error_state.so -Wl,--version-script=/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999/scipy/_build_utils/link-version-pyinit.map /usr/lib/python3.12/site-packages/numpy/_core/include/../lib/libnpymath.a -Wl,--end-group
FAILED: scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so
g++-14 -o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/meson-generated_cython_special.c.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/_cosine.c.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/special_wrappers.cpp.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/sf_error.cc.o scipy/special/cython_special.cpython-312-x86_64-linux-gnu.so.p/dd_real_wrappers.cpp.o -flto -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999-python3_12/scipy/special -Wl,--start-group scipy/special/libcdflib.a scipy/special/libsf_error_state.so -Wl,--version-script=/var/tmp/portage/dev-python/scipy-9999/work/scipy-9999/scipy/_build_utils/link-version-pyinit.map /usr/lib/python3.12/site-packages/numpy/_core/include/../lib/libnpymath.a -Wl,--end-group
../scipy-9999/scipy/special/special_wrappers.h:178:13: error: type of ‘hyp2f1_complex_wrap’ does not match original declaration [-Werror=lto-type-mismatch]
178 | npy_cdouble hyp2f1_complex_wrap(double a, double b, double c, npy_cdouble zp);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:184:13: note: return value type mismatch
184 | npy_cdouble hyp2f1_complex_wrap(double a, double b, double c, npy_cdouble z) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:184:13: note: ‘hyp2f1_complex_wrap’ was previously declared here
184 | npy_cdouble hyp2f1_complex_wrap(double a, double b, double c, npy_cdouble z) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:184:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:94:6: error: type of ‘special_cairye’ does not match original declaration [-Werror=lto-type-mismatch]
94 | void special_cairye(npy_cdouble z, npy_cdouble *ai, npy_cdouble *aip, npy_cdouble *bi, npy_cdouble *bip);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:328:6: note: type mismatch in parameter 1
328 | void special_cairye(npy_cdouble z, npy_cdouble *ai, npy_cdouble *aip, npy_cdouble *bi, npy_cdouble *bip) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:328:6: note: ‘special_cairye’ was previously declared here
328 | void special_cairye(npy_cdouble z, npy_cdouble *ai, npy_cdouble *aip, npy_cdouble *bi, npy_cdouble *bip) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:328:6: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:30:13: error: type of ‘special_cexp1’ does not match original declaration [-Werror=lto-type-mismatch]
30 | npy_cdouble special_cexp1(npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:145:13: note: return value type mismatch
145 | npy_cdouble special_cexp1(npy_cdouble z) { return to_ccomplex(special::exp1(to_complex(z))); }
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:145:13: note: ‘special_cexp1’ was previously declared here
145 | npy_cdouble special_cexp1(npy_cdouble z) { return to_ccomplex(special::exp1(to_complex(z))); }
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:145:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:33:13: error: type of ‘special_cexpi’ does not match original declaration [-Werror=lto-type-mismatch]
33 | npy_cdouble special_cexpi(npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:149:13: note: return value type mismatch
149 | npy_cdouble special_cexpi(npy_cdouble z) { return to_ccomplex(special::expi(to_complex(z))); }
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:149:13: note: ‘special_cexpi’ was previously declared here
149 | npy_cdouble special_cexpi(npy_cdouble z) { return to_ccomplex(special::expi(to_complex(z))); }
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:149:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
scipy/special/_ufuncs_defs.h:53:9: error: type of ‘cfresnl_wrap’ does not match original declaration [-Werror=lto-type-mismatch]
53 | npy_int cfresnl_wrap(npy_cdouble, npy_cdouble *, npy_cdouble *);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:196:5: note: type mismatch in parameter 1
196 | int cfresnl_wrap(npy_cdouble z, npy_cdouble *zfs, npy_cdouble *zfc) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘complex double’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:196:5: note: ‘cfresnl_wrap’ was previously declared here
196 | int cfresnl_wrap(npy_cdouble z, npy_cdouble *zfs, npy_cdouble *zfc) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:196:5: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:123:13: error: type of ‘special_ccyl_hankel_1’ does not match original declaration [-Werror=lto-type-mismatch]
123 | npy_cdouble special_ccyl_hankel_1(double v, npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:385:13: note: return value type mismatch
385 | npy_cdouble special_ccyl_hankel_1(double v, npy_cdouble z) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:385:13: note: ‘special_ccyl_hankel_1’ was previously declared here
385 | npy_cdouble special_ccyl_hankel_1(double v, npy_cdouble z) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:385:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:125:13: error: type of ‘special_ccyl_hankel_1e’ does not match original declaration [-Werror=lto-type-mismatch]
125 | npy_cdouble special_ccyl_hankel_1e(double v, npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:389:13: note: return value type mismatch
389 | npy_cdouble special_ccyl_hankel_1e(double v, npy_cdouble z) {
| ^
../../../../../../../usr/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_common.h:362:3: note: type ‘struct npy_cdouble’ should match type ‘npy_cdouble’
362 | } npy_cdouble;
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:389:13: note: ‘special_ccyl_hankel_1e’ was previously declared here
389 | npy_cdouble special_ccyl_hankel_1e(double v, npy_cdouble z) {
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:389:13: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../scipy-9999/scipy/special/special_wrappers.h:124:13: error: type of ‘special_ccyl_hankel_2’ does not match original declaration [-Werror=lto-type-mismatch]
124 | npy_cdouble special_ccyl_hankel_2(double v, npy_cdouble z);
| ^
../scipy-9999/scipy/special/special_wrappers.cpp:393:13: note: return value type mismatch
393 | npy_cdouble special_ccyl_hankel_2(double v, npy_cdouble z) {
| ^
../../../../../../../usr/libSource: scipy/scipy