From 1e41007aeba071d1a30f1f0eb7ebfe41f75917fb Mon Sep 17 00:00:00 2001 From: George Rimar Date: Mon, 10 Jun 2019 12:43:18 +0000 Subject: [yaml2obj/obj2yaml] - Make RawContentSection::Content and RawContentSection::Size optional This is a follow-up for D62809. Content and Size fields should be optional as was discussed in comments of the D62809's thread. With that, we can describe a specific string table and symbol table sections in a more correct way and also show appropriate errors. The patch adds lots of test cases where the behavior is described in details. Differential revision: https://reviews.llvm.org/D62957 llvm-svn: 362931 --- llvm/lib/ObjectYAML/ELFYAML.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'llvm/lib/ObjectYAML') diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index 33d011cbd9f..8be86ab4707 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -914,7 +914,7 @@ static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) { static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { commonSectionMapping(IO, Section); IO.mapOptional("Content", Section.Content); - IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size())); + IO.mapOptional("Size", Section.Size); IO.mapOptional("Info", Section.Info, Hex64(0)); } @@ -1042,9 +1042,12 @@ void MappingTraits>::mapping( StringRef MappingTraits>::validate( IO &io, std::unique_ptr &Section) { const auto *RawSection = dyn_cast(Section.get()); - if (!RawSection || RawSection->Size >= RawSection->Content.binary_size()) - return StringRef(); - return "Section size must be greater or equal to the content size"; + if (!RawSection) + 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"; + return {}; } namespace { -- cgit v1.2.3