Lines Matching refs:Section

309 bool refersToReorderedSection(ErrorOr<BinarySection &> Section) {  in refersToReorderedSection()  argument
312 return (Section && Section->getName() == SectionName); in refersToReorderedSection()
456 for (const SectionRef &Section : InputFile->sections()) { in discoverStorage() local
457 Expected<StringRef> SectionNameOrErr = Section.getName(); in discoverStorage()
462 BC->OldTextSectionAddress = Section.getAddress(); in discoverStorage()
463 BC->OldTextSectionSize = Section.getSize(); in discoverStorage()
465 Expected<StringRef> SectionContentsOrErr = Section.getContents(); in discoverStorage()
837 BinarySection Section(*BC, *cantFail(Sym.getSection())); in discoverFileObjects() local
838 return Section.isAllocatable(); in discoverFileObjects()
1016 section_iterator Section = in discoverFileObjects() local
1018 if (Section == InputFile->section_end()) { in discoverFileObjects()
1030 if (!Section->isText()) { in discoverFileObjects()
1154 ErrorOr<BinarySection &> Section = BC->getSectionForAddress(Address); in discoverFileObjects() local
1156 if (!Section) { in discoverFileObjects()
1161 assert(Section && "section for functions must be registered"); in discoverFileObjects()
1164 if (!Section->getSize()) in discoverFileObjects()
1167 BF = BC->createBinaryFunction(UniqueName, *Section, Address, SymbolSize); in discoverFileObjects()
1207 ErrorOr<BinarySection &> Section = BC->getSectionForAddress(Address); in discoverFileObjects() local
1208 assert(Section && "cannot get section for address from FDE"); in discoverFileObjects()
1211 BC->createBinaryFunction(FunctionName, *Section, Address, in discoverFileObjects()
1277 ErrorOr<BinarySection &> Section = BC->getSectionForAddress(EntryAddress); in createPLTBinaryFunction() local
1278 assert(Section && "cannot get section for address"); in createPLTBinaryFunction()
1279 BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT", *Section, in createPLTBinaryFunction()
1281 Section->getAlignment()); in createPLTBinaryFunction()
1285 void RewriteInstance::disassemblePLTSectionAArch64(BinarySection &Section) { in disassemblePLTSectionAArch64() argument
1286 const uint64_t SectionAddress = Section.getAddress(); in disassemblePLTSectionAArch64()
1287 const uint64_t SectionSize = Section.getSize(); in disassemblePLTSectionAArch64()
1288 StringRef PLTContents = Section.getContents(); in disassemblePLTSectionAArch64()
1299 << Section.getName() << " at offset 0x" in disassemblePLTSectionAArch64()
1345 void RewriteInstance::disassemblePLTSectionX86(BinarySection &Section, in disassemblePLTSectionX86() argument
1347 const uint64_t SectionAddress = Section.getAddress(); in disassemblePLTSectionX86()
1348 const uint64_t SectionSize = Section.getSize(); in disassemblePLTSectionX86()
1349 StringRef PLTContents = Section.getContents(); in disassemblePLTSectionX86()
1360 << Section.getName() << " at offset 0x" in disassemblePLTSectionX86()
1401 auto analyzeOnePLTSection = [&](BinarySection &Section, uint64_t EntrySize) { in disassemblePLT() argument
1403 return disassemblePLTSectionAArch64(Section); in disassemblePLT()
1404 return disassemblePLTSectionX86(Section, EntrySize); in disassemblePLT()
1407 for (BinarySection &Section : BC->allocatableSections()) { in disassemblePLT()
1408 const PLTSectionInfo *PLTSI = getPLTSectionInfo(Section.getName()); in disassemblePLT()
1412 analyzeOnePLTSection(Section, PLTSI->EntrySize); in disassemblePLT()
1415 if (BC->getBinaryFunctions().find(Section.getAddress()) == in disassemblePLT()
1418 "__BOLT_PSEUDO_" + Section.getName().str(), Section, in disassemblePLT()
1419 Section.getAddress(), 0, PLTSI->EntrySize, Section.getAlignment()); in disassemblePLT()
1568 for (const SectionRef &Section : InputFile->sections()) { in readSpecialSections() local
1569 Expected<StringRef> SectionNameOrErr = Section.getName(); in readSpecialSections()
1575 if (Error E = Section.getContents().takeError()) in readSpecialSections()
1577 BC->registerSection(Section); in readSpecialSections()
1580 << Twine::utohexstr(Section.getAddress()) << ":0x" in readSpecialSections()
1581 << Twine::utohexstr(Section.getAddress() + Section.getSize()) in readSpecialSections()
1902 ErrorOr<BinarySection &> Section = BC->getSectionForAddress(SymbolAddress); in analyzeRelocation() local
1903 assert(Section && "section expected for section relocation"); in analyzeRelocation()
1904 SymbolName = "section " + std::string(Section->getName()); in analyzeRelocation()
1907 if (Section->containsAddress(ExtractedValue) && !IsPCRelative) { in analyzeRelocation()
2002 for (const SectionRef &Section : InputFile->sections()) { in processRelocations() local
2003 if (cantFail(Section.getRelocatedSection()) != InputFile->section_end() && in processRelocations()
2004 !BinarySection(*BC, Section).isAllocatable()) in processRelocations()
2005 readRelocations(Section); in processRelocations()
2218 void RewriteInstance::readDynamicRelocations(const SectionRef &Section, in readDynamicRelocations() argument
2220 assert(BinarySection(*BC, Section).isAllocatable() && "allocatable expected"); in readDynamicRelocations()
2223 StringRef SectionName = cantFail(Section.getName()); in readDynamicRelocations()
2228 for (const RelocationRef &Rel : Section.relocations()) { in readDynamicRelocations()
2267 void RewriteInstance::readRelocations(const SectionRef &Section) { in readRelocations() argument
2269 StringRef SectionName = cantFail(Section.getName()); in readRelocations()
2273 if (BinarySection(*BC, Section).isAllocatable()) { in readRelocations()
2277 section_iterator SecIter = cantFail(Section.getRelocatedSection()); in readRelocations()
2311 ErrorOr<BinarySection &> Section = BC->getSectionForAddress(SymbolAddress); in readRelocations() local
2317 << " (" << (Section ? Section->getName() : "") << ")" in readRelocations()
2329 for (const RelocationRef &Rel : Section.relocations()) { in readRelocations()
3175 ErrorOr<BinarySection &> Section = Function->getCodeSection(); in emitAndLink() local
3176 if (Section && in emitAndLink()
3182 if (Section) in emitAndLink()
3183 BC->deregisterSection(*Section); in emitAndLink()
3559 for (BinarySection &Section : BC->textSections()) in getCodeSections()
3560 if (Section.hasValidSectionID()) in getCodeSections()
3561 CodeSections.emplace_back(&Section); in getCodeSections()
3610 llvm::erase_if(CodeSections, [](BinarySection *Section) { in mapCodeSections() argument
3611 return Section->getOutputAddress(); in mapCodeSections()
3614 for (const BinarySection *Section : CodeSections) in mapCodeSections()
3615 dbgs() << Section->getName() << '\n'; in mapCodeSections()
3622 for (BinarySection *Section : CodeSections) { in mapCodeSections()
3623 Address = alignTo(Address, Section->getAlignment()); in mapCodeSections()
3624 Section->setOutputAddress(Address); in mapCodeSections()
3625 Address += Section->getOutputSize(); in mapCodeSections()
3664 for (BinarySection *Section : CodeSections) { in mapCodeSections()
3666 dbgs() << "BOLT: mapping " << Section->getName() << " at 0x" in mapCodeSections()
3667 << Twine::utohexstr(Section->getAllocAddress()) << " to 0x" in mapCodeSections()
3668 << Twine::utohexstr(Section->getOutputAddress()) << '\n'); in mapCodeSections()
3669 RTDyld.reassignSectionAddress(Section->getSectionID(), in mapCodeSections()
3670 Section->getOutputAddress()); in mapCodeSections()
3671 Section->setOutputFileOffset( in mapCodeSections()
3672 getFileOffsetForAddress(Section->getOutputAddress())); in mapCodeSections()
3713 BinarySection &Section = JT->getOutputSection(); in mapCodeSections() local
3714 Section.setOutputAddress(JT->getAddress()); in mapCodeSections()
3715 Section.setOutputFileOffset(getFileOffsetForAddress(JT->getAddress())); in mapCodeSections()
3716 LLVM_DEBUG(dbgs() << "BOLT-DEBUG: mapping " << Section.getName() in mapCodeSections()
3719 RTDyld.reassignSectionAddress(Section.getSectionID(), JT->getAddress()); in mapCodeSections()
3765 BinarySection &Section = in mapCodeSections() local
3772 Section.setOutputAddress(NewTextSectionStartAddress); in mapCodeSections()
3773 Section.setOutputFileOffset( in mapCodeSections()
3789 ErrorOr<BinarySection &> Section = BC->getUniqueSectionByName(SectionName); in mapDataSections() local
3790 if (!Section || !Section->isAllocatable() || !Section->isFinalized()) in mapDataSections()
3793 alignTo(NextAvailableAddress, Section->getAlignment()); in mapDataSections()
3795 << Twine::utohexstr(Section->getAllocAddress()) in mapDataSections()
3799 Section->getOutputSize()) in mapDataSections()
3802 RTDyld.reassignSectionAddress(Section->getSectionID(), in mapDataSections()
3804 Section->setOutputAddress(NextAvailableAddress); in mapDataSections()
3805 Section->setOutputFileOffset(getFileOffsetForAddress(NextAvailableAddress)); in mapDataSections()
3807 NextAvailableAddress += Section->getOutputSize(); in mapDataSections()
3811 for (BinarySection &Section : BC->sections()) { in mapDataSections()
3812 if (!Section.hasSectionRef()) in mapDataSections()
3815 StringRef SectionName = Section.getName(); in mapDataSections()
3834 << Twine::utohexstr(Section.getAddress()) << '\n'); in mapDataSections()
3837 Section.getAddress()); in mapDataSections()
3839 OrgSection->setOutputAddress(Section.getAddress()); in mapDataSections()
3840 OrgSection->setOutputFileOffset(Section.getContents().data() - in mapDataSections()
3846 for (BinarySection &Section : BC->allocatableSections()) { in mapExtraSections()
3847 if (Section.getOutputAddress() || !Section.hasValidSectionID()) in mapExtraSections()
3850 alignTo(NextAvailableAddress, Section.getAlignment()); in mapExtraSections()
3851 Section.setOutputAddress(NextAvailableAddress); in mapExtraSections()
3852 NextAvailableAddress += Section.getOutputSize(); in mapExtraSections()
3854 LLVM_DEBUG(dbgs() << "BOLT: (extra) mapping " << Section.getName() in mapExtraSections()
3855 << " at 0x" << Twine::utohexstr(Section.getAllocAddress()) in mapExtraSections()
3857 << Twine::utohexstr(Section.getOutputAddress()) << '\n'); in mapExtraSections()
3859 RTDyld.reassignSectionAddress(Section.getSectionID(), in mapExtraSections()
3860 Section.getOutputAddress()); in mapExtraSections()
3861 Section.setOutputFileOffset( in mapExtraSections()
3862 getFileOffsetForAddress(Section.getOutputAddress())); in mapExtraSections()
4000 for (const ELF64LE::Shdr &Section : cantFail(Obj.sections())) { in rewriteNoteSections() local
4001 if (Section.sh_type == ELF::SHT_NULL) in rewriteNoteSections()
4003 if (Section.sh_flags & ELF::SHF_ALLOC) in rewriteNoteSections()
4007 cantFail(Obj.getSectionName(Section), "cannot get section name"); in rewriteNoteSections()
4010 if (shouldStrip(Section, SectionName)) in rewriteNoteSections()
4015 appendPadding(OS, NextAvailableOffset, Section.sh_addralign); in rewriteNoteSections()
4023 Size = Section.sh_size; in rewriteNoteSections()
4024 StringRef Dataref = InputFile->getData().substr(Section.sh_offset, Size); in rewriteNoteSections()
4041 Size = appendPadding(OS, Size, Section.sh_addralign); in rewriteNoteSections()
4047 assert(BSec->getAlignment() <= Section.sh_addralign && in rewriteNoteSections()
4073 Section.sh_addralign, in rewriteNoteSections()
4084 for (BinarySection &Section : BC->nonAllocatableSections()) { in rewriteNoteSections()
4085 if (Section.getOutputFileOffset() || !Section.getAllocAddress()) in rewriteNoteSections()
4088 assert(!Section.hasPendingRelocations() && "cannot have pending relocs"); in rewriteNoteSections()
4091 appendPadding(OS, NextAvailableOffset, Section.getAlignment()); in rewriteNoteSections()
4092 Section.setOutputFileOffset(NextAvailableOffset); in rewriteNoteSections()
4095 dbgs() << "BOLT-DEBUG: writing out new section " << Section.getName() in rewriteNoteSections()
4096 << " of size " << Section.getOutputSize() << " at offset 0x" in rewriteNoteSections()
4097 << Twine::utohexstr(Section.getOutputFileOffset()) << '\n'); in rewriteNoteSections()
4099 OS.write(Section.getOutputContents().data(), Section.getOutputSize()); in rewriteNoteSections()
4100 NextAvailableOffset += Section.getOutputSize(); in rewriteNoteSections()
4110 for (const ELFShdrTy &Section : cantFail(Obj.sections())) { in finalizeSectionStringTable() local
4112 cantFail(Obj.getSectionName(Section), "cannot get section name"); in finalizeSectionStringTable()
4114 std::string OutputSectionName = getOutputSectionName(Obj, Section); in finalizeSectionStringTable()
4120 for (const BinarySection &Section : BC->sections()) in finalizeSectionStringTable() local
4121 SHStrTab.add(Section.getName()); in finalizeSectionStringTable()
4179 const ELFShdrTy &Section) { in getOutputSectionName() argument
4180 if (Section.sh_type == ELF::SHT_NULL) in getOutputSectionName()
4184 cantFail(Obj.getSectionName(Section), "cannot get section name"); in getOutputSectionName()
4186 if ((Section.sh_flags & ELF::SHF_ALLOC) && willOverwriteSection(SectionName)) in getOutputSectionName()
4193 bool RewriteInstance::shouldStrip(const ELFShdrTy &Section, in shouldStrip() argument
4196 if (!(Section.sh_flags & ELF::SHF_ALLOC) && Section.sh_type == ELF::SHT_RELA) in shouldStrip()
4204 if (opts::RemoveSymtab && Section.sh_type == ELF::SHT_SYMTAB) in shouldStrip()
4220 auto addSection = [&](const std::string &Name, const ELFShdrTy &Section) { in getOutputSections() argument
4221 ELFShdrTy NewSection = Section; in getOutputSections()
4227 for (const ELFShdrTy &Section : Sections) { in getOutputSections() local
4229 if (Section.sh_type == ELF::SHT_NULL) { in getOutputSections()
4230 OutputSections.emplace_back("", Section); in getOutputSections()
4234 if (!(Section.sh_flags & ELF::SHF_ALLOC)) in getOutputSections()
4237 addSection(getOutputSectionName(Obj, Section), Section); in getOutputSections()
4240 for (const BinarySection &Section : BC->allocatableSections()) { in getOutputSections() local
4241 if (!Section.isFinalized()) in getOutputSections()
4244 if (Section.getName().startswith(getOrgSecPrefix()) || in getOutputSections()
4245 Section.isAnonymous()) { in getOutputSections()
4248 << Section.getName() << '\n'; in getOutputSections()
4253 outs() << "BOLT-INFO: writing section header for " << Section.getName() in getOutputSections()
4257 NewSection.sh_addr = Section.getOutputAddress(); in getOutputSections()
4258 NewSection.sh_offset = Section.getOutputFileOffset(); in getOutputSections()
4259 NewSection.sh_size = Section.getOutputSize(); in getOutputSections()
4261 NewSection.sh_flags = Section.getELFFlags(); in getOutputSections()
4264 NewSection.sh_addralign = Section.getAlignment(); in getOutputSections()
4265 addSection(std::string(Section.getName()), NewSection); in getOutputSections()
4279 ELFShdrTy &Section = SectionKV.second; in getOutputSections() local
4283 if (Section.sh_type == ELF::SHT_NOBITS && (Section.sh_flags & ELF::SHF_TLS)) in getOutputSections()
4287 PrevSection->sh_addr + PrevSection->sh_size > Section.sh_addr) { in getOutputSections()
4291 PrevSection->sh_size = Section.sh_addr > PrevSection->sh_addr in getOutputSections()
4292 ? Section.sh_addr - PrevSection->sh_addr in getOutputSections()
4296 PrevSection = &Section; in getOutputSections()
4304 for (const ELFShdrTy &Section : Sections) { in getOutputSections() local
4305 if (Section.sh_type == ELF::SHT_NULL) in getOutputSections()
4307 if (Section.sh_flags & ELF::SHF_ALLOC) in getOutputSections()
4311 cantFail(Obj.getSectionName(Section), "cannot get section name"); in getOutputSections()
4313 if (shouldStrip(Section, SectionName)) in getOutputSections()
4319 ELFShdrTy NewSection = Section; in getOutputSections()
4332 for (BinarySection &Section : BC->nonAllocatableSections()) { in getOutputSections()
4333 if (Section.getOutputFileOffset() <= LastFileOffset) in getOutputSections()
4337 outs() << "BOLT-INFO: writing section header for " << Section.getName() in getOutputSections()
4341 NewSection.sh_type = Section.getELFType(); in getOutputSections()
4343 NewSection.sh_offset = Section.getOutputFileOffset(); in getOutputSections()
4344 NewSection.sh_size = Section.getOutputSize(); in getOutputSections()
4346 NewSection.sh_flags = Section.getELFFlags(); in getOutputSections()
4349 NewSection.sh_addralign = Section.getAlignment(); in getOutputSections()
4351 addSection(std::string(Section.getName()), NewSection); in getOutputSections()
4359 if (ErrorOr<BinarySection &> Section = in getOutputSections() local
4361 Section->setIndex(Index); in getOutputSections()
4367 for (const ELFShdrTy &Section : Sections) { in getOutputSections() local
4368 if (Section.sh_type == ELF::SHT_NULL) in getOutputSections()
4371 size_t OrgIndex = std::distance(Sections.begin(), &Section); in getOutputSections()
4372 std::string SectionName = getOutputSectionName(Obj, Section); in getOutputSections()
4418 for (ELFShdrTy &Section : OutputSections) { in patchELFSectionHeaderTable()
4419 Section.sh_link = NewSectionIndex[Section.sh_link]; in patchELFSectionHeaderTable()
4420 if (Section.sh_type == ELF::SHT_REL || Section.sh_type == ELF::SHT_RELA) { in patchELFSectionHeaderTable()
4421 if (Section.sh_info) in patchELFSectionHeaderTable()
4422 Section.sh_info = NewSectionIndex[Section.sh_info]; in patchELFSectionHeaderTable()
4424 OS.write(reinterpret_cast<const char *>(&Section), sizeof(Section)); in patchELFSectionHeaderTable()
4568 Expected<const typename ELFT::Shdr *> Section = in updateELFSymbolTable() local
4570 if (!Section) in updateELFSymbolTable()
4583 if (!((*Section)->sh_flags & ELF::SHF_ALLOC)) in updateELFSymbolTable()
4820 for (const ELFShdrTy &Section : cantFail(Obj.sections())) { in patchELFSymTabs() local
4821 if (Section.sh_type == ELF::SHT_DYNSYM) { in patchELFSymTabs()
4822 DynSymSection = &Section; in patchELFSymTabs()
4847 for (const ELFShdrTy &Section : cantFail(Obj.sections())) { in patchELFSymTabs() local
4848 if (Section.sh_type == ELF::SHT_SYMTAB) { in patchELFSymTabs()
4849 SymTabSection = &Section; in patchELFSymTabs()
4912 ErrorOr<BinarySection &> Section = BC->getSectionForAddress(Address); in patchELFAllocatableRelaSections() local
4913 Start = Section->getInputFileOffset(); in patchELFAllocatableRelaSections()
4914 End = Start + Section->getSize(); in patchELFAllocatableRelaSections()
4936 for (BinarySection &Section : BC->allocatableSections()) { in patchELFAllocatableRelaSections()
4937 for (const Relocation &Rel : Section.dynamicRelocations()) { in patchELFAllocatableRelaSections()
4946 uint64_t SectionAddress = Section.getOutputAddress(); in patchELFAllocatableRelaSections()
4948 SectionAddress == 0 ? Section.getAddress() : SectionAddress; in patchELFAllocatableRelaSections()
5014 for (const SectionRef &Section : File->sections()) { in patchELFGOT() local
5015 StringRef SectionName = cantFail(Section.getName()); in patchELFGOT()
5017 GOTSection = Section; in patchELFGOT()
5272 BinarySection &Section = JT->getOutputSection(); in rewriteFile() local
5273 BC->deregisterSection(Section); in rewriteFile()
5355 for (BinarySection &Section : BC->allocatableSections()) { in rewriteFile()
5356 if (!Section.isFinalized() || !Section.getOutputData()) in rewriteFile()
5360 outs() << "BOLT: writing new section " << Section.getName() in rewriteFile()
5361 << "\n data at 0x" << Twine::utohexstr(Section.getAllocAddress()) in rewriteFile()
5362 << "\n of size " << Section.getOutputSize() << "\n at offset " in rewriteFile()
5363 << Section.getOutputFileOffset() << '\n'; in rewriteFile()
5364 OS.pwrite(reinterpret_cast<const char *>(Section.getOutputData()), in rewriteFile()
5365 Section.getOutputSize(), Section.getOutputFileOffset()); in rewriteFile()
5368 for (BinarySection &Section : BC->allocatableSections()) in rewriteFile()
5369 Section.flushPendingRelocations(OS, [this](const MCSymbol *S) { in rewriteFile()
5526 ErrorOr<BinarySection &> Section = BC->getUniqueSectionByName(SectionName); in willOverwriteSection() local
5527 return Section && Section->isAllocatable() && Section->isFinalized(); in willOverwriteSection()