#!/bin/bash
PS1='PS1'
PS4='$ '
dir="$(mktemp --tmpdir --directory undefined-symbol.tmp.XXXXXXXX)"
cleanup () { rm --recursive --force "$dir"; }
trap cleanup EXIT
cd "$dir"
set -x
lib="$1"
link="$2"
set +x
set -v
pkg="$(dpkg-query --search "$lib" | sed s/:.*//)"
src="$(grep-aptavail --no-field-names --show-field Source:Package --field Package --exact-match --pattern "$pkg" | sed 's/ .*//')"
first="$(printf '%s' "$src" | head --bytes 1)"
adequate "$pkg"
adequate "$pkg" | c++filt
man adequate | grep -A4 undefined-symbol
lddtree "$lib"
symtree "$lib"
symtree "$lib" | c++filt
objdump -T "$link" | grep -E " ($(symtree "$lib" | sed -n 's/    UNRESOLVED => //p' | tr , '|'))$"
objdump -T "$link" | grep -E " ($(symtree "$lib" | sed -n 's/    UNRESOLVED => //p' | tr , '|'))$" | c++filt
w3m -dump https://qa.debian.org/bls/packages/"$first"/"$src".html | grep -A2 symbol
w3m -dump https://qa.debian.org/bls/bytag/W-shlibs-symbol-not-found.html | grep -A12 description
chronic getbuildlog "$src" last
grep 'dpkg-shlibdeps: warning: symbol .* used by .* found in none of the libraries' ./*.log
grep 'dpkg-shlibdeps: warning: symbol .* used by .* found in none of the libraries' ./*.log | c++filt
set +v
body="

User: debian-qa@lists.debian.org
Usertags: undefined-symbol adequate

$lib needs to link with -l$link, see the output of
adequate, symtree and objdump below. I detected this on amd64 but the
Debian build log scanner also detected dpkg-buildpackage complaining
about it on most architectures, see the w3m/getbuildlog output below.

I filed this bug at severity minor since I'm not sure if there are any
programs using the $lib lib and if they already use the
$link symbols and link with the -l$link flag or not.

This bug report brought to you by adequate:

https://bonedaddy.net/pabs3/log/2013/02/23/inadequate-software/
"
reportbug --body="$body" "$lib"
