Lines Matching refs:Sec
69 template <class ELFT> void ELFWriter<ELFT>::writeShdr(const SectionBase &Sec) { in writeShdr() argument
70 uint8_t *B = Buf.getBufferStart() + Sec.HeaderOffset; in writeShdr()
72 Shdr.sh_name = Sec.NameIndex; in writeShdr()
73 Shdr.sh_type = Sec.Type; in writeShdr()
74 Shdr.sh_flags = Sec.Flags; in writeShdr()
75 Shdr.sh_addr = Sec.Addr; in writeShdr()
76 Shdr.sh_offset = Sec.Offset; in writeShdr()
77 Shdr.sh_size = Sec.Size; in writeShdr()
78 Shdr.sh_link = Sec.Link; in writeShdr()
79 Shdr.sh_info = Sec.Info; in writeShdr()
80 Shdr.sh_addralign = Sec.Align; in writeShdr()
81 Shdr.sh_entsize = Sec.EntrySize; in writeShdr()
102 Error ELFSectionSizer<ELFT>::visit(SymbolTableSection &Sec) { in visit() argument
103 Sec.EntrySize = sizeof(Elf_Sym); in visit()
104 Sec.Size = Sec.Symbols.size() * Sec.EntrySize; in visit()
106 Sec.Align = ELFT::Is64Bits ? sizeof(Elf_Xword) : sizeof(Elf_Word); in visit()
111 Error ELFSectionSizer<ELFT>::visit(RelocationSection &Sec) { in visit() argument
112 Sec.EntrySize = Sec.Type == SHT_REL ? sizeof(Elf_Rel) : sizeof(Elf_Rela); in visit()
113 Sec.Size = Sec.Relocations.size() * Sec.EntrySize; in visit()
115 Sec.Align = ELFT::Is64Bits ? sizeof(Elf_Xword) : sizeof(Elf_Word); in visit()
124 template <class ELFT> Error ELFSectionSizer<ELFT>::visit(GroupSection &Sec) { in visit() argument
125 Sec.Size = sizeof(Elf_Word) + Sec.GroupMembers.size() * sizeof(Elf_Word); in visit()
143 Error BinarySectionWriter::visit(const SectionIndexSection &Sec) { in visit() argument
146 Sec.Name + "' "); in visit()
149 Error BinarySectionWriter::visit(const SymbolTableSection &Sec) { in visit() argument
151 "cannot write symbol table '" + Sec.Name + in visit()
155 Error BinarySectionWriter::visit(const RelocationSection &Sec) { in visit() argument
157 "cannot write relocation section '" + Sec.Name + in visit()
161 Error BinarySectionWriter::visit(const GnuDebugLinkSection &Sec) { in visit() argument
163 "cannot write '" + Sec.Name + "' out to binary"); in visit()
166 Error BinarySectionWriter::visit(const GroupSection &Sec) { in visit() argument
168 "cannot write '" + Sec.Name + "' out to binary"); in visit()
171 Error SectionWriter::visit(const Section &Sec) { in visit() argument
172 if (Sec.Type != SHT_NOBITS) in visit()
173 llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset); in visit()
328 static uint64_t sectionPhysicalAddr(const SectionBase *Sec) { in sectionPhysicalAddr() argument
329 Segment *Seg = Sec->ParentSegment; in sectionPhysicalAddr()
332 return Seg ? Seg->PAddr + Sec->OriginalOffset - Seg->OriginalOffset in sectionPhysicalAddr()
333 : Sec->Addr; in sectionPhysicalAddr()
336 void IHexSectionWriterBase::writeSection(const SectionBase *Sec, in writeSection() argument
338 assert(Data.size() == Sec->Size); in writeSection()
340 uint32_t Addr = sectionPhysicalAddr(Sec) & 0xFFFFFFFFU; in writeSection()
385 Error IHexSectionWriterBase::visit(const Section &Sec) { in visit() argument
386 writeSection(&Sec, Sec.Contents); in visit()
390 Error IHexSectionWriterBase::visit(const OwnedDataSection &Sec) { in visit() argument
391 writeSection(&Sec, Sec.Data); in visit()
395 Error IHexSectionWriterBase::visit(const StringTableSection &Sec) { in visit() argument
397 assert(Sec.Size == Sec.StrTabBuilder.getSize()); in visit()
401 writeSection(&Sec, {nullptr, static_cast<size_t>(Sec.Size)}); in visit()
405 Error IHexSectionWriterBase::visit(const DynamicRelocationSection &Sec) { in visit() argument
406 writeSection(&Sec, Sec.Contents); in visit()
417 Error IHexSectionWriter::visit(const StringTableSection &Sec) { in visit() argument
418 assert(Sec.Size == Sec.StrTabBuilder.getSize()); in visit()
419 std::vector<uint8_t> Data(Sec.Size); in visit()
420 Sec.StrTabBuilder.write(Data.data()); in visit()
421 writeSection(&Sec, Data); in visit()
433 Error SectionWriter::visit(const OwnedDataSection &Sec) { in visit() argument
434 llvm::copy(Sec.Data, Out.getBufferStart() + Sec.Offset); in visit()
462 Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) { in visit() argument
463 const size_t DataOffset = isDataGnuCompressed(Sec.OriginalData) in visit()
464 ? (ZlibGnuMagic.size() + sizeof(Sec.Size)) in visit()
468 reinterpret_cast<const char *>(Sec.OriginalData.data()) + DataOffset, in visit()
469 Sec.OriginalData.size() - DataOffset); in visit()
473 static_cast<size_t>(Sec.Size))) in visit()
475 "'" + Sec.Name + "': " + toString(std::move(Err))); in visit()
477 uint8_t *Buf = Out.getBufferStart() + Sec.Offset; in visit()
483 Error BinarySectionWriter::visit(const DecompressedSection &Sec) { in visit() argument
485 "cannot write compressed section '" + Sec.Name + in visit()
514 Error BinarySectionWriter::visit(const CompressedSection &Sec) { in visit() argument
516 "cannot write compressed section '" + Sec.Name + in visit()
521 Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) { in visit() argument
522 uint8_t *Buf = Out.getBufferStart() + Sec.Offset; in visit()
523 if (Sec.CompressionType == DebugCompressionType::None) { in visit()
524 std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), Buf); in visit()
528 if (Sec.CompressionType == DebugCompressionType::GNU) { in visit()
533 support::endian::read64be(&Sec.DecompressedSize); in visit()
539 Chdr.ch_size = Sec.DecompressedSize; in visit()
540 Chdr.ch_addralign = Sec.DecompressedAlign; in visit()
545 std::copy(Sec.CompressedData.begin(), Sec.CompressedData.end(), Buf); in visit()
550 CompressedSection::create(const SectionBase &Sec, in create() argument
553 CompressedSection Section(Sec, CompressionType, Err); in create()
567 CompressedSection::CompressedSection(const SectionBase &Sec, in CompressedSection() argument
570 : SectionBase(Sec), CompressionType(CompressionType), in CompressedSection()
571 DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) { in CompressedSection()
585 Name = ".z" + Sec.Name.substr(1); in CompressedSection()
626 Error SectionWriter::visit(const StringTableSection &Sec) { in visit() argument
627 Sec.StrTabBuilder.write(Out.getBufferStart() + Sec.Offset); in visit()
640 Error ELFSectionWriter<ELFT>::visit(const SectionIndexSection &Sec) { in visit() argument
641 uint8_t *Buf = Out.getBufferStart() + Sec.Offset; in visit()
642 llvm::copy(Sec.Indexes, reinterpret_cast<Elf_Word *>(Buf)); in visit()
648 Expected<SymbolTableSection *> Sec = in initialize() local
655 if (!Sec) in initialize()
656 return Sec.takeError(); in initialize()
658 setSymTab(*Sec); in initialize()
798 Expected<StringTableSection *> Sec = in initialize() local
805 if (!Sec) in initialize()
806 return Sec.takeError(); in initialize()
808 setStrTab(*Sec); in initialize()
872 Error ELFSectionWriter<ELFT>::visit(const SymbolTableSection &Sec) { in visit() argument
873 Elf_Sym *Sym = reinterpret_cast<Elf_Sym *>(Out.getBufferStart() + Sec.Offset); in visit()
875 for (const std::unique_ptr<Symbol> &Symbol : Sec.Symbols) { in visit()
927 Expected<SymTabType *> Sec = SecTable.getSectionOfType<SymTabType>( in initialize() local
933 if (!Sec) in initialize()
934 return Sec.takeError(); in initialize()
936 setSymTab(*Sec); in initialize()
940 Expected<SectionBase *> Sec = in initialize() local
943 if (!Sec) in initialize()
944 return Sec.takeError(); in initialize()
946 setSection(*Sec); in initialize()
981 Error ELFSectionWriter<ELFT>::visit(const RelocationSection &Sec) { in visit() argument
982 uint8_t *Buf = Out.getBufferStart() + Sec.Offset; in visit()
983 if (Sec.Type == SHT_REL) in visit()
984 writeRel(Sec.Relocations, reinterpret_cast<Elf_Rel *>(Buf)); in visit()
986 writeRel(Sec.Relocations, reinterpret_cast<Elf_Rela *>(Buf)); in visit()
1022 Error SectionWriter::visit(const DynamicRelocationSection &Sec) { in visit() argument
1023 llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset); in visit()
1106 for (SectionBase *&Sec : GroupMembers) in replaceSectionReferences()
1107 if (SectionBase *To = FromTo.lookup(Sec)) in replaceSectionReferences()
1108 Sec = To; in replaceSectionReferences()
1114 for (SectionBase *Sec : GroupMembers) in onRemove()
1115 Sec->Flags &= ~SHF_GROUP; in onRemove()
1122 Expected<SectionBase *> Sec = in initialize() local
1125 if (!Sec) in initialize()
1126 return Sec.takeError(); in initialize()
1128 LinkSection = *Sec; in initialize()
1162 Error ELFSectionWriter<ELFT>::visit(const GnuDebugLinkSection &Sec) { in visit() argument
1163 unsigned char *Buf = Out.getBufferStart() + Sec.Offset; in visit()
1165 reinterpret_cast<Elf_Word *>(Buf + Sec.Size - sizeof(Elf_Word)); in visit()
1166 *CRC = Sec.CRC32; in visit()
1167 llvm::copy(Sec.FileName, Buf); in visit()
1180 Error ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) { in visit() argument
1182 reinterpret_cast<ELF::Elf32_Word *>(Out.getBufferStart() + Sec.Offset); in visit()
1183 *Buf++ = Sec.FlagWord; in visit()
1184 for (SectionBase *S : Sec.GroupMembers) in visit()
1198 static bool sectionWithinSegment(const SectionBase &Sec, const Segment &Seg) { in sectionWithinSegment() argument
1203 uint64_t SecSize = Sec.Size ? Sec.Size : 1; in sectionWithinSegment()
1205 if (Sec.Type == SHT_NOBITS) { in sectionWithinSegment()
1206 if (!(Sec.Flags & SHF_ALLOC)) in sectionWithinSegment()
1209 bool SectionIsTLS = Sec.Flags & SHF_TLS; in sectionWithinSegment()
1214 return Seg.VAddr <= Sec.Addr && in sectionWithinSegment()
1215 Seg.VAddr + Seg.MemSize >= Sec.Addr + SecSize; in sectionWithinSegment()
1218 return Seg.Offset <= Sec.OriginalOffset && in sectionWithinSegment()
1219 Seg.Offset + Seg.FileSize >= Sec.OriginalOffset + SecSize; in sectionWithinSegment()
1275 for (SectionBase &Sec : Obj->sections()) in initSections()
1276 if (Error Err = Sec.initialize(Obj->sections())) in initSections()
1395 for (const SectionBase &Sec : Obj.sections()) { in findEhdrOffset() local
1396 if (Sec.Type == SHT_LLVM_PART_EHDR && Sec.Name == *ExtractPartition) { in findEhdrOffset()
1397 EhdrOffset = Sec.Offset; in findEhdrOffset()
1436 for (SectionBase &Sec : Obj.sections()) in readProgramHeaders()
1437 if (sectionWithinSegment(Sec, Seg)) { in readProgramHeaders()
1438 Seg.addSection(&Sec); in readProgramHeaders()
1439 if (!Sec.ParentSegment || Sec.ParentSegment->Offset > Seg.Offset) in readProgramHeaders()
1440 Sec.ParentSegment = &Seg; in readProgramHeaders()
1511 Expected<SectionBase *> Sec = SecTable.getSection( in initGroupSection() local
1514 if (!Sec) in initGroupSection()
1515 return Sec.takeError(); in initGroupSection()
1517 GroupSec->addMember(*Sec); in initGroupSection()
1572 Expected<SectionBase *> Sec = Obj.sections().getSection( in initSymbolTable() local
1575 if (!Sec) in initSymbolTable()
1576 return Sec.takeError(); in initSymbolTable()
1578 DefSection = *Sec; in initSymbolTable()
1589 Expected<SectionBase *> Sec = Obj.sections().getSection( in initSymbolTable() local
1593 if (!Sec) in initSymbolTable()
1594 return Sec.takeError(); in initSymbolTable()
1596 DefSection = *Sec; in initSymbolTable()
1657 if (T *Sec = dyn_cast<T>(*BaseSec)) in getSectionOfType() local
1658 return Sec; in getSectionOfType()
1759 Expected<SectionBase &> Sec = makeSection(Shdr); in readSectionHeaders() local
1760 if (!Sec) in readSectionHeaders()
1761 return Sec.takeError(); in readSectionHeaders()
1766 Sec->Name = SecName->str(); in readSectionHeaders()
1767 Sec->Type = Sec->OriginalType = Shdr.sh_type; in readSectionHeaders()
1768 Sec->Flags = Sec->OriginalFlags = Shdr.sh_flags; in readSectionHeaders()
1769 Sec->Addr = Shdr.sh_addr; in readSectionHeaders()
1770 Sec->Offset = Shdr.sh_offset; in readSectionHeaders()
1771 Sec->OriginalOffset = Shdr.sh_offset; in readSectionHeaders()
1772 Sec->Size = Shdr.sh_size; in readSectionHeaders()
1773 Sec->Link = Shdr.sh_link; in readSectionHeaders()
1774 Sec->Info = Shdr.sh_info; in readSectionHeaders()
1775 Sec->Align = Shdr.sh_addralign; in readSectionHeaders()
1776 Sec->EntrySize = Shdr.sh_entsize; in readSectionHeaders()
1777 Sec->Index = Index++; in readSectionHeaders()
1778 Sec->OriginalIndex = Sec->Index; in readSectionHeaders()
1779 Sec->OriginalData = in readSectionHeaders()
1790 Expected<const Elf_Shdr *> Sec = ElfFile.getSection(0); in readSections() local
1791 if (!Sec) in readSections()
1792 return Sec.takeError(); in readSections()
1794 ShstrIndex = (*Sec)->sh_link; in readSections()
1800 Expected<StringTableSection *> Sec = in readSections() local
1807 if (!Sec) in readSections()
1808 return Sec.takeError(); in readSections()
1810 Obj.SectionNames = *Sec; in readSections()
1836 for (SectionBase &Sec : Obj.sections()) { in readSections()
1837 if (&Sec == Obj.SymbolTable) in readSections()
1839 if (Error Err = Sec.initialize(Obj.sections())) in readSections()
1841 if (auto RelSec = dyn_cast<RelocationSection>(&Sec)) { in readSections()
1866 } else if (auto GroupSec = dyn_cast<GroupSection>(&Sec)) { in readSections()
2060 for (SectionBase &Sec : Obj.sections()) in writeShdrs()
2061 writeShdr(Sec); in writeShdrs()
2065 for (SectionBase &Sec : Obj.sections()) in writeSectionData()
2069 if (Sec.ParentSegment == nullptr) in writeSectionData()
2070 if (Error Err = Sec.accept(*SecWriter)) in writeSectionData()
2084 for (auto &Sec : Obj.removedSections()) { in writeSegmentData() local
2085 Segment *Parent = Sec.ParentSegment; in writeSegmentData()
2086 if (Parent == nullptr || Sec.Type == SHT_NOBITS || Sec.Size == 0) in writeSegmentData()
2089 Sec.OriginalOffset - Parent->OriginalOffset + Parent->Offset; in writeSegmentData()
2090 std::memset(Buf.getBufferStart() + Offset, 0, Sec.Size); in writeSegmentData()
2104 std::begin(Sections), std::end(Sections), [=](const SecPtr &Sec) { in removeSections() argument
2105 if (ToRemove(*Sec)) in removeSections()
2107 if (auto RelSec = dyn_cast<RelocationSectionBase>(Sec.get())) { in removeSections()
2138 AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) { in removeSections() argument
2139 return RemoveSections.find(Sec) != RemoveSections.end(); in removeSections()
2154 for (const SecPtr &Sec : Sections) in removeSymbols() local
2155 if (Error E = Sec->removeSymbols(ToRemove)) in removeSymbols()
2165 for (SectionBase &Sec : sections()) { in addNewSymbolTable()
2166 if (Sec.Type == ELF::SHT_STRTAB && !(Sec.Flags & SHF_ALLOC)) { in addNewSymbolTable()
2167 StrTab = static_cast<StringTableSection *>(&Sec); in addNewSymbolTable()
2171 if (SectionNames != &Sec) in addNewSymbolTable()
2253 for (auto &Sec : Sections) { in layoutSections() local
2254 Sec.Index = Index++; in layoutSections()
2255 if (Sec.ParentSegment != nullptr) { in layoutSections()
2256 auto Segment = *Sec.ParentSegment; in layoutSections()
2257 Sec.Offset = in layoutSections()
2258 Segment.Offset + (Sec.OriginalOffset - Segment.OriginalOffset); in layoutSections()
2260 Offset = alignTo(Offset, Sec.Align == 0 ? 1 : Sec.Align); in layoutSections()
2261 Sec.Offset = Offset; in layoutSections()
2262 if (Sec.Type != SHT_NOBITS) in layoutSections()
2263 Offset += Sec.Size; in layoutSections()
2273 for (auto &Sec : Obj.sections()) { in layoutSectionsForOnlyKeepDebug() local
2274 Sec.Index = Index++; in layoutSectionsForOnlyKeepDebug()
2276 auto *FirstSec = Sec.ParentSegment && Sec.ParentSegment->Type == PT_LOAD in layoutSectionsForOnlyKeepDebug()
2277 ? Sec.ParentSegment->firstSection() in layoutSectionsForOnlyKeepDebug()
2282 if (FirstSec && FirstSec == &Sec) in layoutSectionsForOnlyKeepDebug()
2283 Off = alignTo(Off, Sec.ParentSegment->Align, Sec.Addr); in layoutSectionsForOnlyKeepDebug()
2288 if (Sec.Type == SHT_NOBITS) { in layoutSectionsForOnlyKeepDebug()
2289 Sec.Offset = Off; in layoutSectionsForOnlyKeepDebug()
2296 Off = Sec.Align ? alignTo(Off, Sec.Align) : Off; in layoutSectionsForOnlyKeepDebug()
2297 } else if (FirstSec != &Sec) { in layoutSectionsForOnlyKeepDebug()
2300 Off = Sec.OriginalOffset - FirstSec->OriginalOffset + FirstSec->Offset; in layoutSectionsForOnlyKeepDebug()
2302 Sec.Offset = Off; in layoutSectionsForOnlyKeepDebug()
2303 Off += Sec.Size; in layoutSectionsForOnlyKeepDebug()
2327 for (const SectionBase *Sec : Seg->Sections) { in layoutSegmentsForOnlyKeepDebug() local
2328 uint64_t Size = Sec->Type == SHT_NOBITS ? 0 : Sec->Size; in layoutSegmentsForOnlyKeepDebug()
2329 if (Sec->Offset + Size > Offset) in layoutSegmentsForOnlyKeepDebug()
2330 FileSize = std::max(FileSize, Sec->Offset + Size - Offset); in layoutSegmentsForOnlyKeepDebug()
2429 return Obj.removeSections(false, [&](const SectionBase &Sec) { in removeUnneededSections() argument
2430 return &Sec == Obj.SymbolTable || &Sec == StrTab; in removeUnneededSections()
2455 [](const SectionBase &Sec) { return Sec.HasSymbol; }); in finalize() argument
2476 [this](const SectionBase &Sec) { in finalize() argument
2477 return &Sec == Obj.SectionIndexTable; in finalize()
2486 for (const SectionBase &Sec : Obj.sections()) in finalize() local
2487 Obj.SectionNames->addString(Sec.Name); in finalize()
2496 for (SectionBase &Sec : Obj.sections()) { in finalize()
2497 Sec.Index = Index++; in finalize()
2498 if (Error Err = Sec.accept(*SecSizer)) in finalize()
2510 for (SectionBase &Sec : Obj.sections()) in finalize()
2511 if (auto StrTab = dyn_cast<StringTableSection>(&Sec)) in finalize()
2524 for (SectionBase &Sec : Obj.sections()) { in finalize()
2525 Sec.HeaderOffset = Offset; in finalize()
2528 Sec.NameIndex = Obj.SectionNames->findIndex(Sec.Name); in finalize()
2529 Sec.finalize(); in finalize()
2539 for (const SectionBase &Sec : Obj.allocSections()) in write() local
2540 if (Error Err = Sec.accept(*SecWriter)) in write()
2552 for (SectionBase &Sec : Obj.allocSections()) { in finalize()
2553 if (Sec.ParentSegment != nullptr) in finalize()
2554 Sec.Addr = in finalize()
2555 Sec.Offset - Sec.ParentSegment->Offset + Sec.ParentSegment->PAddr; in finalize()
2556 if (Sec.Size > 0) in finalize()
2557 MinAddr = std::min(MinAddr, Sec.Addr); in finalize()
2565 for (SectionBase &Sec : Obj.allocSections()) in finalize()
2566 if (Sec.Type != SHT_NOBITS && Sec.Size > 0) { in finalize()
2567 Sec.Offset = Sec.Addr - MinAddr; in finalize()
2568 TotalSize = std::max(TotalSize, Sec.Offset + Sec.Size); in finalize()
2613 for (const SectionBase *Sec : Sections) in write() local
2614 if (Error Err = Sec->accept(Writer)) in write()
2626 Error IHexWriter::checkSection(const SectionBase &Sec) { in checkSection() argument
2627 uint64_t Addr = sectionPhysicalAddr(&Sec); in checkSection()
2628 if (addressOverflows32bit(Addr) || addressOverflows32bit(Addr + Sec.Size - 1)) in checkSection()
2632 Sec.Name.c_str(), Addr, Addr + Sec.Size - 1); in checkSection()
2638 auto ShouldWrite = [](const SectionBase &Sec) { in finalize() argument
2639 return (Sec.Flags & ELF::SHF_ALLOC) && (Sec.Type != ELF::SHT_NOBITS); in finalize()
2641 auto IsInPtLoad = [](const SectionBase &Sec) { in finalize() argument
2642 return Sec.ParentSegment && Sec.ParentSegment->Type == ELF::PT_LOAD; in finalize()
2654 for (const SectionBase &Sec : Obj.sections()) in finalize() local
2655 if (ShouldWrite(Sec) && IsInPtLoad(Sec)) { in finalize()
2660 for (const SectionBase &Sec : Obj.sections()) in finalize() local
2661 if (ShouldWrite(Sec) && (!UseSegments || IsInPtLoad(Sec))) { in finalize()
2662 if (Error E = checkSection(Sec)) in finalize()
2664 Sections.insert(&Sec); in finalize()
2668 for (const SectionBase *Sec : Sections) in finalize() local
2669 if (Error Err = Sec->accept(LengthCalc)) in finalize()