Lines Matching defs:Sec
47 using SectionPred = std::function<bool(const SectionBase &Sec)>;
49 static bool isDebugSection(const SectionBase &Sec) {
50 return StringRef(Sec.Name).starts_with(".debug") || Sec.Name == ".gdb_index";
53 static bool isDWOSection(const SectionBase &Sec) {
54 return StringRef(Sec.Name).ends_with(".dwo");
57 static bool onlyKeepDWOPred(const Object &Obj, const SectionBase &Sec) {
59 if (&Sec == Obj.SectionNames)
63 return !isDWOSection(Sec);
105 static void setSectionType(SectionBase &Sec, uint64_t Type) {
106 // If Sec's type is changed from SHT_NOBITS due to --set-section-flags,
108 if (Sec.Type == ELF::SHT_NOBITS && Type != ELF::SHT_NOBITS)
109 Sec.Offset = alignTo(Sec.Offset, std::max(Sec.Align, uint64_t(1)));
110 Sec.Type = Type;
113 static Error setSectionFlagsAndType(SectionBase &Sec, SectionFlag Flags,
118 Sec.Flags = getSectionFlagsPreserveMask(Sec.Flags, *NewFlags, EMachine);
123 if (Sec.Type == SHT_NOBITS &&
124 (!(Sec.Flags & ELF::SHF_ALLOC) ||
126 setSectionType(Sec, ELF::SHT_PROGBITS);
190 for (auto &Sec : Obj.sections()) {
191 if (Sec.Name == SecName) {
192 if (Sec.Type == SHT_NOBITS)
197 FileOutputBuffer::create(Filename, Sec.OriginalData.size());
201 std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(),
218 for (SectionBase &Sec : sections()) {
221 if (Matcher.matches(Sec.Name))
225 if (!(Sec.Flags & SHF_ALLOC) && StringRef(Sec.Name).starts_with(".debug")) {
234 if (Sec.ParentSegment)
237 "section '" + Sec.Name +
240 if (auto *CS = dyn_cast<CompressedSection>(&Sec)) {
243 &Sec, [=] { return &addSection<DecompressedSection>(*CS); });
245 ToReplace.emplace_back(&Sec, [=, S = &Sec] {
367 for (SectionBase &Sec : Obj.sections())
368 Sec.markSymbols();
417 RemovePred = [&Config](const SectionBase &Sec) {
418 return Config.ToRemove.matches(Sec.Name);
423 RemovePred = [RemovePred](const SectionBase &Sec) {
424 return isDWOSection(Sec) || RemovePred(Sec);
428 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
429 return onlyKeepDWOPred(Obj, Sec) || RemovePred(Sec);
433 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
434 if (RemovePred(Sec))
436 if ((Sec.Flags & SHF_ALLOC) != 0)
438 if (&Sec == Obj.SectionNames)
440 switch (Sec.Type) {
447 return isDebugSection(Sec);
451 RemovePred = [RemovePred](const SectionBase &Sec) {
452 return RemovePred(Sec) || Sec.ParentSegment == nullptr;
457 RemovePred = [RemovePred](const SectionBase &Sec) {
458 return RemovePred(Sec) || isDebugSection(Sec);
463 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
464 if (RemovePred(Sec))
466 if (&Sec == Obj.SectionNames)
468 return (Sec.Flags & SHF_ALLOC) == 0 && Sec.ParentSegment == nullptr;
472 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
473 if (RemovePred(Sec))
475 if (&Sec == Obj.SectionNames)
477 if (StringRef(Sec.Name).starts_with(".gnu.warning"))
479 if (StringRef(Sec.Name).starts_with(".gnu_debuglink"))
485 if (Sec.Type == SHT_ARM_ATTRIBUTES)
487 if (Sec.ParentSegment != nullptr)
489 return (Sec.Flags & SHF_ALLOC) == 0;
493 RemovePred = [RemovePred](const SectionBase &Sec) {
494 if (RemovePred(Sec))
496 if (Sec.Type == SHT_LLVM_PART_EHDR || Sec.Type == SHT_LLVM_PART_PHDR)
498 return (Sec.Flags & SHF_ALLOC) != 0 && !Sec.ParentSegment;
504 RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) {
506 if (Config.OnlySection.matches(Sec.Name))
510 if (RemovePred(Sec))
514 if (Obj.SectionNames == &Sec)
516 if (Obj.SymbolTable == &Sec ||
517 (Obj.SymbolTable && Obj.SymbolTable->getStrTab() == &Sec))
526 RemovePred = [&Config, RemovePred](const SectionBase &Sec) {
528 if (Config.KeepSection.matches(Sec.Name))
531 return RemovePred(Sec);
542 RemovePred = [&Obj, RemovePred](const SectionBase &Sec) {
543 if (&Sec == Obj.SymbolTable || &Sec == Obj.SymbolTable->getStrTab())
545 return RemovePred(Sec);
561 SectionBase *Sec = Obj.findSection(SymInfo.SectionName);
562 uint64_t Value = Sec ? Sec->Addr + SymInfo.Value : SymInfo.Value;
608 SymInfo.SymbolName, Bind, Type, Sec, Value, Visibility,
609 Sec ? (uint16_t)SYMBOL_SIMPLE_INDEX : (uint16_t)SHN_ABS, 0);
688 for (auto &Sec : Obj.sections()) {
689 if (Sec.Type != SHT_NOTE || !Sec.hasContents())
692 if (Sec.ParentSegment) {
696 "cannot remove note(s) from " + Sec.Name +
701 ArrayRef<uint8_t> OldData = Sec.getContents();
702 size_t Align = std::max<size_t>(4, Sec.Align);
712 Sec, RemoveNoteDetail::updateData(OldData, ToRemove)))
793 [&Obj](const SectionBase &Sec) { return onlyKeepDWOPred(Obj, Sec); });
816 for (SectionBase &Sec : Obj.sections()) {
817 auto I = Config.SetSectionAlignment.find(Sec.Name);
819 Sec.Align = I->second;
860 for (SectionBase &Sec : Obj.sections()) {
861 if (PatternUpdate.SectionPattern.matches(Sec.Name) &&
862 SectionsToUpdateAddress.try_emplace(Sec.Name, PatternUpdate.Update)
865 Sec.Addr < PatternUpdate.Update.Value) {
868 "address 0x" + Twine::utohexstr(Sec.Addr) +
874 Sec.Addr > std::numeric_limits<uint64_t>::max() -
878 "address 0x" + Twine::utohexstr(Sec.Addr) +
886 Sec.Addr = PatternUpdate.Update.Value;
889 Sec.Addr -= PatternUpdate.Update.Value;
892 Sec.Addr += PatternUpdate.Update.Value;
901 for (auto &Sec : Obj.sections())
902 if (Sec.Flags & SHF_ALLOC && Sec.Type != SHT_NOTE)
903 Sec.Type = SHT_NOBITS;
953 for (auto &Sec : Obj.sections()) {
954 const auto Iter = Config.SetSectionFlags.find(Sec.Name);
957 if (Error E = setSectionFlagsAndType(Sec, SFU.NewFlags, Obj.Machine))
960 auto It2 = Config.SetSectionType.find(Sec.Name);
962 setSectionType(Sec, It2->second);
969 for (SectionBase &Sec : Obj.sections()) {
970 auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec);
971 const auto Iter = Config.SectionsToRename.find(Sec.Name);
974 Sec.Name = std::string(SR.NewName);
976 if (Error E = setSectionFlagsAndType(Sec, *SR.NewFlags, Obj.Machine))
979 RenamedSections.insert(&Sec);
980 } else if (RelocSec && !(Sec.Flags & SHF_ALLOC))
1003 for (SectionBase &Sec : Obj.sections()) {
1004 if (Sec.Flags & SHF_ALLOC) {
1005 Sec.Name = (Config.AllocSectionsPrefix + Sec.Name).str();
1006 PrefixedSections.insert(&Sec);
1007 } else if (auto *RelocSec = dyn_cast<RelocationSectionBase>(&Sec)) {
1022 Sec.Name = (RelocSec->getNamePrefix() + TargetSec->Name).str();
1024 Sec.Name = (RelocSec->getNamePrefix() + Config.AllocSectionsPrefix +