Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -1550,6 +1550,9 @@ Out::ElfHeader = make("", 0, SHF_ALLOC); Out::ElfHeader->Size = sizeof(typename ELFT::Ehdr); + // Create wrapped symbols for -wrap option. + std::vector Wrapped = addWrappedSymbols(Args); + // We need to create some reserved symbols such as _end. Create them. if (!Config->Relocatable) addReservedSymbols(); @@ -1562,9 +1565,6 @@ if (!Config->Relocatable) Symtab->scanVersionScript(); - // Create wrapped symbols for -wrap option. - std::vector Wrapped = addWrappedSymbols(Args); - // Do link-time optimization if given files are LLVM bitcode files. // This compiles bitcode files into real object files. // Index: test/ELF/Inputs/pr40134.s =================================================================== --- test/ELF/Inputs/pr40134.s +++ test/ELF/Inputs/pr40134.s @@ -0,0 +1,5 @@ +.global __executable_start +.global __wrap_get_executable_start + +__wrap_get_executable_start: + movabs $__executable_start,%rdx Index: test/ELF/pr40134.s =================================================================== --- test/ELF/pr40134.s +++ test/ELF/pr40134.s @@ -0,0 +1,11 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/pr40134.s -o %t2 +// RUN: llvm-ar rcs %t3 %t2 +// RUN: ld.lld -o %t4 %t %t3 -wrap get_executable_start + +.global get_executable_start +.global _start + +_start: + jmp get_executable_start