On 2024-07-10 05:31, Sean Conner wrote:
> It was thus said that the Great Fengkai Sun once stated:
>> By "statically-linked program" to say I mean a program without any external
>> dependency. If so, it needs an interpreter to resolve dependencies at
>> runtime.
>> [...]
G'day,
I think that there's a couple of things going on here, although
my knowledge of details is a little old now.
1. I think that "lua_isnumber" was a symbol that was provided by
earlier (5.1?) versions of Lua, but the client doesn't reference it
directly: The detail comes from the ABI. In this case, you may be
compiling an external module with the wrong version of the ABI.
(In fact, this is also partially what the 5.4.7-rc3 ABI
identification issue was all about.)
2. If you're looking to load a module from Lua, using "require",
the code needs to be compatible with dl_open() at a binary level, as
well as being findable on the LUA_CPATH or LUA_PATH set of paths.
In my lglicua Assistant, I tried to cover this when I switched from
Distro-provided Lua packaging (which was originally missing
versions, or else only had older patchlevels) to downloading and
compiling Lua automagically within the installation process.
See (from lglicua-0.1-beta1):
https://sourceforge.net/p/lglicua/code/ci/master/tree/install/support/lua-generic-utils.sh#l395
The Bash function "localLGU_SourcePatch" prepares Lua for dynamic
linking:
--------
# Part 1: Add item to CFLAGS asking for position-independent
# code.
sed -i -e '/^CFLAGS=/s/$/ -fPIC/' src/Makefile
# Part 2: Add a line to the build target "libluaX.Y.a" ($LUA_A)
# to also create "libluaX.Y.so.0" as part of its recipe.
SOLibBuild="\$(CC) -shared -ldl -Wl,-soname=%s"
SOLibBuild="${SOLibBuild} -Wl,-version-script=luaver.ld"
SOLibBuild="${SOLibBuild} -o %s \$? -lm \$(MYLSFLAGS)"
# shellcheck disable=SC2059
BuildSOCmd="$(printf "$SOLibBuild" "${SOLibFile}.0" "liblua.so")"
# shellcheck disable=SC2016
BuildSOSedCmd="$(printf '/$(RANLIB) $@/a\\\t%s' "$BuildSOCmd")"
sed -i -e "$BuildSOSedCmd" src/Makefile
# Part 3: Create a simple luaver.ld script for the linker.
cat <<EOF >src/luaver.ld
LUA_${cnLuaVer:3} {
global:
*;
};
EOF
"cnLuaVer" means "Canonical Name for Lua Version", e.g. "5.4",
regardless of the patchlevel. (The caller can specify any of
5.1, 5.2, 5.3 or 5.4.)
"SOLibFile" maps to "liblua.so"; this gets used both during the
build, but especially during the library installation function,
see:
https://sourceforge.net/p/lglicua/code/ci/master/tree/install/support/family-ubuntu.sh#l316
--------
# Install Dynamically-loadable shared-object files, using install
# and ldconfig:
# install: "lib/liblua.so" -> "LIBPATH/libluaX.Y.so.0.0.0"
# manual: ( cd "LIBPATH";
# ln -fs "libluaX.Y.so.0.0.0" "
libluaX.Y.so"
# )
# ldconfig.1: symlink-add re "LIBPATH/
libluaX.Y.so*"
# ldconfig.2: cache-update re "
LIBPATHlibluaX.Y.so*"
# ?? SECURITY: USES SUDO. (Several times.)
GenericSOLibFile="$(DBIU_FN Lua:SOLibFile)"
VersionedSOLibFile="$(DBIU_FN "$cnLuaVer" SOLibFile)"
RealSOLibFile="${VersionedSOLibFile}.0.0.0"
sudo install -m 0644 "lib/${GenericSOLibFile}" \
"${LibPath}${RealSOLibFile}"
(
cd "$LibPath" || exit 42
# Create symlink "libluaX.Y.so.0.0.0" -> "
libluaX.Y.so"
sudo ln -fs "$RealSOLibFile" "$VersionedSOLibFile"
# All remaining symlinks are a by-product of ldconfig, along
# with object caching.
sudo ldconfig "${LibPath}/${VersionedSOLibFile}"
)
--------
This results in a Lua version with all symbols exported, and with
position-independent code (-fPIC), so that the dynamic loader can
do its stuff.
We use "make local", which delivers unversioned headers, libraries
and executables purely into the source tree, so that we can
control filenames, particularly adding explicit versioning, when
we install the files into the OS's filesystem. (There may also be
a version-registration step, such as Debian's "update-alternatives",
so that we can switch between versions at runtime.)
--------
cheers, b