Backported 9929e98404c1.