sqlite-jdbc
sqlite-jdbc copied to clipboard
Static/Dynamic linking of sqlite shadows symbols needed for RTree* callbacks
This issue effects mainly using deprecated functions in spatialite.
- RTreeWithin
- RTreeContains
- RTreeIntersects
- RTreeDistWithin
via the sqlite3_rtree_geometry_callback
If one does a search for RTreeIntersects they will find lots of
[SQLITE_ERROR] SQL error or missing database (no such function: RTreeIntersects)
And when traced through with a debugger the calls will seemingly disappear. Like in this issue (same effect, not xerial related)
What happens is that the JNI lib that xerial loads, calls to select load_extension('mod_spatialite') which then dynamically loads libsqlite makes a call to sqlite3_rtree_geometry_callback. The callbacks are registered in this second copy of sqlite, not the original. So when one attempts to call RTreeIntersects, the sqlite engine loaded by xerial knows nothing about it. Bermuda Triangle of function calls. The solution for those needing a quick hack is link in your libsqlite from the system.
In Makefile
- $(CC) $(CFLAGS) -o $@ $(SQLITE_OUT)/*.o $(LINKFLAGS)
- $(STRIP) $@
+ $(CC) $(CFLAGS) -o $@ $(SQLITE_OUT)/NativeDB.o $(LINKFLAGS)
in Makefile.common
-Default_LINKFLAGS := -shared
+Default_LINKFLAGS := -shared -L/usr/local/lib -lsqlite3
Did you confirm this fix works well? I'm a little bit hesitate to apply this fix since it will expose sqlite3 functions in a different copy, which are already hidden by -fvisibility=hidden flag.
Just a local hack for now. Working on a better long term solution.
It isn't the visiblity=hidden that is doing it. Dynamic linking is a fairly complex subject and I am no expert, but when the mod_spatialite extension dynamically links to libsqlite it doesn't get the symbols from the original libsqlitejdbc.so included in the archive, it gets a new copy.
I think what would need to happen is that NativeDB.c would need to be dynamically linked against libsqlite so that xerial could both ship an internal libsqlite AND be able to defer to the platform version. Both the new JNI lib with just NativeDB and the shipped libsqlite would need to be extracted from the jar archive on load.
Is this still happening on the latest version?