Various fixes for build failures

A bunch of bugfixes to prevent build failures with newer toolchain as seen on latest Debian/Ubuntu. Two of them are actual backports from qemu git.