Backport of 2e898e4c0a38 for 4.4, 4.9, 4.14, and 4.16