Backport changes from Emacs r115870