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()
461 Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) { in visit() argument
462 const size_t DataOffset = isDataGnuCompressed(Sec.OriginalData) in visit()
463 ? (ZlibGnuMagic.size() + sizeof(Sec.Size)) in visit()
467 reinterpret_cast<const char *>(Sec.OriginalData.data()) + DataOffset, in visit()
468 Sec.OriginalData.size() - DataOffset); in visit()
472 static_cast<size_t>(Sec.Size))) in visit()
474 "'" + Sec.Name + "': " + toString(std::move(Err))); in visit()
476 uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
482 Error BinarySectionWriter::visit(const DecompressedSection &Sec) { in visit() argument
484 "cannot write compressed section '" + Sec.Name + in visit()
513 Error BinarySectionWriter::visit(const CompressedSection &Sec) { in visit() argument
515 "cannot write compressed section '" + Sec.Name + in visit()
520 Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) { in visit() argument
521 uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
522 if (Sec.CompressionType == DebugCompressionType::None) { in visit()
523 std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), Buf); in visit()
527 if (Sec.CompressionType == DebugCompressionType::GNU) { in visit()
532 support::endian::read64be(&Sec.DecompressedSize); in visit()
538 Chdr.ch_size = Sec.DecompressedSize; in visit()
539 Chdr.ch_addralign = Sec.DecompressedAlign; in visit()
544 std::copy(Sec.CompressedData.begin(), Sec.CompressedData.end(), Buf); in visit()
549 CompressedSection::create(const SectionBase &Sec, in create() argument
552 CompressedSection Section(Sec, CompressionType, Err); in create()
566 CompressedSection::CompressedSection(const SectionBase &Sec, in CompressedSection() argument
569 : SectionBase(Sec), CompressionType(CompressionType), in CompressedSection()
570 DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) { in CompressedSection()
584 Name = ".z" + Sec.Name.substr(1); in CompressedSection()
625 Error SectionWriter::visit(const StringTableSection &Sec) { in visit() argument
626 Sec.StrTabBuilder.write(reinterpret_cast<uint8_t *>(Out.getBufferStart()) + in visit()
627 Sec.Offset); in visit()
640 Error ELFSectionWriter<ELFT>::visit(const SectionIndexSection &Sec) { in visit() argument
641 uint8_t *Buf = reinterpret_cast<uint8_t *>(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 = reinterpret_cast<uint8_t *>(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()
1112 for (SectionBase *&Sec : GroupMembers) in replaceSectionReferences()
1113 if (SectionBase *To = FromTo.lookup(Sec)) in replaceSectionReferences()
1114 Sec = To; in replaceSectionReferences()
1120 for (SectionBase *Sec : GroupMembers) in onRemove()
1121 Sec->Flags &= ~SHF_GROUP; in onRemove()
1128 Expected<SectionBase *> Sec = in initialize() local
1131 if (!Sec) in initialize()
1132 return Sec.takeError(); in initialize()
1134 LinkSection = *Sec; in initialize()
1168 Error ELFSectionWriter<ELFT>::visit(const GnuDebugLinkSection &Sec) { in visit() argument
1170 reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset; in visit()
1172 reinterpret_cast<Elf_Word *>(Buf + Sec.Size - sizeof(Elf_Word)); in visit()
1173 *CRC = Sec.CRC32; in visit()
1174 llvm::copy(Sec.FileName, Buf); in visit()
1187 Error ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) { in visit() argument
1189 reinterpret_cast<ELF::Elf32_Word *>(Out.getBufferStart() + Sec.Offset); in visit()
1190 support::endian::write32<ELFT::TargetEndianness>(Buf++, Sec.FlagWord); in visit()
1191 for (SectionBase *S : Sec.GroupMembers) in visit()
1205 static bool sectionWithinSegment(const SectionBase &Sec, const Segment &Seg) { in sectionWithinSegment() argument
1210 uint64_t SecSize = Sec.Size ? Sec.Size : 1; in sectionWithinSegment()
1213 if (Sec.OriginalOffset == std::numeric_limits<uint64_t>::max()) in sectionWithinSegment()
1216 if (Sec.Type == SHT_NOBITS) { in sectionWithinSegment()
1217 if (!(Sec.Flags & SHF_ALLOC)) in sectionWithinSegment()
1220 bool SectionIsTLS = Sec.Flags & SHF_TLS; in sectionWithinSegment()
1225 return Seg.VAddr <= Sec.Addr && in sectionWithinSegment()
1226 Seg.VAddr + Seg.MemSize >= Sec.Addr + SecSize; in sectionWithinSegment()
1229 return Seg.Offset <= Sec.OriginalOffset && in sectionWithinSegment()
1230 Seg.Offset + Seg.FileSize >= Sec.OriginalOffset + SecSize; in sectionWithinSegment()
1286 for (SectionBase &Sec : Obj->sections()) in initSections()
1287 if (Error Err = Sec.initialize(Obj->sections())) in initSections()
1407 for (const SectionBase &Sec : Obj.sections()) { in findEhdrOffset() local
1408 if (Sec.Type == SHT_LLVM_PART_EHDR && Sec.Name == *ExtractPartition) { in findEhdrOffset()
1409 EhdrOffset = Sec.Offset; in findEhdrOffset()
1448 for (SectionBase &Sec : Obj.sections()) in readProgramHeaders()
1449 if (sectionWithinSegment(Sec, Seg)) { in readProgramHeaders()
1450 Seg.addSection(&Sec); in readProgramHeaders()
1451 if (!Sec.ParentSegment || Sec.ParentSegment->Offset > Seg.Offset) in readProgramHeaders()
1452 Sec.ParentSegment = &Seg; in readProgramHeaders()
1524 Expected<SectionBase *> Sec = SecTable.getSection( in initGroupSection() local
1527 if (!Sec) in initGroupSection()
1528 return Sec.takeError(); in initGroupSection()
1530 GroupSec->addMember(*Sec); in initGroupSection()
1585 Expected<SectionBase *> Sec = Obj.sections().getSection( in initSymbolTable() local
1588 if (!Sec) in initSymbolTable()
1589 return Sec.takeError(); in initSymbolTable()
1591 DefSection = *Sec; in initSymbolTable()
1602 Expected<SectionBase *> Sec = Obj.sections().getSection( in initSymbolTable() local
1606 if (!Sec) in initSymbolTable()
1607 return Sec.takeError(); in initSymbolTable()
1609 DefSection = *Sec; in initSymbolTable()
1670 if (T *Sec = dyn_cast<T>(*BaseSec)) in getSectionOfType() local
1671 return Sec; in getSectionOfType()
1772 Expected<SectionBase &> Sec = makeSection(Shdr); in readSectionHeaders() local
1773 if (!Sec) in readSectionHeaders()
1774 return Sec.takeError(); in readSectionHeaders()
1779 Sec->Name = SecName->str(); in readSectionHeaders()
1780 Sec->Type = Sec->OriginalType = Shdr.sh_type; in readSectionHeaders()
1781 Sec->Flags = Sec->OriginalFlags = Shdr.sh_flags; in readSectionHeaders()
1782 Sec->Addr = Shdr.sh_addr; in readSectionHeaders()
1783 Sec->Offset = Shdr.sh_offset; in readSectionHeaders()
1784 Sec->OriginalOffset = Shdr.sh_offset; in readSectionHeaders()
1785 Sec->Size = Shdr.sh_size; in readSectionHeaders()
1786 Sec->Link = Shdr.sh_link; in readSectionHeaders()
1787 Sec->Info = Shdr.sh_info; in readSectionHeaders()
1788 Sec->Align = Shdr.sh_addralign; in readSectionHeaders()
1789 Sec->EntrySize = Shdr.sh_entsize; in readSectionHeaders()
1790 Sec->Index = Index++; in readSectionHeaders()
1791 Sec->OriginalIndex = Sec->Index; in readSectionHeaders()
1792 Sec->OriginalData = in readSectionHeaders()
1803 Expected<const Elf_Shdr *> Sec = ElfFile.getSection(0); in readSections() local
1804 if (!Sec) in readSections()
1805 return Sec.takeError(); in readSections()
1807 ShstrIndex = (*Sec)->sh_link; in readSections()
1813 Expected<StringTableSection *> Sec = in readSections() local
1820 if (!Sec) in readSections()
1821 return Sec.takeError(); in readSections()
1823 Obj.SectionNames = *Sec; in readSections()
1849 for (SectionBase &Sec : Obj.sections()) { in readSections()
1850 if (&Sec == Obj.SymbolTable) in readSections()
1852 if (Error Err = Sec.initialize(Obj.sections())) in readSections()
1854 if (auto RelSec = dyn_cast<RelocationSection>(&Sec)) { in readSections()
1879 } else if (auto GroupSec = dyn_cast<GroupSection>(&Sec)) { in readSections()
2073 for (SectionBase &Sec : Obj.sections()) in writeShdrs()
2074 writeShdr(Sec); in writeShdrs()
2078 for (SectionBase &Sec : Obj.sections()) in writeSectionData()
2082 if (Sec.ParentSegment == nullptr) in writeSectionData()
2083 if (Error Err = Sec.accept(*SecWriter)) in writeSectionData()
2097 for (auto &Sec : Obj.removedSections()) { in writeSegmentData() local
2098 Segment *Parent = Sec.ParentSegment; in writeSegmentData()
2099 if (Parent == nullptr || Sec.Type == SHT_NOBITS || Sec.Size == 0) in writeSegmentData()
2102 Sec.OriginalOffset - Parent->OriginalOffset + Parent->Offset; in writeSegmentData()
2103 std::memset(Buf->getBufferStart() + Offset, 0, Sec.Size); in writeSegmentData()
2117 std::begin(Sections), std::end(Sections), [=](const SecPtr &Sec) { in removeSections() argument
2118 if (ToRemove(*Sec)) in removeSections()
2120 if (auto RelSec = dyn_cast<RelocationSectionBase>(Sec.get())) { in removeSections()
2151 AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) { in removeSections() argument
2152 return RemoveSections.find(Sec) != RemoveSections.end(); in removeSections()
2167 for (const SecPtr &Sec : Sections) in removeSymbols() local
2168 if (Error E = Sec->removeSymbols(ToRemove)) in removeSymbols()
2178 for (SectionBase &Sec : sections()) { in addNewSymbolTable()
2179 if (Sec.Type == ELF::SHT_STRTAB && !(Sec.Flags & SHF_ALLOC)) { in addNewSymbolTable()
2180 StrTab = static_cast<StringTableSection *>(&Sec); in addNewSymbolTable()
2184 if (SectionNames != &Sec) in addNewSymbolTable()
2266 for (auto &Sec : Sections) { in layoutSections() local
2267 Sec.Index = Index++; in layoutSections()
2268 if (Sec.ParentSegment != nullptr) { in layoutSections()
2269 auto Segment = *Sec.ParentSegment; in layoutSections()
2270 Sec.Offset = in layoutSections()
2271 Segment.Offset + (Sec.OriginalOffset - Segment.OriginalOffset); in layoutSections()
2273 Offset = alignTo(Offset, Sec.Align == 0 ? 1 : Sec.Align); in layoutSections()
2274 Sec.Offset = Offset; in layoutSections()
2275 if (Sec.Type != SHT_NOBITS) in layoutSections()
2276 Offset += Sec.Size; in layoutSections()
2286 for (auto &Sec : Obj.sections()) { in layoutSectionsForOnlyKeepDebug() local
2287 Sec.Index = Index++; in layoutSectionsForOnlyKeepDebug()
2289 auto *FirstSec = Sec.ParentSegment && Sec.ParentSegment->Type == PT_LOAD in layoutSectionsForOnlyKeepDebug()
2290 ? Sec.ParentSegment->firstSection() in layoutSectionsForOnlyKeepDebug()
2295 if (FirstSec && FirstSec == &Sec) in layoutSectionsForOnlyKeepDebug()
2296 Off = alignTo(Off, Sec.ParentSegment->Align, Sec.Addr); in layoutSectionsForOnlyKeepDebug()
2301 if (Sec.Type == SHT_NOBITS) { in layoutSectionsForOnlyKeepDebug()
2302 Sec.Offset = Off; in layoutSectionsForOnlyKeepDebug()
2309 Off = Sec.Align ? alignTo(Off, Sec.Align) : Off; in layoutSectionsForOnlyKeepDebug()
2310 } else if (FirstSec != &Sec) { in layoutSectionsForOnlyKeepDebug()
2313 Off = Sec.OriginalOffset - FirstSec->OriginalOffset + FirstSec->Offset; in layoutSectionsForOnlyKeepDebug()
2315 Sec.Offset = Off; in layoutSectionsForOnlyKeepDebug()
2316 Off += Sec.Size; in layoutSectionsForOnlyKeepDebug()
2341 for (const SectionBase *Sec : Seg->Sections) { in layoutSegmentsForOnlyKeepDebug() local
2342 uint64_t Size = Sec->Type == SHT_NOBITS ? 0 : Sec->Size; in layoutSegmentsForOnlyKeepDebug()
2343 if (Sec->Offset + Size > Offset) in layoutSegmentsForOnlyKeepDebug()
2344 FileSize = std::max(FileSize, Sec->Offset + Size - Offset); in layoutSegmentsForOnlyKeepDebug()
2447 return Obj.removeSections(false, [&](const SectionBase &Sec) { in removeUnneededSections() argument
2448 return &Sec == Obj.SymbolTable || &Sec == StrTab; in removeUnneededSections()
2475 [](const SectionBase &Sec) { return Sec.HasSymbol; }); in finalize() argument
2496 [this](const SectionBase &Sec) { in finalize() argument
2497 return &Sec == Obj.SectionIndexTable; in finalize()
2506 for (const SectionBase &Sec : Obj.sections()) in finalize() local
2507 Obj.SectionNames->addString(Sec.Name); in finalize()
2516 for (SectionBase &Sec : Obj.sections()) { in finalize()
2517 Sec.Index = Index++; in finalize()
2518 if (Error Err = Sec.accept(*SecSizer)) in finalize()
2530 for (SectionBase &Sec : Obj.sections()) in finalize()
2531 if (auto StrTab = dyn_cast<StringTableSection>(&Sec)) in finalize()
2544 for (SectionBase &Sec : Obj.sections()) { in finalize()
2545 Sec.HeaderOffset = Offset; in finalize()
2548 Sec.NameIndex = Obj.SectionNames->findIndex(Sec.Name); in finalize()
2549 Sec.finalize(); in finalize()
2564 for (const SectionBase &Sec : Obj.allocSections()) in write() local
2565 if (Error Err = Sec.accept(*SecWriter)) in write()
2580 for (SectionBase &Sec : Obj.allocSections()) { in finalize()
2581 if (Sec.ParentSegment != nullptr) in finalize()
2582 Sec.Addr = in finalize()
2583 Sec.Offset - Sec.ParentSegment->Offset + Sec.ParentSegment->PAddr; in finalize()
2584 if (Sec.Type != SHT_NOBITS && Sec.Size > 0) in finalize()
2585 MinAddr = std::min(MinAddr, Sec.Addr); in finalize()
2593 for (SectionBase &Sec : Obj.allocSections()) in finalize()
2594 if (Sec.Type != SHT_NOBITS && Sec.Size > 0) { in finalize()
2595 Sec.Offset = Sec.Addr - MinAddr; in finalize()
2596 TotalSize = std::max(TotalSize, Sec.Offset + Sec.Size); in finalize()
2644 for (const SectionBase *Sec : Sections) in write() local
2645 if (Error Err = Sec->accept(Writer)) in write()
2663 Error IHexWriter::checkSection(const SectionBase &Sec) { in checkSection() argument
2664 uint64_t Addr = sectionPhysicalAddr(&Sec); in checkSection()
2665 if (addressOverflows32bit(Addr) || addressOverflows32bit(Addr + Sec.Size - 1)) in checkSection()
2669 Sec.Name.c_str(), Addr, Addr + Sec.Size - 1); in checkSection()
2680 for (const SectionBase &Sec : Obj.sections()) in finalize() local
2681 if ((Sec.Flags & ELF::SHF_ALLOC) && Sec.Type != ELF::SHT_NOBITS && in finalize()
2682 Sec.Size > 0) { in finalize()
2683 if (Error E = checkSection(Sec)) in finalize()
2685 Sections.insert(&Sec); in finalize()
2695 for (const SectionBase *Sec : Sections) in finalize() local
2696 if (Error Err = Sec->accept(LengthCalc)) in finalize()