Fixes build with glibc-2.22.
Also fixes hard-to-trigger deadlock in highly threaded case, and fix
libraries dependencies.
Misc minor improvements in test programs as well.
Fixes #8446.
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: gamadril.dev@gmail.com
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>