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

ARM Raspbian 3.x fails to build _testcapi extension: undefined symbol: __atomic_fetch_or_8 #109054

Closed
vstinner opened this issue Sep 7, 2023 · 23 comments

Comments

@vstinner
Copy link
Member

vstinner commented Sep 7, 2023

I supposed that the build error is related to Modules/_testcapi/pyatomic.c and Include/cpython/pyatomic.h.

"Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware."

Buildbot worker says: "Raspberry Pi 4 B running Raspbian (Bullseye 11.x)."

test.pythoninfo:

  • CC.version: gcc (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110
  • platform.architecture: 32bit ELF
  • platform.libc_ver: glibc 2.31
  • platform.platform: Linux-6.1.21-v8+-aarch64-with-glibc2.31
  • sysconfig[PY_CFLAGS]: -fno-strict-overflow -DNDEBUG -g -O3 -Wall -UNDEBUG
  • sysconfig[PY_CFLAGS_NODIST]: -std=c11 -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal
  • sysconfig[PY_STDMODULE_CFLAGS]: -fno-strict-overflow -DNDEBUG -g -O3 -Wall -UNDEBUG -std=c11 -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include

Logs:

gcc -pthread -shared      Modules/_testcapimodule.o Modules/_testcapi/vectorcall.o Modules/_testcapi/vectorcall_limited.o Modules/_testcapi/heaptype.o Modules/_testcapi/abstract.o Modules/_testcapi/unicode.o Modules/_testcapi/dict.o Modules/_testcapi/getargs.o Modules/_testcapi/datetime.o Modules/_testcapi/docstring.o Modules/_testcapi/mem.o Modules/_testcapi/watchers.o Modules/_testcapi/long.o Modules/_testcapi/float.o Modules/_testcapi/structmember.o Modules/_testcapi/exceptions.o Modules/_testcapi/code.o Modules/_testcapi/buffer.o Modules/_testcapi/pyatomic.o Modules/_testcapi/pyos.o Modules/_testcapi/immortal.o Modules/_testcapi/heaptype_relative.o Modules/_testcapi/gc.o   -o Modules/_testcapi.cpython-313-arm-linux-gnueabihf.so
[ERROR] _testcapi failed to import: /var/lib/buildbot/workers/3.x.gps-raspbian.nondebug/build/build/lib.linux-aarch64-3.13/_testcapi.cpython-313-arm-linux-gnueabihf.so: undefined symbol: __atomic_fetch_or_8
The necessary bits to build these optional modules were not found:
_tkinter              _uuid                                    
To find the necessary bits, look in configure.ac and config.log.

Following modules built successfully but were removed because they could not be imported:
_testcapi                                                      

Checked 107 modules (31 built-in, 72 shared, 1 n/a on linux-aarch64, 0 disabled, 2 missing, 1 failed on import)

logs: https://buildbot.python.org/all/#/builders/424/builds/4849

cc @colesbury @gpshead

Linked PRs

@vstinner
Copy link
Member Author

vstinner commented Sep 7, 2023

Maybe Python should be linked to -latomic. Old GCC discussions:

@vstinner
Copy link
Member Author

vstinner commented Sep 7, 2023

@vstinner
Copy link
Member Author

vstinner commented Sep 7, 2023

I confirm that this regression comes from the commit 2bd960b.

@colesbury
Copy link
Contributor

I'm on vacation this week, but I'll have some time to look at this this evening.

@vstinner
Copy link
Member Author

vstinner commented Sep 7, 2023

I never heard about Raspbian before. I was curious about it, so I added platform.freedesktop_os_release() to test.pythoninfo :-)

platform.freedesktop_os_release[ID]: raspbian
platform.freedesktop_os_release[NAME]: Raspbian GNU/Linux
platform.freedesktop_os_release[VERSION]: 11 (bullseye)
platform.freedesktop_os_release[VERSION_CODENAME]: bullseye
platform.freedesktop_os_release[VERSION_ID]: 11

