Index: tools/llvm-objcopy/Object.cpp =================================================================== --- tools/llvm-objcopy/Object.cpp +++ tools/llvm-objcopy/Object.cpp @@ -353,7 +353,9 @@ template void BinaryObject::write(FileOutputBuffer &Out) const { for (auto &Segment : this->Segments) { - if (Segment->Type == llvm::ELF::PT_LOAD) { + // GNU objcopy does not output segments that do not cover a section. Such + // segments can sometimes be produced by LLD due to how LLD handles PT_PHDR. + if (Segment->Type == llvm::ELF::PT_LOAD && Segment->firstSection()) { Segment->writeSegment(Out); } } @@ -372,7 +374,7 @@ uint64_t Offset = 0; for (auto &Segment : this->Segments) { - if (Segment->Type == llvm::ELF::PT_LOAD) { + if (Segment->Type == llvm::ELF::PT_LOAD && Segment->firstSection()) { Offset = alignTo(Offset, Segment->Align); Segment->Offset = Offset; Offset += Segment->FileSize;