[llvm-branch-commits] [llvm] [llvm-objcopy] Stream ELF output to reduce peak memory usage (PR #217706)

James Henderson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Oct 13 02:08:32 PDT 2026


================
@@ -63,10 +144,9 @@ void SectionBase::replaceSectionReferences(
     const DenseMap<SectionBase *, SectionBase *> &) {}
 void SectionBase::onRemove() {}
 
-template <class ELFT> void ELFWriter<ELFT>::writeShdr(const SectionBase &Sec) {
-  uint8_t *B =
-      reinterpret_cast<uint8_t *>(Buf->getBufferStart()) + Sec.HeaderOffset;
-  Elf_Shdr &Shdr = *reinterpret_cast<Elf_Shdr *>(B);
+template <class ELFT>
+void ELFWriter<ELFT>::writeShdr(raw_ostream &Out, const SectionBase &Sec) {
+  Elf_Shdr Shdr = {};
----------------
jh7370 wrote:

There's no need for the explicit instantiation of the Elf_Shdr: the struct members are all written to below.

https://github.com/llvm/llvm-project/pull/217706


More information about the llvm-branch-commits mailing list