backport of 5495f98