I'm using the SQLite3 package in a small Pascal program and I noticed that my binary is dynamically linked to libc in addition to libsqlite3 (and SDL, but that doesn't come into this story):
> readelf -d highscores
Dynamic section at offset 0x70db8 contains 28 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libSDL2-2.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libsqlite3.so.0]
0x0000000000000001 (NEEDED) Shared library: [libSDL2_image-2.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
...
I wanted to trim down my dependencies to make it easier to deploy my binary, so I looked into what in my program requires libc:
> nm -u highscores
w __cxa_finalize@GLIBC_2.2.5
U dladdr@GLIBC_2.34
U dlclose@GLIBC_2.34
U dlerror@GLIBC_2.34
U dlopen@GLIBC_2.34
U dlsym@GLIBC_2.34
w __gmon_start__
U IMG_LoadTexture
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
U __libc_start_main@GLIBC_2.34
U SDL_AddEventWatch
U sqlite3_libversion
(and other SDL stuff...)
Looks like my program depends on dlopen and friends for some reason. I know that SQLite uses dlopen, but that shouldn't affect the dependencies of my binary.
I found this in sqlite3.inc:
uses
ctypes,
{$ifdef LOAD_DYNAMICALLY}
SysUtils, DynLibs;
{$else}
DynLibs;
LOAD_DYNAMICALLY is set for sqlite3dyn, but not for sqlite3. However, even when LOAD_DYNAMICALLY is
not set, we still
use DynLibs. When I made a copy of sqlite3.inc in my project with DynLibs outside of LOAD_DYNAMICALLY removed, my binary doesn't link to libc anymore.
Is this a mistake in sqlite3.inc? I don't see any uses of LoadLibrary except in an {$ifdef LOAD_DYNAMICALLY} block, so as far as I can see there should be no need for DynLibs in this mode. Does this make sense? If so, I'd be happy to submit a patch to fix it, but I just wonder if I'm missing a valid reason for this to be here.