llvm.org GIT mirror llvm / fdd2cc8
[llvm][llvm-objcopy] When outputting to binary don't output segments that cover no sections Sometimes LLD will produce a PT_LOAD segment that only covers the headers (and covers no sections). GNU objcopy does not output the segment contents for these sections. In particular this is an issue in building magenta because the final link step for the kernel would produce just such a PT_LOAD segment. This change is to support this case and to match what GNU objcopy does in this case. Patch by Jake Ehrlich Differential Revision: https://reviews.llvm.org/D36196 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310149 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 2 years ago
3 changed file(s) with 10 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 # RUN: llvm-objcopy -O binary %p/Inputs/pt-phdr.elf %t
1 # RUN: wc -c < %t | FileCheck %s
2
3 # CHECK: 4110
353353 template
354354 void BinaryObject::write(FileOutputBuffer &Out) const {
355355 for (auto &Segment : this->Segments) {
356 if (Segment->Type == llvm::ELF::PT_LOAD) {
356 // GNU objcopy does not output segments that do not cover a section. Such
357 // segments can sometimes be produced by LLD due to how LLD handles PT_PHDR.
358 if (Segment->Type == llvm::ELF::PT_LOAD &&
359 Segment->firstSection() != nullptr) {
357360 Segment->writeSegment(Out);
358361 }
359362 }
372375
373376 uint64_t Offset = 0;
374377 for (auto &Segment : this->Segments) {
375 if (Segment->Type == llvm::ELF::PT_LOAD) {
378 if (Segment->Type == llvm::ELF::PT_LOAD &&
379 Segment->firstSection() != nullptr) {
376380 Offset = alignTo(Offset, Segment->Align);
377381 Segment->Offset = Offset;
378382 Offset += Segment->FileSize;