python / cpython

The Python programming language
https://www.python.org
Other
63.3k stars 30.3k forks source link

cross-compile error: undefined reference to `__atomic_load_8' #125269

Open Lapshin opened 2 weeks ago

Lapshin commented 2 weeks ago

Bug report

Bug description:

Should not configure script check if -latomic is needed?

getting build error when cross-compile:

arm-linux-gnueabi-gcc -L/opt/zlib-arm-linux-gnueabi/lib -L/opt/xz-arm-linux-gnueabi/lib -L/opt/readline-arm-linux-gnueabi/lib -L/opt/libffi-arm-linux-gnueabi/lib -L/opt/libtirpc-arm-linux-gnueabi/lib -L/opt/libuuid-arm-linux-gnueabi/lib -L/opt/zlib-arm-linux-gnueabi/lib -L/opt/xz-arm-linux-gnueabi/lib -L/opt/readline-arm-linux-gnueabi/lib -L/opt/libffi-arm-linux-gnueabi/lib -L/opt/libtirpc-arm-linux-gnueabi/lib -L/opt/libuuid-arm-linux-gnueabi/lib   -Xlinker -export-dynamic -o Programs/_testembed Programs/_testembed.o -L. -lpython3.13 -lpthread -ldl  -lpthread -lutil                          -lm 
/root/x-tools/arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/13.2.0/../../../../arm-linux-gnueabi/bin/ld: ./libpython3.13.so: undefined reference to `__atomic_load_8'
/root/x-tools/arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/13.2.0/../../../../arm-linux-gnueabi/bin/ld: ./libpython3.13.so: undefined reference to `__atomic_store_8'
/root/x-tools/arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/13.2.0/../../../../arm-linux-gnueabi/bin/ld: ./libpython3.13.so: undefined reference to `__atomic_fetch_add_8'
/root/x-tools/arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/13.2.0/../../../../arm-linux-gnueabi/bin/ld: ./libpython3.13.so: undefined reference to `__atomic_compare_exchange_8'
collect2: error: ld returned 1 exit status

configure cmd line:

./configure --prefix=/opt/python-arm-linux-gnueabi-3.13.0 --host=arm-linux-gnueabi --target=arm-linux-gnueabi --build=x86_64-linux-gnu --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no  --enable-shared --with-openssl=/opt/openssl-arm-linux-gnueabi --with-build-python=/root/.pyenv/versions/3.13.0/bin/python

workaround

export LDFLAGS="-latomic $LDFLAGS"

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

colesbury commented 2 weeks ago

The configure script has a check for -latomic. I'm not sure why it's not working on your system:

https://github.com/python/cpython/blob/01fc3b34cc6994bc83b6540da3a8573e79dfbb56/configure.ac#L7498-L7545

colesbury commented 2 weeks ago

Oh, I guess we disabled it for cross compilation (https://github.com/python/cpython/pull/109211). cc @vstinner @erlend-aasland

colesbury commented 2 weeks ago

Could we use AC_LINK_IFELSE instead of AC_RUN_IFELSE for this check?

vstinner commented 2 weeks ago

Could we use AC_LINK_IFELSE instead of AC_RUN_IFELSE for this check?

I don't know, it's beyond my autotools skills :-) Maybe @erlend-aasland or @corona10 knows.

vstinner commented 2 weeks ago

I don't know autotools. When Python is cross-compiled, does AC_RUN_IFELSE build the program? Or does it do nothing?

erlend-aasland commented 2 weeks ago

IIRC, the LINK variant only runs the linker, so it should work on a correctly setup cross-compiling environment. The RUN variant also runs the resulting executable, which will fail in a cross-compiling dev environment.

erlend-aasland commented 2 weeks ago

Ah, the check in our configure script defaults to not requiring libatomic if we are cross compiling. Perhaps we want to change that configure branch.

colesbury commented 2 weeks ago

Ah, the check in our configure script defaults to not requiring libatomic if we are cross compiling. Perhaps we want to change that configure branch.

Looking at the past PRs:

IIRC, the LINK variant only runs the linker, so it should work on a correctly setup cross-compiling environment

I think the link time check should be sufficient for both cross-compiling and native compilation (famous last words). I'll give it a go.

erlend-aasland commented 2 weeks ago

I think the link time check should be sufficient for both cross-compiling and native compilation (famous last words). I'll give it a go.

Yes, that aligns with my assumptions as well. Let's try.