Replaces commit 45141320 to address the problem in a better way.

See https://bugs.gentoo.org/show_bug.cgi?id=509592 for details.