Landfall

Annotated tools/listlibs.sh

26:b921e4f8cd4c
2018-05-29 Paul Boddie Added a script that attempts to show library module requirements for a payload. This also shows a library that will not be detected.
paul@26 1
#!/bin/sh
paul@26 2
paul@26 3
CONF="$1"
paul@26 4
paul@26 5
if [ ! "$CONF" ] || [ ! -e "$CONF" ] ; then
paul@26 6
    cat 1>&2 <<EOF
paul@26 7
Usage: $0 <configuration filename>
paul@26 8
paul@26 9
List modules required by the given system/payload configuration. These modules
paul@26 10
should be added to the configuration file so that the dynamic linker can find
paul@26 11
them in the running system.
paul@26 12
EOF
paul@26 13
    exit 1
paul@26 14
fi
paul@26 15
paul@26 16
BIN=mybuild/bin/mips_32/l4f
paul@26 17
TMPLIBS=_libs.txt
paul@26 18
paul@26 19
echo -n > "$TMPLIBS"
paul@26 20
paul@26 21
for MODULE in `grep '^module ' "$CONF" | sed 's/module //'` ; do
paul@26 22
    PROG=`basename "$MODULE" .cfg`
paul@26 23
    if [ "$PROG" != "$MODULE" ] ; then
paul@26 24
        continue
paul@26 25
    fi
paul@26 26
    PROG=`basename "$MODULE" .io`
paul@26 27
    if [ "$PROG" != "$MODULE" ] ; then
paul@26 28
        continue
paul@26 29
    fi
paul@26 30
    PROG=`basename "$MODULE" .so`
paul@26 31
    if [ "$PROG" != "$MODULE" ] ; then
paul@26 32
        continue
paul@26 33
    fi
paul@26 34
    if [ ! -e "$BIN/$PROG" ] ; then
paul@26 35
        echo "Not found: $PROG" 1>&2
paul@26 36
        exit 1
paul@26 37
    fi
paul@26 38
    mipsel-linux-gnu-readelf -d "$BIN/$PROG" | grep NEEDED | sed 's/.*\[//;s/\]$//' >> "$TMPLIBS"
paul@26 39
done
paul@26 40
paul@26 41
# Explicitly add undetected module.
paul@26 42
paul@26 43
echo "libl4sys-direct.so" >> "$TMPLIBS"
paul@26 44
paul@26 45
sort -u "$TMPLIBS" | sed 's/^/module /'
paul@26 46
rm "$TMPLIBS"