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

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

Open
Lapshin opened this issue Oct 10, 2024 · 9 comments
Open

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

Lapshin opened this issue Oct 10, 2024 · 9 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes build The build process and cross-build topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@Lapshin
Copy link

Lapshin commented Oct 10, 2024

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

@Lapshin Lapshin added the type-bug An unexpected behavior, bug, or error label Oct 10, 2024
@colesbury
Copy link
Contributor

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

cpython/configure.ac

Lines 7498 to 7545 in 01fc3b3

AC_CACHE_CHECK([whether libatomic is needed by <pyatomic.h>],
[ac_cv_libatomic_needed],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
// pyatomic.h needs uint64_t and Py_ssize_t types
#include <stdint.h> // int64_t, intptr_t
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> // ssize_t
#endif
// Code adapted from Include/pyport.h
#if HAVE_SSIZE_T
typedef ssize_t Py_ssize_t;
#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
typedef intptr_t Py_ssize_t;
#else
# error "unable to define Py_ssize_t"
#endif
#include "pyatomic.h"
int main()
{
uint64_t value;
_Py_atomic_store_uint64(&value, 2);
if (_Py_atomic_or_uint64(&value, 8) != 2) {
return 1; // error
}
if (_Py_atomic_load_uint64(&value) != 10) {
return 1; // error
}
uint8_t byte = 0xb8;
if (_Py_atomic_or_uint8(&byte, 0x2d) != 0xb8) {
return 1; // error
}
if (_Py_atomic_load_uint8(&byte) != 0xbd) {
return 1; // error
}
return 0; // all good
}
]])],
[ac_cv_libatomic_needed=no], dnl build succeeded
[ac_cv_libatomic_needed=yes], dnl build failed
[ac_cv_libatomic_needed=no]) dnl cross compilation
])
AS_VAR_IF([ac_cv_libatomic_needed], [yes],
[LIBS="${LIBS} -latomic"
LIBATOMIC=${LIBATOMIC-"-latomic"}])
_RESTORE_VAR([CPPFLAGS])

@colesbury
Copy link
Contributor

Oh, I guess we disabled it for cross compilation (#109211). cc @vstinner @erlend-aasland

@colesbury
Copy link
Contributor

Could we use AC_LINK_IFELSE instead of AC_RUN_IFELSE for this check?

@ZeroIntensity ZeroIntensity added build The build process and cross-build topic-free-threading labels Oct 10, 2024
@vstinner
Copy link
Member

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
Copy link
Member

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

@erlend-aasland
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

@colesbury colesbury added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Oct 13, 2024
colesbury added a commit to colesbury/cpython that referenced this issue Oct 13, 2024
We previously used `AC_RUN_IF_ELSE` with a short test program to detect
if `-latomic` is needed, but that requires choosing a specific default
value when cross-compiling because the test program is not run.
Some cross compilation targets like `wasm32-emscripten` do not support
`-latomic`, while other cross compilation targets, like
`arm-linux-gnueabi` require it.
@erlend-aasland
Copy link
Contributor

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.

colesbury added a commit that referenced this issue Oct 15, 2024
…125416)

We previously used `AC_RUN_IF_ELSE` with a short test program to detect
if `-latomic` is needed, but that requires choosing a specific default
value when cross-compiling because the test program is not run.
Some cross compilation targets like `wasm32-emscripten` do not support
`-latomic`, while other cross compilation targets, like
`arm-linux-gnueabi` require it.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 15, 2024
…ded (pythonGH-125416)

We previously used `AC_RUN_IF_ELSE` with a short test program to detect
if `-latomic` is needed, but that requires choosing a specific default
value when cross-compiling because the test program is not run.
Some cross compilation targets like `wasm32-emscripten` do not support
`-latomic`, while other cross compilation targets, like
`arm-linux-gnueabi` require it.
(cherry picked from commit 8d42e2d)

Co-authored-by: Sam Gross <[email protected]>
vstinner pushed a commit that referenced this issue Oct 15, 2024
…eded (GH-125416) (#125493)

gh-125269: Use `AC_LINK_IF_ELSE` to detect if `-latomic` is needed (GH-125416)

We previously used `AC_RUN_IF_ELSE` with a short test program to detect
if `-latomic` is needed, but that requires choosing a specific default
value when cross-compiling because the test program is not run.
Some cross compilation targets like `wasm32-emscripten` do not support
`-latomic`, while other cross compilation targets, like
`arm-linux-gnueabi` require it.
(cherry picked from commit 8d42e2d)

Co-authored-by: Sam Gross <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes build The build process and cross-build topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants