diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 14d2bc76e11f..a1d97e791988 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -591,10 +591,7 @@ template void Writer::writeHeader() { EHdr->e_shentsize = sizeof(Elf_Shdr); EHdr->e_shnum = getNumSections(); EHdr->e_shstrndx = Out::StrTab->getSectionIndex(); - - auto PHdrs = reinterpret_cast(Buf + EHdr->e_phoff); - for (Elf_Phdr &PH : Phdrs) - *PHdrs++ = PH; + memcpy(Buf + EHdr->e_phoff, &Phdrs[0], Phdrs.size() * sizeof(Phdrs[0])); auto SHdrs = reinterpret_cast(Buf + EHdr->e_shoff); // First entry is null.