Sort objects before relocations

(cherry picked from commit 6ee65ed6ddbf04402fad0bec6aa9c73b9d982ae4)
Fix locking in fmtmsg

(cherry picked from commit 7724defcf8873116fe4efab256596861eef21a94)