vstinner added a commit to vstinner/cpython that referenced this issue Sep 7, 2023
Check if <cpython/pyatomic.h> needs to be linked to libatomic.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 7, 2023
Fix building the _testcapi extension on ARM Raspbian which requires
linking to libatomic when <cpython/pyatomic.h> is used.

* configure checks if programs using <cpython/pyatomic.h> need to be
  linked to libatomic.
* Add LIBATOMIC variable to Makefile.
* _testcapi extension now uses the LIBATOMIC variable in its LDFLAGS,
  since Modules/_testcapi/pyatomic.c uses <cpython/pyatomic.h>.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 7, 2023
Fix building the _testcapi extension on ARM Raspbian which requires
linking to libatomic when <cpython/pyatomic.h> is used.

* configure checks if programs using <cpython/pyatomic.h> need to be
  linked to libatomic.
* Add LIBATOMIC variable to Makefile.
* _testcapi extension now uses the LIBATOMIC variable in its LDFLAGS,
  since Modules/_testcapi/pyatomic.c uses <cpython/pyatomic.h>.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 7, 2023
Fix building the _testcapi extension on ARM Raspbian which requires
linking to libatomic when <cpython/pyatomic.h> is used.

* configure checks if programs using <cpython/pyatomic.h> need to be
  linked to libatomic.
* Add LIBATOMIC variable to Makefile.
* _testcapi extension now uses the LIBATOMIC variable in its LDFLAGS,
  since Modules/_testcapi/pyatomic.c uses <cpython/pyatomic.h>.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 7, 2023
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint8() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

_testcapi extension now uses the LIBATOMIC variable in its LDFLAGS,
since Modules/_testcapi/pyatomic.c uses <cpython/pyatomic.h>.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 7, 2023
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint8() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

Building the _testcapi extension now uses the LIBATOMIC variable in
its LDFLAGS, since Modules/_testcapi/pyatomic.c uses
<cpython/pyatomic.h>.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 7, 2023
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint8() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

Building the _testcapi extension now uses the LIBATOMIC variable in
its LDFLAGS, since Modules/_testcapi/pyatomic.c uses
<cpython/pyatomic.h>.
@colesbury
Copy link
Contributor

From @vstinner's comments and playing with https://gcc.godbolt.org/, it looks like the 8 byte (64-bit) use library support with the default compiler options on this platform. GCC doesn't need the library support if you target -march=armv7-a (the ARMv7-A and ARMv7-R profiles support the ldrexd "double-word" exclusive load).

Some random other things that I learned, but are probably not important:

  • Raspbian is now called Raspberry Pi OS
  • The Raspberry Pi Model B's have used a 64-bit CPUs (armv8-a) since ~2016, but the Raspbian/Raspberry Pi OS was 32-bit only until 2022 and it seems like 32-bit OS is still the most commonly used

vstinner added a commit to vstinner/cpython that referenced this issue Sep 8, 2023
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint64() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

Building the _testcapi extension now uses the LIBATOMIC variable in
its LDFLAGS, since Modules/_testcapi/pyatomic.c uses
<cpython/pyatomic.h>.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 8, 2023
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint64() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

Building the _testcapi extension now uses the LIBATOMIC variable in
its LDFLAGS, since Modules/_testcapi/pyatomic.c uses
<cpython/pyatomic.h>.
@vstinner
Copy link
Member Author

vstinner commented Sep 8, 2023

From @vstinner's comments and playing with https://gcc.godbolt.org/, it looks like the 8 byte (64-bit) use library support with the default compiler options on this platform. GCC doesn't need the library support if you target -march=armv7-a (the ARMv7-A and ARMv7-R profiles support the ldrexd "double-word" exclusive load).

It's nice if libatomic can be omitted depending on the compiler and compiler flags, but I would like to cover all cases :-) We should detect and add -latomic when needed.

@ayappanec
Copy link
Contributor

