Repository navigation
Statically linked sqlite3 fails checks due to missing -lm #128321
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 29, 2024 cc @erlend-aasland — I understand you're the expert in this area.
Reacted by Erlend E. Aasland- addedbuildThe build process and cross-buildThe build process and cross-build
on Dec 29, 2024 In addition to #128322, we may also want to include
-lmatLine 4207 in 492b224
LIBSQLITE3_LIBS=${LIBSQLITE3_LIBS-"-lsqlite3"} If the
pkg-configcheck fails, we fallback to including these flags. However, without-lmall of our subsequent checks will fail! Happy to post a pull request for that too.This will result in over-linking when sqlite3 is used as a shared library (no pkg-config --static).
Reacted by Erlend E. Aasland and Zanie BlueThis will result in over-linking when sqlite3 is used as a shared library
Ah true — we could just include it during the checks but it seems like a bit of a pain.
Reacted by Erlend E. Aasland- added a commit that references this issue
on Dec 30, 2024 @zanieb Thank you for finding and fixing this. It's a huge help.
This will result in over-linking when sqlite3 is used as a shared library
Ah true — we could just include it during the checks but it seems like a bit of a pain.
I'm probably missing something, and if so please forgive me.
Since
cpythonwon't be usingpkgconfig --staticany time soon, is it therefor impossible for anyone to compile sqlite3 in statically without patchingconfigurethemselves just to append-lmto theLIBS, and just to successfully satisfy the check? If so, does the overlinking represent a risk for the sqlite symbol check that is worth leaving it in this state, which is basically just broken for this use case?Typically what happens is people who are interested in a static build export
PKG_CONFIG="pkg-config --static"to ensure that all dependencies are detected statically. That will include-lmand also-lz(the latter wasn't mentioned here and it is needed if you build a dynamic python that is statically linked to the sqlite library).So everything works fine using pkg-config, the question is what to do about the fallback.
For a fallback, what you'd typically do is perform a series of compile checks, to see if you can link successfully to sqlite on its own and upon failure check again to see if you can link successfully to sqlite when adding
-lm -lz.I have no objections to the "series of compile checks". I don't think it's fully appropriate in terms of general theory to simply add it unconditionally though. I'm also fine with only supporting pkg-config at all, for my own personal use, but that's another story. :)
I see. It seems to me the project is designed to support static/dynamic choices (and all configuration choices for that matter), on a per-dependency basis. I definitely see it being "very common" that people who want "some deps" compiled in statically want "all deps" statically. On the other hand, it's also "not uncommon" for people to want a subset of deps static. Regardless, it doesn't seem appropriate even in principle to have an "all static or nothing static" support story, just because pkgconfig makes the "all static" case easy. So many other configurations and mechanisms in cpython are in place to make it flexible in this way.
Bug report
Bug description:
On Linux, if I build a static version of sqlite3 (e.g.,
./configure --disable-shared && makefrom a sqlite3 tarball)You can see that
./configurefor CPython fails the SQLite checks (added back in #30016):And in the
config.logthere are a bunch of failures due to undefined references to functions in libm, e.g.:CPython is determing SQLite's requirements via
pkg-configif it can at:cpython/configure.ac
Lines 4204 to 4209 in 492b224
And
-lmis included in thepkg-configfor the static sqlite3 build, but it's in the private libs and requires the--staticflag to be included in the--libsoutput:However,
PKG_CHECK_MODULESdoesn't pass this flag. There's aPKG_CHECK_MODULES_STATICmacro which does, but CPython doesn't seem to use this yet. The alternative is set the flag manually at configure time:which changes all the
PKG_CHECK_MODULEScalls to include the--staticflag. However, there's a missing export forLIBSwhich prevents this from resolving the issue:This is "solved" with the patch:
As demonstrated by:
For context, this was reported in astral-sh/python-build-standalone#449 and some of the findings here are repeated there.
I've posted the patch in #128322
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
LIBSinstead ofLDFLAGSduring sqlite3 library build checks #128322