Lines Matching refs: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
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()
193 for (auto &Sec : Obj.sections()) { in dumpSectionToFile() local
194 if (Sec.Name == SecName) { in dumpSectionToFile()
195 if (Sec.Type == SHT_NOBITS) in dumpSectionToFile()
200 FileOutputBuffer::create(Filename, Sec.OriginalData.size()); in dumpSectionToFile()
204 std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), in dumpSectionToFile()
215 static bool isCompressable(const SectionBase &Sec) { in isCompressable() argument
216 return !(Sec.Flags & ELF::SHF_COMPRESSED) && in isCompressable()
217 StringRef(Sec.Name).starts_with(".debug"); in isCompressable()
227 for (auto &Sec : Obj.sections()) in replaceDebugSections() local
228 if (ShouldReplace(Sec)) in replaceDebugSections()
229 ToReplace.push_back(&Sec); in replaceDebugSections()
341 for (SectionBase &Sec : Obj.sections()) in updateAndRemoveSymbols()
342 Sec.markSymbols(); in updateAndRemoveSymbols()
391 RemovePred = [&Config](const SectionBase &Sec) { in replaceAndRemoveSections() argument
392 return Config.ToRemove.matches(Sec.Name); in replaceAndRemoveSections()
397 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
398 return isDWOSection(Sec) || RemovePred(Sec); in replaceAndRemoveSections()
402 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
403 return onlyKeepDWOPred(Obj, Sec) || RemovePred(Sec); in replaceAndRemoveSections()
407 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
408 if (RemovePred(Sec)) in replaceAndRemoveSections()
410 if ((Sec.Flags & SHF_ALLOC) != 0) in replaceAndRemoveSections()
412 if (&Sec == Obj.SectionNames) in replaceAndRemoveSections()
414 switch (Sec.Type) { in replaceAndRemoveSections()
421 return isDebugSection(Sec); in replaceAndRemoveSections()
425 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
426 return RemovePred(Sec) || Sec.ParentSegment == nullptr; in replaceAndRemoveSections()
431 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
432 return RemovePred(Sec) || isDebugSection(Sec); in replaceAndRemoveSections()
437 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
438 if (RemovePred(Sec)) in replaceAndRemoveSections()
440 if (&Sec == Obj.SectionNames) in replaceAndRemoveSections()
442 return (Sec.Flags & SHF_ALLOC) == 0 && Sec.ParentSegment == nullptr; in replaceAndRemoveSections()
446 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
447 if (RemovePred(Sec)) in replaceAndRemoveSections()
449 if (&Sec == Obj.SectionNames) in replaceAndRemoveSections()
451 if (StringRef(Sec.Name).starts_with(".gnu.warning")) in replaceAndRemoveSections()
457 if (Sec.Type == SHT_ARM_ATTRIBUTES) in replaceAndRemoveSections()
459 if (Sec.ParentSegment != nullptr) in replaceAndRemoveSections()
461 return (Sec.Flags & SHF_ALLOC) == 0; in replaceAndRemoveSections()
465 RemovePred = [RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
466 if (RemovePred(Sec)) in replaceAndRemoveSections()
468 if (Sec.Type == SHT_LLVM_PART_EHDR || Sec.Type == SHT_LLVM_PART_PHDR) in replaceAndRemoveSections()
470 return (Sec.Flags & SHF_ALLOC) != 0 && !Sec.ParentSegment; in replaceAndRemoveSections()
476 RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) { in replaceAndRemoveSections() argument
478 if (Config.OnlySection.matches(Sec.Name)) in replaceAndRemoveSections()
482 if (RemovePred(Sec)) in replaceAndRemoveSections()
486 if (Obj.SectionNames == &Sec) in replaceAndRemoveSections()
488 if (Obj.SymbolTable == &Sec || in replaceAndRemoveSections()
489 (Obj.SymbolTable && Obj.SymbolTable->getStrTab() == &Sec)) in replaceAndRemoveSections()
498 RemovePred = [&Config, RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
500 if (Config.KeepSection.matches(Sec.Name)) in replaceAndRemoveSections()
503 return RemovePred(Sec); in replaceAndRemoveSections()
514 RemovePred = [&Obj, RemovePred](const SectionBase &Sec) { in replaceAndRemoveSections() argument
515 if (&Sec == Obj.SymbolTable || &Sec == Obj.SymbolTable->getStrTab()) in replaceAndRemoveSections()
517 return RemovePred(Sec); in replaceAndRemoveSections()
549 SectionBase *Sec = Obj.findSection(SymInfo.SectionName); in addSymbol() local
550 uint64_t Value = Sec ? Sec->Addr + SymInfo.Value : SymInfo.Value; in addSymbol()
596 SymInfo.SymbolName, Bind, Type, Sec, Value, Visibility, in addSymbol()
597 Sec ? (uint16_t)SYMBOL_SIMPLE_INDEX : (uint16_t)SHN_ABS, 0); in addSymbol()
626 [&Obj](const SectionBase &Sec) { return onlyKeepDWOPred(Obj, Sec); }); in handleArgs() argument
649 for (SectionBase &Sec : Obj.sections()) { in handleArgs()
650 auto I = Config.SetSectionAlignment.find(Sec.Name); in handleArgs()
652 Sec.Align = I->second; in handleArgs()
657 for (auto &Sec : Obj.sections()) in handleArgs() local
658 if (Sec.Flags & SHF_ALLOC && Sec.Type != SHT_NOTE) in handleArgs()
659 Sec.Type = SHT_NOBITS; in handleArgs()
696 for (auto &Sec : Obj.sections()) { in handleArgs() local
697 const auto Iter = Config.SetSectionFlags.find(Sec.Name); in handleArgs()
700 if (Error E = setSectionFlagsAndType(Sec, SFU.NewFlags, Obj.Machine)) in handleArgs()
703 auto It2 = Config.SetSectionType.find(Sec.Name); in handleArgs()
705 setSectionType(Sec, It2->second); in handleArgs()
712 for (SectionBase &Sec : Obj.sections()) { in handleArgs()
713 auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec); in handleArgs()
714 const auto Iter = Config.SectionsToRename.find(Sec.Name); in handleArgs()
717 Sec.Name = std::string(SR.NewName); in handleArgs()
719 if (Error E = setSectionFlagsAndType(Sec, *SR.NewFlags, Obj.Machine)) in handleArgs()
722 RenamedSections.insert(&Sec); in handleArgs()
723 } else if (RelocSec && !(Sec.Flags & SHF_ALLOC)) in handleArgs()
746 for (SectionBase &Sec : Obj.sections()) { in handleArgs()
747 if (Sec.Flags & SHF_ALLOC) { in handleArgs()
748 Sec.Name = (Config.AllocSectionsPrefix + Sec.Name).str(); in handleArgs()
749 PrefixedSections.insert(&Sec); in handleArgs()
750 } else if (auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec)) { in handleArgs()
765 Sec.Name = (RelocSec->getNamePrefix() + TargetSec->Name).str(); in handleArgs()
767 Sec.Name = (RelocSec->getNamePrefix() + Config.AllocSectionsPrefix + in handleArgs()