Lines Matching full:sec
52 using SectionPred = std::function<bool(const SectionBase &Sec)>;
54 static bool isDebugSection(const SectionBase &Sec) { in isDebugSection() argument
55 return StringRef(Sec.Name).starts_with(".debug") || Sec.Name == ".gdb_index"; in isDebugSection()
58 static bool isDWOSection(const SectionBase &Sec) { in isDWOSection() argument
59 return StringRef(Sec.Name).ends_with(".dwo"); in isDWOSection()
62 static bool onlyKeepDWOPred(const Object &Obj, const SectionBase &Sec) { in onlyKeepDWOPred() argument
64 if (&Sec == Obj.SectionNames) in onlyKeepDWOPred()
68 return !isDWOSection(Sec); in onlyKeepDWOPred()
110 static void setSectionType(SectionBase &Sec, uint64_t Type) { in setSectionType() argument
111 // If Sec's type is changed from SHT_NOBITS due to --set-section-flags, in setSectionType()
113 if (Sec.Type == ELF::SHT_NOBITS && Type != ELF::SHT_NOBITS) in setSectionType()
114 Sec.Offset = alignTo(Sec.Offset, std::max(Sec.Align, uint64_t(1))); in setSectionType()
115 Sec.Type = Type; in setSectionType()
118 static Error setSectionFlagsAndType(SectionBase &Sec, SectionFlag Flags, in setSectionFlagsAndType() argument
123 Sec.Flags = getSectionFlagsPreserveMask(Sec.Flags, *NewFlags, EMachine); in setSectionFlagsAndType()
128 if (Sec.Type == SHT_NOBITS && in setSectionFlagsAndType()
129 (!(Sec.Flags & ELF::SHF_ALLOC) || in setSectionFlagsAndType()
131 setSectionType(Sec, ELF::SHT_PROGBITS); in setSectionFlagsAndType()
195 for (auto &Sec : Obj.sections()) { in dumpSectionToFile() local
196 if (Sec.Name == SecName) { in dumpSectionToFile()
197 if (Sec.Type == SHT_NOBITS) in dumpSectionToFile()
202 FileOutputBuffer::create(Filename, Sec.OriginalData.size()); in dumpSectionToFile()
206 std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), in dumpSectionToFile()
223 for (SectionBase &Sec : sections()) { in compressOrDecompressSections()
226 if (Matcher.matches(Sec.Name)) in compressOrDecompressSections()
230 if (!(Sec.Flags & SHF_ALLOC) && StringRef(Sec.Name).starts_with(".debug")) { in compressOrDecompressSections()
239 if (Sec.ParentSegment) in compressOrDecompressSections()
242 "section '" + Sec.Name + in compressOrDecompressSections()
245 if (auto *CS = dyn_cast<CompressedSection>(&Sec)) { in compressOrDecompressSections()
248 &Sec, [=] { return &addSection<DecompressedSection>(*CS); }); in compressOrDecompressSections()
250 ToReplace.emplace_back(&Sec, [=, S = &Sec] { in compressOrDecompressSections()
372 for (SectionBase &Sec : Obj.sections()) in updateAndRemoveSymbols()
373 Sec.markSymbols(); in updateAndRemoveSymbols()
422 RemovePred = [&Config](const SectionBase &Sec) { in replaceAndRemoveSections() argument
423 return Config.ToRemove.matches(Sec.Name); in replaceAndRemoveSections()
428 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
429 return isDWOSection(Sec) || RemovePred(Sec); in replaceAndRemoveSections()
433 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
434 return onlyKeepDWOPred(Obj, Sec) || RemovePred(Sec); in replaceAndRemoveSections()
438 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
439 if (RemovePred(Sec)) in replaceAndRemoveSections()
441 if ((Sec.Flags & SHF_ALLOC) != 0) in replaceAndRemoveSections()
443 if (&Sec == Obj.SectionNames) in replaceAndRemoveSections()
445 switch (Sec.Type) { in replaceAndRemoveSections()
452 return isDebugSection(Sec); in replaceAndRemoveSections()
456 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
457 return RemovePred(Sec) || Sec.ParentSegment == nullptr; in replaceAndRemoveSections()
462 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
463 return RemovePred(Sec) || isDebugSection(Sec); in replaceAndRemoveSections()
468 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
469 if (RemovePred(Sec)) in replaceAndRemoveSections()
471 if (&Sec == Obj.SectionNames) in replaceAndRemoveSections()
473 return (Sec.Flags & SHF_ALLOC) == 0 && Sec.ParentSegment == nullptr; in replaceAndRemoveSections()
477 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
478 if (RemovePred(Sec)) in replaceAndRemoveSections()
480 if (&Sec == Obj.SectionNames) in replaceAndRemoveSections()
482 if (StringRef(Sec.Name).starts_with(".gnu.warning")) in replaceAndRemoveSections()
484 if (StringRef(Sec.Name).starts_with(".gnu_debuglink")) in replaceAndRemoveSections()
490 if (Sec.Type == SHT_ARM_ATTRIBUTES) in replaceAndRemoveSections()
492 if (Sec.ParentSegment != nullptr) in replaceAndRemoveSections()
494 return (Sec.Flags & SHF_ALLOC) == 0; in replaceAndRemoveSections()
498 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
499 if (RemovePred(Sec)) in replaceAndRemoveSections()
501 if (Sec.Type == SHT_LLVM_PART_EHDR || Sec.Type == SHT_LLVM_PART_PHDR) in replaceAndRemoveSections()
503 return (Sec.Flags & SHF_ALLOC) != 0 && !Sec.ParentSegment; in replaceAndRemoveSections()
509 RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
511 if (Config.OnlySection.matches(Sec.Name)) in replaceAndRemoveSections()
515 if (RemovePred(Sec)) in replaceAndRemoveSections()
519 if (Obj.SectionNames == &Sec) in replaceAndRemoveSections()
521 if (Obj.SymbolTable == &Sec || in replaceAndRemoveSections()
522 (Obj.SymbolTable && Obj.SymbolTable->getStrTab() == &Sec)) in replaceAndRemoveSections()
531 RemovePred = [&Config, RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
533 if (Config.KeepSection.matches(Sec.Name)) in replaceAndRemoveSections()
536 return RemovePred(Sec); in replaceAndRemoveSections()
547 RemovePred = [&Obj, RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
548 if (&Sec == Obj.SymbolTable || &Sec == Obj.SymbolTable->getStrTab()) in replaceAndRemoveSections()
550 return RemovePred(Sec); in replaceAndRemoveSections()
566 SectionBase *Sec = Obj.findSection(SymInfo.SectionName); in addSymbol() local
567 uint64_t Value = Sec ? Sec->Addr + SymInfo.Value : SymInfo.Value; in addSymbol()
613 SymInfo.SymbolName, Bind, Type, Sec, Value, Visibility, in addSymbol()
614 Sec ? (uint16_t)SYMBOL_SIMPLE_INDEX : (uint16_t)SHN_ABS, 0); in addSymbol()
691 [&Obj](const SectionBase &Sec) { return onlyKeepDWOPred(Obj, Sec); }); in handleArgs() argument
714 for (SectionBase &Sec : Obj.sections()) { in handleArgs()
715 auto I = Config.SetSectionAlignment.find(Sec.Name); in handleArgs()
717 Sec.Align = I->second; in handleArgs()
749 for (auto &Sec : Obj.sections()) in handleArgs() local
750 if (Sec.Flags & SHF_ALLOC && Sec.Type != SHT_NOTE) in handleArgs()
751 Sec.Type = SHT_NOBITS; in handleArgs()
795 for (auto &Sec : Obj.sections()) { in handleArgs() local
796 const auto Iter = Config.SetSectionFlags.find(Sec.Name); in handleArgs()
799 if (Error E = setSectionFlagsAndType(Sec, SFU.NewFlags, Obj.Machine)) in handleArgs()
802 auto It2 = Config.SetSectionType.find(Sec.Name); in handleArgs()
804 setSectionType(Sec, It2->second); in handleArgs()
811 for (SectionBase &Sec : Obj.sections()) { in handleArgs()
812 auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec); in handleArgs()
813 const auto Iter = Config.SectionsToRename.find(Sec.Name); in handleArgs()
816 Sec.Name = std::string(SR.NewName); in handleArgs()
818 if (Error E = setSectionFlagsAndType(Sec, *SR.NewFlags, Obj.Machine)) in handleArgs()
821 RenamedSections.insert(&Sec); in handleArgs()
822 } else if (RelocSec && !(Sec.Flags & SHF_ALLOC)) in handleArgs()
845 for (SectionBase &Sec : Obj.sections()) { in handleArgs()
846 if (Sec.Flags & SHF_ALLOC) { in handleArgs()
847 Sec.Name = (Config.AllocSectionsPrefix + Sec.Name).str(); in handleArgs()
848 PrefixedSections.insert(&Sec); in handleArgs()
849 } else if (auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec)) { in handleArgs()
864 Sec.Name = (RelocSec->getNamePrefix() + TargetSec->Name).str(); in handleArgs()
866 Sec.Name = (RelocSec->getNamePrefix() + Config.AllocSectionsPrefix + in handleArgs()