From 3c3d81e5a001b82fadb75607b35b303e4c46f7bf Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 14 Mar 2022 20:31:12 +0100 Subject: mbuto: Add support for additional libraries typically loaded via dlopen(3) Example: glibc needs, for basic tasks such as domain resolution, libnss_files and libnss_dns, which in turn links to libresolv. Add a LIBS_DLOPEN variable to hold pairs of libraries typically doing this and additional libraries to copy -- not a complete list, just what's strictly needed for basic functionality. Signed-off-by: Stefano Brivio --- mbuto | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mbuto b/mbuto index 5f11319..f3fb96c 100755 --- a/mbuto +++ b/mbuto @@ -27,6 +27,12 @@ PROGS="${PROGS:-kata-agent ash,dash,bash ip mount ls modprobe insmod mkdir nsenter ln}" +# Libraries commonly loaded via dlopen(3) (strictly needed for basic tasks) +LIBS_DLOPEN="${LIBS_DLOPEN:- + libc.so.6 libnss_dns.so.2 + libc.so.6 libnss_files.so.2 +}" + # Links: installed target program, then link name, one per line LINKS="${LINKS:- kata-agent /init @@ -397,6 +403,21 @@ libs_copy_ld_so() { "${CP}" --parents --preserve=all "${1}" "${wd}" } +# libs_dlopen_copy() - Recursively copy matching libraries from LIBS_DLOPEN +# $1: Library (base path) that loads further libraries using dlopen(3) +libs_dlopen_copy() { + __match= + for __t in ${LIBS_DLOPEN}; do + [ -z "${__match}" ] && __match="${__t}" && continue + if [ "${__match}" = "$(basename ${1})" ]; then + __path="$(dirname "${1}")/${__t}" + "${CP}" --parents --preserve=all "${__path}" "${wd}" + libs_copy "${__path}" + __match= + fi + done +} + # libs_copy() - Recursively copy shared dependencies for programs and libraries # $1: Host path to program or library libs_copy() { @@ -427,6 +448,8 @@ libs_copy() { libs_copy "${__path}" done + libs_dlopen_copy "${1}" + # Dynamic linker is listed as single path, make sure we copy it once __ld_so= for __l in $("${LDD}" "${1}" 2>/dev/null); do @@ -820,6 +843,11 @@ usage() { echo "Environmental variables can be used to replace:" echo " PROGS" echo " base programs" + echo " LIBS_DLOPEN" + echo " additional libraries, not directly linked from" + echo " programs, typically loaded via dlopen(3) by matching" + echo " libraries, in the form" + echo " MATCHING_LIBRARY ADDITIONAL_LIBRARY" echo " KMODS" echo " base kernel modules" echo " NODES" -- cgit v1.2.3