AIX also fails to build because of this problem.
Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp Modules/_testcapimodule.o Modules/_testcapi/vectorcall.o Modules/_testcapi/vectorcall_limited.o Modules/_testcapi/heaptype.o Modules/_testcapi/abstract.o Modules/_testcapi/unicode.o Modules/_testcapi/dict.o Modules/_testcapi/getargs.o Modules/_testcapi/datetime.o Modules/_testcapi/docstring.o Modules/_testcapi/mem.o Modules/_testcapi/watchers.o Modules/_testcapi/long.o Modules/_testcapi/float.o Modules/_testcapi/structmember.o Modules/_testcapi/exceptions.o Modules/_testcapi/code.o Modules/_testcapi/buffer.o Modules/_testcapi/pyatomic.o Modules/_testcapi/pyos.o Modules/_testcapi/immortal.o Modules/_testcapi/heaptype_relative.o Modules/_testcapi/gc.o -o Modules/_testcapi.cpython-313.so
ld: 0711-327 WARNING: Entry point not found: PyInit__testcapi.cpython-313
ld: 0711-317 ERROR: Undefined symbol: .__atomic_fetch_or_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_fetch_and_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_load_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_store_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_exchange_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_compare_exchange_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_fetch_add_8

Need -latomic to be passed. I see MODULE__TESTCAPI_LDFLAGS variable in the generated Makefile but not populated with anything

@vstinner
Copy link
Member Author

vstinner commented Sep 8, 2023

AIX also fails to build because of this problem.

Can you try my PR? Does it fix your issue?

@ayappanec
Copy link
Contributor

ayappanec commented Sep 8, 2023

AIX also fails to build because of this problem.

Can you try my PR? Does it fix your issue?

https://github.com/vstinner/cpython/tree/configure_libatomic
It still failed with the same error

The config.log has this

configure:27770: checking whether libatomic is needed by <pyatomic.h>
configure:27815: gcc -pthread -o conftest -I. -I./Include conftest.c -lintl -ldl >&5
conftest.c:422: warning: "PY_BUILTIN_HASHLIB_HASHES" redefined
422 | #define PY_BUILTIN_HASHLIB_HASHES "md5,sha1,sha2,sha3,blake2"
|
conftest.c:421: note: this is the location of the previous definition
421 | #define PY_BUILTIN_HASHLIB_HASHES /**/
|
ld: 0711-317 ERROR: Undefined symbol: .__atomic_fetch_or_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_load_8
ld: 0711-317 ERROR: Undefined symbol: .__atomic_store_8
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: error: ld returned 8 exit status
configure:27815: $? = 1
configure: program exited with status 1

@ayappanec
Copy link
Contributor

In AIX, only the 32bit build fails. 64bit build doesn't require -latomic looks like.

@vstinner
Copy link
Member Author

vstinner commented Sep 8, 2023

The config.log has this

What does the configure say? Does it say checking whether libatomic is needed by <pyatomic.h>... yes?

Also, check if make links _testcapi with -latomic. Or check grep '_TESTCAPI_.*=' Makefile command to see if you have -latomic in MODULE__TESTCAPI_LDFLAGS.

@ayappanec
Copy link
Contributor

https://github.com/vstinner/cpython/blob/configure_libatomic/configure#L27834
This line has some typo error I guess.

@ayappanec
Copy link
Contributor

LIBATOMIC=${LIBATOMIC-"-latomic"}

@ayappanec
Copy link
Contributor

The config.log has this

What does the configure say? Does it say checking whether libatomic is needed by <pyatomic.h>... yes?

Also, check if make links _testcapi with -latomic. Or check grep '_TESTCAPI_.*=' Makefile command to see if you have -latomic in MODULE__TESTCAPI_LDFLAGS.

MODULE__TESTCAPI_LDFLAGS is never populated with $LIBATOMIC, even though "MODULE__TESTCAPI_STATE=yes"

vstinner added a commit to vstinner/cpython that referenced this issue Sep 8, 2023
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint64() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

Building the _testcapi extension now uses the LIBATOMIC variable in
its LDFLAGS, since Modules/_testcapi/pyatomic.c uses
<cpython/pyatomic.h>.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@vstinner
Copy link
Member Author

vstinner commented Sep 8, 2023

