peter.smith added a comment. The algorithm looks good to me. For ELF I preferred to give the Thunk a name related to the destination as it makes it a bit easier to follow disassembled binaries, but it is not essential. https://reviews.llvm.org/D51089