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