Lines Matching refs:Sec
67 template <class ELFT> void ELFWriter<ELFT>::writeShdr(const SectionBase &Sec) { in writeShdr() argument
69 reinterpret_cast<uint8_t *>(Buf->getBufferStart()) + Sec.HeaderOffset; in writeShdr()
71 Shdr.sh_name = Sec.NameIndex; in writeShdr()
72 Shdr.sh_type = Sec.Type; in writeShdr()
73 Shdr.sh_flags = Sec.Flags; in writeShdr()
74 Shdr.sh_addr = Sec.Addr; in writeShdr()
75 Shdr.sh_offset = Sec.Offset; in writeShdr()
76 Shdr.sh_size = Sec.Size; in writeShdr()
77 Shdr.sh_link = Sec.Link; in writeShdr()
78 Shdr.sh_info = Sec.Info; in writeShdr()
79 Shdr.sh_addralign = Sec.Align; in writeShdr()
80 Shdr.sh_entsize = Sec.EntrySize; in writeShdr()
101 Error ELFSectionSizer<ELFT>::visit(SymbolTableSection &Sec) { in visit() argument
102 Sec.EntrySize = sizeof(Elf_Sym); in visit()
103 Sec.Size = Sec.Symbols.size() * Sec.EntrySize; in visit()
105 Sec.Align = ELFT::Is64Bits ? sizeof(Elf_Xword) : sizeof(Elf_Word); in visit()
110 Error ELFSectionSizer<ELFT>::visit(RelocationSection &Sec) { in visit() argument
111 Sec.EntrySize = Sec.Type == SHT_REL ? sizeof(Elf_Rel) : sizeof(Elf_Rela); in visit()
112 Sec.Size = Sec.Relocations.size() * Sec.EntrySize; in visit()
114 Sec.Align = ELFT::Is64Bits ? sizeof(Elf_Xword) : sizeof(Elf_Word); in visit()
123 template <class ELFT> Error ELFSectionSizer<ELFT>::visit(GroupSection &Sec) { in visit() argument
124 Sec.Size = sizeof(Elf_Word) + Sec.GroupMembers.size() * sizeof(Elf_Word); in visit()
142 Error BinarySectionWriter::visit(const SectionIndexSection &Sec) { in visit() argument
145 Sec.Name + "' "); in visit()
148 Error BinarySectionWriter::visit(const SymbolTableSection &Sec) { in visit() argument
150 "cannot write symbol table '" + Sec.Name + in visit()
154 Error BinarySectionWriter::visit(const RelocationSection &Sec) { in visit() argument
156 "cannot write relocation section '" + Sec.Name + in visit()
160 Error BinarySectionWriter::visit(const GnuDebugLinkSection &Sec) { in visit() argument
162 "cannot write '" + Sec.Name + "' out to binary"); in visit()
165 Error BinarySectionWriter::visit(const GroupSection &Sec) { in visit() argument
167 "cannot write '" + Sec.Name + "' out to binary"); in visit()
170 Error SectionWriter::visit(const Section &Sec) { in visit() argument
171 if (Sec.Type != SHT_NOBITS) in visit()
172 llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset); in visit()
327 static uint64_t sectionPhysicalAddr(const SectionBase *Sec) { in sectionPhysicalAddr() argument
328 Segment *Seg = Sec->ParentSegment; in sectionPhysicalAddr()
331 return Seg ? Seg->PAddr + Sec->OriginalOffset - Seg->OriginalOffset in sectionPhysicalAddr()
332 : Sec->Addr; in sectionPhysicalAddr()
335 void IHexSectionWriterBase::writeSection(const SectionBase *Sec, in writeSection() argument
337 assert(Data.size() == Sec->Size); in writeSection()
339 uint32_t Addr = sectionPhysicalAddr(Sec) & 0xFFFFFFFFU; in writeSection()
384 Error IHexSectionWriterBase::visit(const Section &Sec) { in visit() argument
385 writeSection(&Sec, Sec.Contents); in visit()
389 Error IHexSectionWriterBase::visit(const OwnedDataSection &Sec) { in visit() argument
390 writeSection(&Sec, Sec.Data); in visit()
394 Error IHexSectionWriterBase::visit(const StringTableSection &Sec) { in visit() argument
396 assert(Sec.Size == Sec.StrTabBuilder.getSize()); in visit()
400 writeSection(&Sec, {nullptr, static_cast<size_t>(Sec.Size)}); in visit()
404 Error IHexSectionWriterBase::visit(const DynamicRelocationSection &Sec) { in visit() argument
405 writeSection(&Sec, Sec.Contents); in visit()
416 Error IHexSectionWriter::visit(const StringTableSection &Sec) { in visit() argument
417 assert(Sec.Size == Sec.StrTabBuilder.getSize()); in visit()
418 std::vector<uint8_t> Data(Sec.Size); in visit()
419 Sec.StrTabBuilder.write(Data.data()); in visit()
420 writeSection(&Sec, Data); in visit()
432 Error SectionWriter::visit(const OwnedDataSection &Sec) { in visit() argument
433 llvm::copy(Sec.Data, Out.getBufferStart() + Sec.Offset); in visit()
438 Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) { in visit() argument
440 Sec.OriginalData.slice(sizeof(Elf_Chdr_Impl<ELFT>)); in visit()
443 static_cast<size_t>(Sec.Size))) in visit()
445 "'" + Sec.Name + "': " + toString(std::move(Err))); in visit()
447 uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
453 Error BinarySectionWriter::visit(const DecompressedSection &Sec) { in visit() argument
455 "cannot write compressed section '" + Sec.Name + in visit()
484 Error BinarySectionWriter::visit(const CompressedSection &Sec) { in visit() argument
486 "cannot write compressed section '" + Sec.Name + in visit()
491 Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) { in visit() argument
492 uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
494 switch (Sec.CompressionType) { in visit()
496 std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), Buf); in visit()
502 Chdr.ch_size = Sec.DecompressedSize; in visit()
503 Chdr.ch_addralign = Sec.DecompressedAlign; in visit()
507 std::copy(Sec.CompressedData.begin(), Sec.CompressedData.end(), Buf); in visit()
511 CompressedSection::CompressedSection(const SectionBase &Sec, in CompressedSection() argument
513 : SectionBase(Sec), CompressionType(CompressionType), in CompressedSection()
514 DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) { in CompressedSection()
555 Error SectionWriter::visit(const StringTableSection &Sec) { in visit() argument
556 Sec.StrTabBuilder.write(reinterpret_cast<uint8_t *>(Out.getBufferStart()) + in visit()
557 Sec.Offset); in visit()
570 Error ELFSectionWriter<ELFT>::visit(const SectionIndexSection &Sec) { in visit() argument
571 uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
572 llvm::copy(Sec.Indexes, reinterpret_cast<Elf_Word *>(Buf)); in visit()
578 Expected<SymbolTableSection *> Sec = in initialize() local
585 if (!Sec) in initialize()
586 return Sec.takeError(); in initialize()
588 setSymTab(*Sec); in initialize()
737 Expected<StringTableSection *> Sec = in initialize() local
744 if (!Sec) in initialize()
745 return Sec.takeError(); in initialize()
747 setStrTab(*Sec); in initialize()
811 Error ELFSectionWriter<ELFT>::visit(const SymbolTableSection &Sec) { in visit() argument
812 Elf_Sym *Sym = reinterpret_cast<Elf_Sym *>(Out.getBufferStart() + Sec.Offset); in visit()
814 for (const std::unique_ptr<Symbol> &Symbol : Sec.Symbols) { in visit()
877 Expected<SymTabType *> Sec = SecTable.getSectionOfType<SymTabType>( in initialize() local
883 if (!Sec) in initialize()
884 return Sec.takeError(); in initialize()
886 setSymTab(*Sec); in initialize()
890 Expected<SectionBase *> Sec = in initialize() local
893 if (!Sec) in initialize()
894 return Sec.takeError(); in initialize()
896 setSection(*Sec); in initialize()
931 Error ELFSectionWriter<ELFT>::visit(const RelocationSection &Sec) { in visit() argument
932 uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
933 if (Sec.Type == SHT_REL) in visit()
934 writeRel(Sec.Relocations, reinterpret_cast<Elf_Rel *>(Buf), in visit()
935 Sec.getObject().IsMips64EL); in visit()
937 writeRel(Sec.Relocations, reinterpret_cast<Elf_Rela *>(Buf), in visit()
938 Sec.getObject().IsMips64EL); in visit()
974 Error SectionWriter::visit(const DynamicRelocationSection &Sec) { in visit() argument
975 llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset); in visit()
1064 for (SectionBase *&Sec : GroupMembers) in replaceSectionReferences()
1065 if (SectionBase *To = FromTo.lookup(Sec)) in replaceSectionReferences()
1066 Sec = To; in replaceSectionReferences()
1072 for (SectionBase *Sec : GroupMembers) in onRemove()
1073 Sec->Flags &= ~SHF_GROUP; in onRemove()
1080 Expected<SectionBase *> Sec = in initialize() local
1083 if (!Sec) in initialize()
1084 return Sec.takeError(); in initialize()
1086 LinkSection = *Sec; in initialize()
1120 Error ELFSectionWriter<ELFT>::visit(const GnuDebugLinkSection &Sec) { in visit() argument
1122 reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
1124 reinterpret_cast<Elf_Word *>(Buf + Sec.Size - sizeof(Elf_Word)); in visit()
1125 *CRC = Sec.CRC32; in visit()
1126 llvm::copy(Sec.FileName, Buf); in visit()
1139 Error ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) { in visit() argument
1141 reinterpret_cast<ELF::Elf32_Word *>(Out.getBufferStart() + Sec.Offset); in visit()
1142 support::endian::write32<ELFT::TargetEndianness>(Buf++, Sec.FlagWord); in visit()
1143 for (SectionBase *S : Sec.GroupMembers) in visit()
1157 static bool sectionWithinSegment(const SectionBase &Sec, const Segment &Seg) { in sectionWithinSegment() argument
1162 uint64_t SecSize = Sec.Size ? Sec.Size : 1; in sectionWithinSegment()
1165 if (Sec.OriginalOffset == std::numeric_limits<uint64_t>::max()) in sectionWithinSegment()
1168 if (Sec.Type == SHT_NOBITS) { in sectionWithinSegment()
1169 if (!(Sec.Flags & SHF_ALLOC)) in sectionWithinSegment()
1172 bool SectionIsTLS = Sec.Flags & SHF_TLS; in sectionWithinSegment()
1177 return Seg.VAddr <= Sec.Addr && in sectionWithinSegment()
1178 Seg.VAddr + Seg.MemSize >= Sec.Addr + SecSize; in sectionWithinSegment()
1181 return Seg.Offset <= Sec.OriginalOffset && in sectionWithinSegment()
1182 Seg.Offset + Seg.FileSize >= Sec.OriginalOffset + SecSize; in sectionWithinSegment()
1238 for (SectionBase &Sec : Obj->sections()) in initSections()
1239 if (Error Err = Sec.initialize(Obj->sections())) in initSections()
1370 for (const SectionBase &Sec : Obj.sections()) { in findEhdrOffset() local
1371 if (Sec.Type == SHT_LLVM_PART_EHDR && Sec.Name == *ExtractPartition) { in findEhdrOffset()
1372 EhdrOffset = Sec.Offset; in findEhdrOffset()
1411 for (SectionBase &Sec : Obj.sections()) in readProgramHeaders()
1412 if (sectionWithinSegment(Sec, Seg)) { in readProgramHeaders()
1413 Seg.addSection(&Sec); in readProgramHeaders()
1414 if (!Sec.ParentSegment || Sec.ParentSegment->Offset > Seg.Offset) in readProgramHeaders()
1415 Sec.ParentSegment = &Seg; in readProgramHeaders()
1487 Expected<SectionBase *> Sec = SecTable.getSection( in initGroupSection() local
1490 if (!Sec) in initGroupSection()
1491 return Sec.takeError(); in initGroupSection()
1493 GroupSec->addMember(*Sec); in initGroupSection()
1548 Expected<SectionBase *> Sec = Obj.sections().getSection( in initSymbolTable() local
1551 if (!Sec) in initSymbolTable()
1552 return Sec.takeError(); in initSymbolTable()
1554 DefSection = *Sec; in initSymbolTable()
1565 Expected<SectionBase *> Sec = Obj.sections().getSection( in initSymbolTable() local
1569 if (!Sec) in initSymbolTable()
1570 return Sec.takeError(); in initSymbolTable()
1572 DefSection = *Sec; in initSymbolTable()
1633 if (T *Sec = dyn_cast<T>(*BaseSec)) in getSectionOfType() local
1634 return Sec; in getSectionOfType()
1727 Expected<SectionBase &> Sec = makeSection(Shdr); in readSectionHeaders() local
1728 if (!Sec) in readSectionHeaders()
1729 return Sec.takeError(); in readSectionHeaders()
1734 Sec->Name = SecName->str(); in readSectionHeaders()
1735 Sec->Type = Sec->OriginalType = Shdr.sh_type; in readSectionHeaders()
1736 Sec->Flags = Sec->OriginalFlags = Shdr.sh_flags; in readSectionHeaders()
1737 Sec->Addr = Shdr.sh_addr; in readSectionHeaders()
1738 Sec->Offset = Shdr.sh_offset; in readSectionHeaders()
1739 Sec->OriginalOffset = Shdr.sh_offset; in readSectionHeaders()
1740 Sec->Size = Shdr.sh_size; in readSectionHeaders()
1741 Sec->Link = Shdr.sh_link; in readSectionHeaders()
1742 Sec->Info = Shdr.sh_info; in readSectionHeaders()
1743 Sec->Align = Shdr.sh_addralign; in readSectionHeaders()
1744 Sec->EntrySize = Shdr.sh_entsize; in readSectionHeaders()
1745 Sec->Index = Index++; in readSectionHeaders()
1746 Sec->OriginalIndex = Sec->Index; in readSectionHeaders()
1747 Sec->OriginalData = ArrayRef<uint8_t>( in readSectionHeaders()
1758 Expected<const Elf_Shdr *> Sec = ElfFile.getSection(0); in readSections() local
1759 if (!Sec) in readSections()
1760 return Sec.takeError(); in readSections()
1762 ShstrIndex = (*Sec)->sh_link; in readSections()
1768 Expected<StringTableSection *> Sec = in readSections() local
1775 if (!Sec) in readSections()
1776 return Sec.takeError(); in readSections()
1778 Obj.SectionNames = *Sec; in readSections()
1804 for (SectionBase &Sec : Obj.sections()) { in readSections()
1805 if (&Sec == Obj.SymbolTable) in readSections()
1807 if (Error Err = Sec.initialize(Obj.sections())) in readSections()
1809 if (auto RelSec = dyn_cast<RelocationSection>(&Sec)) { in readSections()
1834 } else if (auto GroupSec = dyn_cast<GroupSection>(&Sec)) { in readSections()
2028 for (SectionBase &Sec : Obj.sections()) in writeShdrs()
2029 writeShdr(Sec); in writeShdrs()
2033 for (SectionBase &Sec : Obj.sections()) in writeSectionData()
2037 if (Sec.ParentSegment == nullptr) in writeSectionData()
2038 if (Error Err = Sec.accept(*SecWriter)) in writeSectionData()
2052 SectionBase *Sec = it.first; in writeSegmentData() local
2055 auto *Parent = Sec->ParentSegment; in writeSegmentData()
2058 Sec->OriginalOffset - Parent->OriginalOffset + Parent->Offset; in writeSegmentData()
2063 for (auto &Sec : Obj.removedSections()) { in writeSegmentData() local
2064 Segment *Parent = Sec.ParentSegment; in writeSegmentData()
2065 if (Parent == nullptr || Sec.Type == SHT_NOBITS || Sec.Size == 0) in writeSegmentData()
2068 Sec.OriginalOffset - Parent->OriginalOffset + Parent->Offset; in writeSegmentData()
2069 std::memset(Buf->getBufferStart() + Offset, 0, Sec.Size); in writeSegmentData()
2081 [&](const SecPtr &Sec) { return Sec->Name == Name; }); in updateSection() argument
2114 std::begin(Sections), std::end(Sections), [=](const SecPtr &Sec) { in removeSections() argument
2115 if (ToRemove(*Sec)) in removeSections()
2117 if (auto RelSec = dyn_cast<RelocationSectionBase>(Sec.get())) { in removeSections()
2148 AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) { in removeSections() argument
2149 return RemoveSections.find(Sec) != RemoveSections.end(); in removeSections()
2175 for (auto &Sec : Sections) in replaceSections() local
2176 Sec->replaceSectionReferences(FromTo); in replaceSections()
2180 [=](const SectionBase &Sec) { return FromTo.count(&Sec) > 0; })) in replaceSections() argument
2188 for (const SecPtr &Sec : Sections) in removeSymbols() local
2189 if (Error E = Sec->removeSymbols(ToRemove)) in removeSymbols()
2199 for (SectionBase &Sec : sections()) { in addNewSymbolTable()
2200 if (Sec.Type == ELF::SHT_STRTAB && !(Sec.Flags & SHF_ALLOC)) { in addNewSymbolTable()
2201 StrTab = static_cast<StringTableSection *>(&Sec); in addNewSymbolTable()
2205 if (SectionNames != &Sec) in addNewSymbolTable()
2276 for (auto &Sec : Sections) { in layoutSections() local
2277 Sec.Index = Index++; in layoutSections()
2278 if (Sec.ParentSegment != nullptr) { in layoutSections()
2279 auto Segment = *Sec.ParentSegment; in layoutSections()
2280 Sec.Offset = in layoutSections()
2281 Segment.Offset + (Sec.OriginalOffset - Segment.OriginalOffset); in layoutSections()
2283 OutOfSegmentSections.push_back(&Sec); in layoutSections()
2290 for (auto *Sec : OutOfSegmentSections) { in layoutSections() local
2291 Offset = alignTo(Offset, Sec->Align == 0 ? 1 : Sec->Align); in layoutSections()
2292 Sec->Offset = Offset; in layoutSections()
2293 if (Sec->Type != SHT_NOBITS) in layoutSections()
2294 Offset += Sec->Size; in layoutSections()
2307 for (auto &Sec : Obj.sections()) { in layoutSectionsForOnlyKeepDebug() local
2308 Sec.Index = Index++; in layoutSectionsForOnlyKeepDebug()
2309 Sections.push_back(&Sec); in layoutSectionsForOnlyKeepDebug()
2316 for (auto *Sec : Sections) { in layoutSectionsForOnlyKeepDebug() local
2317 auto *FirstSec = Sec->ParentSegment && Sec->ParentSegment->Type == PT_LOAD in layoutSectionsForOnlyKeepDebug()
2318 ? Sec->ParentSegment->firstSection() in layoutSectionsForOnlyKeepDebug()
2323 if (FirstSec && FirstSec == Sec) in layoutSectionsForOnlyKeepDebug()
2324 Off = alignTo(Off, Sec->ParentSegment->Align, Sec->Addr); in layoutSectionsForOnlyKeepDebug()
2329 if (Sec->Type == SHT_NOBITS) { in layoutSectionsForOnlyKeepDebug()
2330 Sec->Offset = Off; in layoutSectionsForOnlyKeepDebug()
2337 Off = Sec->Align ? alignTo(Off, Sec->Align) : Off; in layoutSectionsForOnlyKeepDebug()
2338 } else if (FirstSec != Sec) { in layoutSectionsForOnlyKeepDebug()
2341 Off = Sec->OriginalOffset - FirstSec->OriginalOffset + FirstSec->Offset; in layoutSectionsForOnlyKeepDebug()
2343 Sec->Offset = Off; in layoutSectionsForOnlyKeepDebug()
2344 Off += Sec->Size; in layoutSectionsForOnlyKeepDebug()
2369 for (const SectionBase *Sec : Seg->Sections) { in layoutSegmentsForOnlyKeepDebug() local
2370 uint64_t Size = Sec->Type == SHT_NOBITS ? 0 : Sec->Size; in layoutSegmentsForOnlyKeepDebug()
2371 if (Sec->Offset + Size > Offset) in layoutSegmentsForOnlyKeepDebug()
2372 FileSize = std::max(FileSize, Sec->Offset + Size - Offset); in layoutSegmentsForOnlyKeepDebug()
2475 return Obj.removeSections(false, [&](const SectionBase &Sec) { in removeUnneededSections() argument
2476 return &Sec == Obj.SymbolTable || &Sec == StrTab; in removeUnneededSections()
2502 [](const SectionBase &Sec) { return Sec.HasSymbol; }); in finalize() argument
2523 [this](const SectionBase &Sec) { in finalize() argument
2524 return &Sec == Obj.SectionIndexTable; in finalize()
2533 for (const SectionBase &Sec : Obj.sections()) in finalize() local
2534 Obj.SectionNames->addString(Sec.Name); in finalize()
2543 for (SectionBase &Sec : Obj.sections()) { in finalize()
2544 Sec.Index = Index++; in finalize()
2545 if (Error Err = Sec.accept(*SecSizer)) in finalize()
2557 for (SectionBase &Sec : Obj.sections()) in finalize()
2558 if (auto StrTab = dyn_cast<StringTableSection>(&Sec)) in finalize()
2571 for (SectionBase &Sec : Obj.sections()) { in finalize()
2572 Sec.HeaderOffset = Offset; in finalize()
2575 Sec.NameIndex = Obj.SectionNames->findIndex(Sec.Name); in finalize()
2576 Sec.finalize(); in finalize()
2591 for (const SectionBase &Sec : Obj.allocSections()) in write() local
2592 if (Error Err = Sec.accept(*SecWriter)) in write()
2607 for (SectionBase &Sec : Obj.allocSections()) { in finalize()
2610 if (Sec.ParentSegment != nullptr) in finalize()
2611 Sec.Addr = alignTo(Sec.Offset - Sec.ParentSegment->Offset + in finalize()
2612 Sec.ParentSegment->PAddr, in finalize()
2613 std::max(Sec.Align, uint64_t(1))); in finalize()
2614 if (Sec.Type != SHT_NOBITS && Sec.Size > 0) in finalize()
2615 MinAddr = std::min(MinAddr, Sec.Addr); in finalize()
2623 for (SectionBase &Sec : Obj.allocSections()) in finalize()
2624 if (Sec.Type != SHT_NOBITS && Sec.Size > 0) { in finalize()
2625 Sec.Offset = Sec.Addr - MinAddr; in finalize()
2626 TotalSize = std::max(TotalSize, Sec.Offset + Sec.Size); in finalize()
2674 for (const SectionBase *Sec : Sections) in write() local
2675 if (Error Err = Sec->accept(Writer)) in write()
2693 Error IHexWriter::checkSection(const SectionBase &Sec) { in checkSection() argument
2694 uint64_t Addr = sectionPhysicalAddr(&Sec); in checkSection()
2695 if (addressOverflows32bit(Addr) || addressOverflows32bit(Addr + Sec.Size - 1)) in checkSection()
2699 Sec.Name.c_str(), Addr, Addr + Sec.Size - 1); in checkSection()
2710 for (const SectionBase &Sec : Obj.sections()) in finalize() local
2711 if ((Sec.Flags & ELF::SHF_ALLOC) && Sec.Type != ELF::SHT_NOBITS && in finalize()
2712 Sec.Size > 0) { in finalize()
2713 if (Error E = checkSection(Sec)) in finalize()
2715 Sections.insert(&Sec); in finalize()
2725 for (const SectionBase *Sec : Sections) in finalize() local
2726 if (Error Err = Sec->accept(LengthCalc)) in finalize()