diff options
Diffstat (limited to 'llvm/lib/ObjectYAML/ELFYAML.cpp')
| -rw-r--r-- | llvm/lib/ObjectYAML/ELFYAML.cpp | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index 161224b0bb7..af795f9732c 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1017,6 +1017,12 @@ static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { IO.mapOptional("Info", Section.Info); } +static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) { + commonSectionMapping(IO, Section); + IO.mapOptional("Content", Section.Content); + IO.mapOptional("Entries", Section.Entries); +} + static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) { commonSectionMapping(IO, Section); IO.mapOptional("Size", Section.Size, Hex64(0)); @@ -1142,20 +1148,40 @@ void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping( sectionMapping(IO, *cast<ELFYAML::SymtabShndxSection>(Section.get())); break; default: - if (!IO.outputting()) - Section.reset(new ELFYAML::RawContentSection()); - sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get())); + if (!IO.outputting()) { + StringRef Name; + IO.mapOptional("Name", Name, StringRef()); + + if (ELFYAML::StackSizesSection::nameMatches(Name)) + Section = std::make_unique<ELFYAML::StackSizesSection>(); + else + Section = std::make_unique<ELFYAML::RawContentSection>(); + } + + if (auto S = dyn_cast<ELFYAML::RawContentSection>(Section.get())) + sectionMapping(IO, *S); + else + sectionMapping(IO, *cast<ELFYAML::StackSizesSection>(Section.get())); } } StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate( IO &io, std::unique_ptr<ELFYAML::Section> &Section) { - const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get()); - if (!RawSection) + if (const auto *RawSection = + dyn_cast<ELFYAML::RawContentSection>(Section.get())) { + if (RawSection->Size && RawSection->Content && + (uint64_t)(*RawSection->Size) < RawSection->Content->binary_size()) + return "Section size must be greater than or equal to the content size"; return {}; - if (RawSection->Size && RawSection->Content && - (uint64_t)(*RawSection->Size) < RawSection->Content->binary_size()) - return "Section size must be greater than or equal to the content size"; + } + + if (const auto *SS = dyn_cast<ELFYAML::StackSizesSection>(Section.get())) { + if (SS->Content && SS->Entries) + return ".stack_sizes: Content and Entries cannot be used together"; + if (!SS->Content && !SS->Entries) + return ".stack_sizes: either Content or Entries tag must be specified"; + return {}; + } return {}; } @@ -1184,6 +1210,13 @@ struct NormalizedMips64RelType { } // end anonymous namespace +void MappingTraits<ELFYAML::StackSizeEntry>::mapping( + IO &IO, ELFYAML::StackSizeEntry &E) { + assert(IO.getContext() && "The IO context is not initialized"); + IO.mapOptional("Address", E.Address, Hex64(0)); + IO.mapRequired("Size", E.Size); +} + void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO, ELFYAML::DynamicEntry &Rel) { assert(IO.getContext() && "The IO context is not initialized"); |