This line has some typo error I guess.

LIBATOMIC=${LIBATOMIC-"-latomic"} is a dark spell of @erlend-aasland.

Sorry but I don't understand you test. Please:

  • Apply my latest PR (I just updated it)
  • Run ./configure
  • Check checking whether libatomic is needed by <pyatomic.h> line in configure output. Is it yes or not?
  • Check MODULE__TESTCAPI_LDFLAGS in Makefile: what is the variable value?

It's not clear to me if you ran your test on 32-bit or 64-bit AIX.

@ayappanec
Copy link
Contributor

This line has some typo error I guess.

LIBATOMIC=${LIBATOMIC-"-latomic"} is a dark spell of @erlend-aasland.

Sorry but I don't understand you test. Please:

  • Apply my latest PR (I just updated it)
  • Run ./configure
  • Check checking whether libatomic is needed by <pyatomic.h> line in configure output. Is it yes or not?
  • Check MODULE__TESTCAPI_LDFLAGS in Makefile: what is the variable value?

It's not clear to me if you ran your test on 32-bit or 64-bit AIX.

I did a fresh
git clone https://github.com/vstinner/cpython
cd cpython
git checkout configure_libatomic
./configure

checking whether libatomic is needed by <pyatomic.h>, the result is yes
But "MODULE__TESTCAPI_LDFLAGS= " is still empty in Makefile.

It's a 32bit build. In AIX ,the default build environment is 32bit.

64bit build in AIX works as it doesn't require -latomic .

@ayappanec
Copy link
Contributor

LIBATOMIC=""
LIBATOMIC=${LIBATOMIC-"-latomic"}
echo $LIBATOMIC

This scenario never works

@ayappanec
Copy link
Contributor

LIBATOMIC=${LIBATOMIC:-"-latomic"} will work instead.

@vstinner
Copy link
Member Author

vstinner commented Sep 8, 2023

I fixed (again ;-)) my PR. Please test it.

The problem is that LIBATOMIC=${LIBATOMIC-"-latomic"} does nothing if the LIBATOMIC variable is already defined. And I defined it to an empty string with LIBATOMIC="".

@ayappanec
Copy link
Contributor

I fixed (again ;-)) my PR. Please test it.

The problem is that LIBATOMIC=${LIBATOMIC-"-latomic"} does nothing if the LIBATOMIC variable is already defined. And I defined it to an empty string with LIBATOMIC="".

It works now.

@vstinner
Copy link
Member Author

vstinner commented Sep 8, 2023

It works now.

Thanks for testing it!

vstinner added a commit that referenced this issue Sep 8, 2023
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint64() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

Building the _testcapi extension now uses the LIBATOMIC variable in
its LDFLAGS, since Modules/_testcapi/pyatomic.c uses
<cpython/pyatomic.h>.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@vstinner
Copy link
Member Author

vstinner commented Sep 8, 2023

Fixed by 1f7e421

@vstinner vstinner closed this as completed Sep 8, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 10, 2023
configure no longer uses libatomic by default when Python is
cross-compiled. The LIBATOMIC variable can be set manually in this
case:

    ./configure LIBATOMIC="-latomic" (...)
vstinner added a commit to vstinner/cpython that referenced this issue Sep 10, 2023
configure no longer uses libatomic by default when Python is
cross-compiled. The LIBATOMIC variable can be set manually in this
case:

    ./configure LIBATOMIC="-latomic" (...)
vstinner added a commit to vstinner/cpython that referenced this issue Sep 10, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 10, 2023
vstinner added a commit that referenced this issue Sep 10, 2023
configure no longer uses libatomic by default when Python is
cross-compiled. The LIBATOMIC variable can be set manually in this
case:

    ./configure LIBATOMIC="-latomic" (...)
vstinner added a commit to vstinner/cpython that referenced this issue Sep 13, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 13, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 19, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 19, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 19, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 19, 2023
csm10495 pushed a commit to csm10495/cpython that referenced this issue Sep 28, 2023
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

No branches or pull requests

3 participants