-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Undefined references to HACL symbols when statically linking Python 3.12 #131298
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
Comments
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. |
…GH-132438) * simplify HACL* build for MD5, SHA1, SHA2 and SHA3 modules * remove statically linked libraries for HACL* implementation * is it better now? * is it better now? * fixup * Present HACL* as a static or shared library. On WASI, extension modules based on HACL* require the HACL* library to be linked statically. On other platforms, it can be built dynamically. * amend whitespace * remove temporary .so file as it requires more symlinks * avoid smelly symbols * fixup checksums * regen sbom * fixup shell warnings and comments * it *should* work
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. |
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_512
shows 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:
apt
on Ubuntu).libpython3.12.a
into 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
The text was updated successfully, but these errors were encountered: