diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index f9ae35f87c21..3c68686e50d0 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2452,6 +2452,9 @@ void LinkerDriver::link(opt::InputArgList &args) { for (auto *s : lto::LTO::getRuntimeLibcallSymbols()) handleLibcall(s); + // Archive members defining __wrap symbols may be extracted. + std::vector wrapped = addWrappedSymbols(args); + // No more lazy bitcode can be extracted at this point. Do post parse work // like checking duplicate symbols. parallelForEach(objectFiles, postParseObjectFile); @@ -2478,8 +2481,6 @@ void LinkerDriver::link(opt::InputArgList &args) { // addReservedSymbols to mark the created symbols as not absolute. Out::elfHeader = make("", 0, SHF_ALLOC); - std::vector wrapped = addWrappedSymbols(args); - // We need to create some reserved symbols such as _end. Create them. if (!config->relocatable) addReservedSymbols(); diff --git a/lld/test/ELF/wrap-extract.s b/lld/test/ELF/wrap-extract.s new file mode 100644 index 000000000000..708b9c8c2f01 --- /dev/null +++ b/lld/test/ELF/wrap-extract.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 +## --wrap may trigger archive extraction. Test that local symbols are initialized. + +# RUN: rm -rf %t && split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o +# RUN: ld.lld %t/a.o --start-lib %t/b.o --end-lib -o %t/a --wrap pthread_create -o /dev/null + +#--- a.s +.globl _start +_start: +.cfi_startproc + call pthread_create +.cfi_endproc + +#--- b.s +.global __wrap_pthread_create +__wrap_pthread_create: +.cfi_startproc + ret +.cfi_endproc