Repository navigation
Undefined references to HACL symbols when statically linking Python 3.12 #131298
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 15, 2025 - addedextension-modulesC modules in the Modules dirC modules in the Modules dirbuildThe build process and cross-buildThe build process and cross-build
on Mar 15, 2025 If the PR wasn't deemed necessary then it won't probably be implemented. Is there any workaround that doesn't include compiling Python from source?
A possible workaround, if you don't need HACL is to create and compile the following .cpp file in your project:
#include <cstddef> #include <cstdlib> extern "C" { void* python_hashlib_Hacl_Hash_SHA2_malloc_512() {} void python_hashlib_Hacl_Hash_SHA2_free_512(void* ptr) {} void python_hashlib_Hacl_Hash_SHA2_update_512(void*, const void*, size_t) {} void python_hashlib_Hacl_Hash_SHA2_digest_512(void*, void*) {} void python_hashlib_Hacl_Hash_SHA2_copy_512(void*, void*) {} void* python_hashlib_Hacl_Hash_SHA2_malloc_256() {} void python_hashlib_Hacl_Hash_SHA2_free_256(void* ptr) {} void python_hashlib_Hacl_Hash_SHA2_update_256(void*, const void*, size_t) {} void python_hashlib_Hacl_Hash_SHA2_digest_256(void*, void*) {} void python_hashlib_Hacl_Hash_SHA2_copy_256(void*, void*) {} void* python_hashlib_Hacl_Hash_SHA2_malloc_224() {} void* python_hashlib_Hacl_Hash_SHA2_malloc_384() {} }
Ah. I think I should have complicated the builds even more :D in my latest HMAC PR, I actually made all objects as being static because it was easier. I'll eliminate those for the upcoming 3.14 beta and make them fully dynamic (I think we can mostly do this now). My very very bad.
Reacted by Luís Tomás Cabete de Almeida- added a commit that references this issue
on Apr 20, 2025 There is #133012 that is pending but now it should work for Python 3.14 and later. I don't want to backport the fix though because 3.12 is security-only. Maybe a backport to 3.13 is possible though but the build process has been changed too much and I fear too many conflicts.
Reacted by Luís Tomás Cabete de Almeida- added a commit that references this issue
on Apr 26, 2025
Bug report
Bug description:
I am developing an application that uses Python 3.12's static library (libpython3.12.a). Due to some restrictions, I am required to use a package manager to install Python and cannot compile it from source. Additionally, I can't use dynamic libraries, so I must link python statically.
When linking libpython3.12.a to my project, I encounter undefined references to HACL (HACL*) symbols, such as:
These symbols appear to be related to the HACL library, which is included in Python 3.12's development. However, I cannot locate the corresponding object files or static libraries for HACL in the Python installation provided by the package manager.
I was previously using python3.11 - which worked flawlessly -, however the dev package has been removed from apt and other similar package managers. For this specific reason, I had to upgrade.
A quick note, the command
nm -gA /usr/lib/x86_64-linux-gnu/*.a 2>/dev/null | grep python_hashlib_Hacl_Hash_SHA2_update_512shows that these symbols are shipped with the static package:/usr/lib/x86_64-linux-gnu/libpython3.12.a:sha2module.o: U python_hashlib_Hacl_Hash_SHA2_update_512.Steps to Reproduce:
apton Ubuntu).libpython3.12.ainto a C/C++ project.Expected Behavior:
The static library libpython3.12.a should include all necessary dependencies, including HACL, or provide a way to link against HACL statically.
Actual Behavior:
The linker fails with undefined references to HACL symbols, as the required HACL objects or static libraries are not provided.
Questions:
Thank you for your assistance.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs