Index: llvm/include/llvm/ObjectYAML/ELFYAML.h =================================================================== --- llvm/include/llvm/ObjectYAML/ELFYAML.h +++ llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -178,6 +178,9 @@ llvm::yaml::Hex64 AddressAlign; Optional EntSize; + Optional Content; + Optional Size; + // Usually sections are not created implicitly, but loaded from YAML. // When they are, this flag is used to signal about that. bool IsImplicit; @@ -228,8 +231,6 @@ }; struct StackSizesSection : Section { - Optional Content; - Optional Size; Optional> Entries; StackSizesSection() : Section(ChunkKind::StackSizes) {} @@ -244,8 +245,7 @@ }; struct DynamicSection : Section { - std::vector Entries; - Optional Content; + Optional> Entries; DynamicSection() : Section(ChunkKind::Dynamic) {} @@ -253,8 +253,6 @@ }; struct RawContentSection : Section { - Optional Content; - Optional Size; Optional Info; RawContentSection() : Section(ChunkKind::RawContent) {} @@ -268,16 +266,12 @@ }; struct NoBitsSection : Section { - llvm::yaml::Hex64 Size; - NoBitsSection() : Section(ChunkKind::NoBits) {} static bool classof(const Chunk *S) { return S->Kind == ChunkKind::NoBits; } }; struct NoteSection : Section { - Optional Content; - Optional Size; Optional> Notes; NoteSection() : Section(ChunkKind::Note) {} @@ -286,8 +280,6 @@ }; struct HashSection : Section { - Optional Content; - Optional Size; Optional> Bucket; Optional> Chain; @@ -322,8 +314,6 @@ }; struct GnuHashSection : Section { - Optional Content; - Optional Header; Optional> BloomFilter; Optional> HashBuckets; @@ -348,7 +338,6 @@ }; struct VerneedSection : Section { - Optional Content; Optional> VerneedV; llvm::yaml::Hex64 Info; @@ -360,8 +349,6 @@ }; struct AddrsigSection : Section { - Optional Content; - Optional Size; Optional> Symbols; AddrsigSection() : Section(ChunkKind::Addrsig) {} @@ -376,7 +363,6 @@ struct LinkerOptionsSection : Section { Optional> Options; - Optional Content; LinkerOptionsSection() : Section(ChunkKind::LinkerOptions) {} @@ -387,7 +373,6 @@ struct DependentLibrariesSection : Section { Optional> Libs; - Optional Content; DependentLibrariesSection() : Section(ChunkKind::DependentLibraries) {} @@ -408,7 +393,6 @@ struct CallGraphProfileSection : Section { Optional> Entries; - Optional Content; CallGraphProfileSection() : Section(ChunkKind::CallGraphProfile) {} @@ -418,7 +402,7 @@ }; struct SymverSection : Section { - std::vector Entries; + Optional> Entries; SymverSection() : Section(ChunkKind::Symver) {} @@ -435,7 +419,6 @@ struct VerdefSection : Section { Optional> Entries; - Optional Content; llvm::yaml::Hex64 Info; @@ -447,7 +430,7 @@ struct GroupSection : Section { // Members of a group contain a flag and a list of section indices // that are part of the group. - std::vector Members; + Optional> Members; Optional Signature; /* Info */ GroupSection() : Section(ChunkKind::Group) {} @@ -463,7 +446,7 @@ }; struct RelocationSection : Section { - std::vector Relocations; + Optional> Relocations; StringRef RelocatableSec; /* Info */ RelocationSection() : Section(ChunkKind::Relocation) {} @@ -475,7 +458,6 @@ struct RelrSection : Section { Optional> Entries; - Optional Content; RelrSection() : Section(ChunkKind::Relr) {} @@ -485,7 +467,7 @@ }; struct SymtabShndxSection : Section { - std::vector Entries; + Optional> Entries; SymtabShndxSection() : Section(ChunkKind::SymtabShndxSection) {} @@ -501,8 +483,6 @@ struct ARMIndexTableSection : Section { Optional> Entries; - Optional Content; - Optional Size; ARMIndexTableSection() : Section(ChunkKind::ARMIndexTable) {} Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -1126,13 +1126,17 @@ ContiguousBlobAccumulator &CBA) { // SHT_NOBITS sections do not have any content to write. SHeader.sh_entsize = 0; - SHeader.sh_size = S.Size; + + if (!S.Size) + return; + + SHeader.sh_size = *S.Size; // When a nobits section is followed by a non-nobits section or fill // in the same segment, we allocate the file space for it. This behavior // matches linkers. if (shouldAllocateFileSpace(Doc.ProgramHeaders, S)) - CBA.writeZeros(S.Size); + CBA.writeZeros(*S.Size); } template @@ -1167,8 +1171,6 @@ SHeader.sh_entsize = *Section.EntSize; else SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); - SHeader.sh_size = (IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel)) * - Section.Relocations.size(); // For relocation section set link to .symtab by default. unsigned Link = 0; @@ -1179,7 +1181,15 @@ if (!Section.RelocatableSec.empty()) SHeader.sh_info = toSectionIndex(Section.RelocatableSec, Section.Name); - for (const auto &Rel : Section.Relocations) { + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); + return; + } + + if (!Section.Relocations) + return; + + for (const ELFYAML::Relocation &Rel : *Section.Relocations) { unsigned SymIdx = Rel.Symbol ? toSymbolIndex(*Rel.Symbol, Section.Name, Section.Link == ".dynsym") : 0; @@ -1198,6 +1208,9 @@ CBA.write((const char *)&REntry, sizeof(REntry)); } } + + SHeader.sh_size = (IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel)) * + Section.Relocations->size(); } template @@ -1207,8 +1220,8 @@ SHeader.sh_entsize = Section.EntSize ? uint64_t(*Section.EntSize) : sizeof(Elf_Relr); - if (Section.Content) { - SHeader.sh_size = writeContent(CBA, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; } @@ -1229,11 +1242,19 @@ void ELFState::writeSectionContent( Elf_Shdr &SHeader, const ELFYAML::SymtabShndxSection &Shndx, ContiguousBlobAccumulator &CBA) { - for (uint32_t E : Shndx.Entries) - CBA.write(E, ELFT::TargetEndianness); - SHeader.sh_entsize = Shndx.EntSize ? (uint64_t)*Shndx.EntSize : 4; - SHeader.sh_size = Shndx.Entries.size() * SHeader.sh_entsize; + + if (Shndx.Content || Shndx.Size) { + SHeader.sh_size = writeContent(CBA, Shndx.Content, Shndx.Size); + return; + } + + if (!Shndx.Entries) + return; + + for (uint32_t E : *Shndx.Entries) + CBA.write(E, ELFT::TargetEndianness); + SHeader.sh_size = Shndx.Entries->size() * SHeader.sh_entsize; } template @@ -1249,13 +1270,20 @@ SHeader.sh_link = Link; SHeader.sh_entsize = 4; - SHeader.sh_size = SHeader.sh_entsize * Section.Members.size(); if (Section.Signature) SHeader.sh_info = toSymbolIndex(*Section.Signature, Section.Name, /*IsDynamic=*/false); - for (const ELFYAML::SectionOrType &Member : Section.Members) { + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); + return; + } + + if (!Section.Members) + return; + + for (const ELFYAML::SectionOrType &Member : *Section.Members) { unsigned int SectionIndex = 0; if (Member.sectionNameOrType == "GRP_COMDAT") SectionIndex = llvm::ELF::GRP_COMDAT; @@ -1263,17 +1291,26 @@ SectionIndex = toSectionIndex(Member.sectionNameOrType, Section.Name); CBA.write(SectionIndex, ELFT::TargetEndianness); } + SHeader.sh_size = SHeader.sh_entsize * Section.Members->size(); } template void ELFState::writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::SymverSection &Section, ContiguousBlobAccumulator &CBA) { - for (uint16_t Version : Section.Entries) - CBA.write(Version, ELFT::TargetEndianness); - SHeader.sh_entsize = Section.EntSize ? (uint64_t)*Section.EntSize : 2; - SHeader.sh_size = Section.Entries.size() * SHeader.sh_entsize; + + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); + return; + } + + if (!Section.Entries) + return; + + for (uint16_t Version : *Section.Entries) + CBA.write(Version, ELFT::TargetEndianness); + SHeader.sh_size = Section.Entries->size() * SHeader.sh_entsize; } template @@ -1295,8 +1332,8 @@ void ELFState::writeSectionContent( Elf_Shdr &SHeader, const ELFYAML::LinkerOptionsSection &Section, ContiguousBlobAccumulator &CBA) { - if (Section.Content) { - SHeader.sh_size = writeContent(CBA, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; } @@ -1316,8 +1353,8 @@ void ELFState::writeSectionContent( Elf_Shdr &SHeader, const ELFYAML::DependentLibrariesSection &Section, ContiguousBlobAccumulator &CBA) { - if (Section.Content) { - SHeader.sh_size = writeContent(CBA, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; } @@ -1369,8 +1406,8 @@ SN2I.lookup(".symtab", Link)) SHeader.sh_link = Link; - if (Section.Content) { - SHeader.sh_size = writeContent(CBA, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; } @@ -1431,8 +1468,8 @@ SHeader.sh_info = Section.Info; - if (Section.Content) { - SHeader.sh_size = writeContent(CBA, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; } @@ -1481,8 +1518,8 @@ SHeader.sh_info = Section.Info; - if (Section.Content) { - SHeader.sh_size = writeContent(CBA, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; } @@ -1577,26 +1614,24 @@ assert(Section.Type == llvm::ELF::SHT_DYNAMIC && "Section type is not SHT_DYNAMIC"); - if (!Section.Entries.empty() && Section.Content) - reportError("cannot specify both raw content and explicit entries " - "for dynamic section '" + - Section.Name + "'"); - - if (Section.Content) - SHeader.sh_size = Section.Content->binary_size(); - else - SHeader.sh_size = 2 * sizeof(uintX_t) * Section.Entries.size(); if (Section.EntSize) SHeader.sh_entsize = *Section.EntSize; else SHeader.sh_entsize = sizeof(Elf_Dyn); - for (const ELFYAML::DynamicEntry &DE : Section.Entries) { + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); + return; + } + + if (!Section.Entries) + return; + + for (const ELFYAML::DynamicEntry &DE : *Section.Entries) { CBA.write(DE.Tag, ELFT::TargetEndianness); CBA.write(DE.Val, ELFT::TargetEndianness); } - if (Section.Content) - CBA.writeAsBinary(*Section.Content); + SHeader.sh_size = 2 * sizeof(uintX_t) * Section.Entries->size(); } template @@ -1670,8 +1705,8 @@ SN2I.lookup(".dynsym", Link)) SHeader.sh_link = Link; - if (Section.Content) { - SHeader.sh_size = writeContent(CBA, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; } Index: llvm/lib/ObjectYAML/ELFYAML.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFYAML.cpp +++ llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1105,6 +1105,9 @@ IO.mapOptional("EntSize", Section.EntSize); IO.mapOptional("Offset", Section.Offset); + IO.mapOptional("Content", Section.Content); + IO.mapOptional("Size", Section.Size); + // obj2yaml does not dump these fields. They are expected to be empty when we // are producing YAML, because yaml2obj sets appropriate values for them // automatically when they are not explicitly defined. @@ -1122,12 +1125,10 @@ static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) { commonSectionMapping(IO, Section); IO.mapOptional("Entries", Section.Entries); - IO.mapOptional("Content", Section.Content); } static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Content", Section.Content); // We also support reading a content as array of bytes using the ContentArray // key. obj2yaml never prints this field. @@ -1139,23 +1140,18 @@ Section.Content = yaml::BinaryRef(*Section.ContentBuf); } - IO.mapOptional("Size", Section.Size); IO.mapOptional("Info", Section.Info); } static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Content", Section.Content); - IO.mapOptional("Size", Section.Size); IO.mapOptional("Entries", Section.Entries); } static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Content", Section.Content); IO.mapOptional("Bucket", Section.Bucket); IO.mapOptional("Chain", Section.Chain); - IO.mapOptional("Size", Section.Size); // obj2yaml does not dump these fields. They can be used to override nchain // and nbucket values for creating broken sections. @@ -1167,15 +1163,12 @@ static void sectionMapping(IO &IO, ELFYAML::NoteSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Content", Section.Content); - IO.mapOptional("Size", Section.Size); IO.mapOptional("Notes", Section.Notes); } static void sectionMapping(IO &IO, ELFYAML::GnuHashSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Content", Section.Content); IO.mapOptional("Header", Section.Header); IO.mapOptional("BloomFilter", Section.BloomFilter); IO.mapOptional("HashBuckets", Section.HashBuckets); @@ -1183,26 +1176,23 @@ } static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Size", Section.Size, Hex64(0)); } static void sectionMapping(IO &IO, ELFYAML::VerdefSection &Section) { commonSectionMapping(IO, Section); IO.mapRequired("Info", Section.Info); IO.mapOptional("Entries", Section.Entries); - IO.mapOptional("Content", Section.Content); } static void sectionMapping(IO &IO, ELFYAML::SymverSection &Section) { commonSectionMapping(IO, Section); - IO.mapRequired("Entries", Section.Entries); + IO.mapOptional("Entries", Section.Entries); } static void sectionMapping(IO &IO, ELFYAML::VerneedSection &Section) { commonSectionMapping(IO, Section); IO.mapRequired("Info", Section.Info); IO.mapOptional("Dependencies", Section.VerneedV); - IO.mapOptional("Content", Section.Content); } static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) { @@ -1214,24 +1204,21 @@ static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) { commonSectionMapping(IO, Section); IO.mapOptional("Entries", Section.Entries); - IO.mapOptional("Content", Section.Content); } static void groupSectionMapping(IO &IO, ELFYAML::GroupSection &Group) { commonSectionMapping(IO, Group); IO.mapOptional("Info", Group.Signature); - IO.mapRequired("Members", Group.Members); + IO.mapOptional("Members", Group.Members); } static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) { commonSectionMapping(IO, Section); - IO.mapRequired("Entries", Section.Entries); + IO.mapOptional("Entries", Section.Entries); } static void sectionMapping(IO &IO, ELFYAML::AddrsigSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Content", Section.Content); - IO.mapOptional("Size", Section.Size); IO.mapOptional("Symbols", Section.Symbols); } @@ -1245,20 +1232,17 @@ static void sectionMapping(IO &IO, ELFYAML::LinkerOptionsSection &Section) { commonSectionMapping(IO, Section); IO.mapOptional("Options", Section.Options); - IO.mapOptional("Content", Section.Content); } static void sectionMapping(IO &IO, ELFYAML::DependentLibrariesSection &Section) { commonSectionMapping(IO, Section); IO.mapOptional("Libraries", Section.Libs); - IO.mapOptional("Content", Section.Content); } static void sectionMapping(IO &IO, ELFYAML::CallGraphProfileSection &Section) { commonSectionMapping(IO, Section); IO.mapOptional("Entries", Section.Entries); - IO.mapOptional("Content", Section.Content); } void MappingTraits::mapping( @@ -1273,8 +1257,6 @@ static void sectionMapping(IO &IO, ELFYAML::ARMIndexTableSection &Section) { commonSectionMapping(IO, Section); - IO.mapOptional("Content", Section.Content); - IO.mapOptional("Size", Section.Size); IO.mapOptional("Entries", Section.Entries); } @@ -1441,10 +1423,18 @@ StringRef MappingTraits>::validate( IO &io, std::unique_ptr &C) { + if (const auto *F = dyn_cast(C.get())) { + if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size) + return "\"Size\" can't be 0 when \"Pattern\" is not empty"; + return {}; + } + + const ELFYAML::Section &Sec = *cast(C.get()); + if (Sec.Size && Sec.Content && + (uint64_t)(*Sec.Size) < Sec.Content->binary_size()) + return "Section size must be greater than or equal to the content size"; + if (const auto *RawSection = dyn_cast(C.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"; if (RawSection->Flags && RawSection->ShFlags) return "ShFlags and Flags cannot be used together"; return {}; @@ -1454,11 +1444,6 @@ if (!SS->Entries && !SS->Content && !SS->Size) return ".stack_sizes: one of Content, Entries and Size must be specified"; - if (SS->Size && SS->Content && - (uint64_t)(*SS->Size) < SS->Content->binary_size()) - return ".stack_sizes: Size must be greater than or equal to the content " - "size"; - // We accept Content, Size or both together when there are no Entries. if (!SS->Entries) return {}; @@ -1476,11 +1461,6 @@ "specified"; if (HS->Content || HS->Size) { - if (HS->Size && HS->Content && - (uint64_t)*HS->Size < HS->Content->binary_size()) - return "\"Size\" must be greater than or equal to the content " - "size"; - if (HS->Bucket) return "\"Bucket\" cannot be used with \"Content\" or \"Size\""; if (HS->Chain) @@ -1497,19 +1477,8 @@ if (!Sec->Symbols && !Sec->Content && !Sec->Size) return "one of \"Content\", \"Size\" or \"Symbols\" must be specified"; - if (Sec->Content || Sec->Size) { - if (Sec->Size && Sec->Content && - (uint64_t)*Sec->Size < Sec->Content->binary_size()) - return "\"Size\" must be greater than or equal to the content " - "size"; - - if (Sec->Symbols) - return "\"Symbols\" cannot be used with \"Content\" or \"Size\""; - return {}; - } - - if (!Sec->Symbols) - return {}; + if ((Sec->Content || Sec->Size) && Sec->Symbols) + return "\"Symbols\" cannot be used with \"Content\" or \"Size\""; return {}; } @@ -1518,21 +1487,13 @@ return "one of \"Content\", \"Size\" or \"Notes\" must be " "specified"; - if (!NS->Content && !NS->Size) - return {}; - - if (NS->Size && NS->Content && - (uint64_t)*NS->Size < NS->Content->binary_size()) - return "\"Size\" must be greater than or equal to the content " - "size"; - - if (NS->Notes) + if ((NS->Content || NS->Size) && NS->Notes) return "\"Notes\" cannot be used with \"Content\" or \"Size\""; return {}; } if (const auto *Sec = dyn_cast(C.get())) { - if (!Sec->Content && !Sec->Header && !Sec->BloomFilter && + if (!Sec->Content && !Sec->Size && !Sec->Header && !Sec->BloomFilter && !Sec->HashBuckets && !Sec->HashValues) return "either \"Content\" or \"Header\", \"BloomFilter\", " "\"HashBuckets\" and \"HashBuckets\" must be specified"; @@ -1543,10 +1504,10 @@ !Sec->HashValues) return "\"Header\", \"BloomFilter\", " "\"HashBuckets\" and \"HashValues\" must be used together"; - if (Sec->Content) + if (Sec->Content || Sec->Size) return "\"Header\", \"BloomFilter\", " "\"HashBuckets\" and \"HashValues\" can't be used together with " - "\"Content\""; + "\"Content\" or \"Size\""; return {}; } @@ -1555,65 +1516,89 @@ } if (const auto *Sec = dyn_cast(C.get())) { - if (Sec->Options && Sec->Content) - return "\"Options\" and \"Content\" can't be used together"; + if ((Sec->Content || Sec->Size) && Sec->Options) + return "\"Options\" cannot be used with \"Content\" or \"Size\""; return {}; } if (const auto *Sec = dyn_cast(C.get())) { - if (Sec->Libs && Sec->Content) - return "SHT_LLVM_DEPENDENT_LIBRARIES: \"Libraries\" and \"Content\" " - "can't " - "be used together"; + if ((Sec->Content || Sec->Size) && Sec->Libs) + return "\"Libraries\" cannot be used with \"Content\" or \"Size\""; return {}; } - if (const auto *F = dyn_cast(C.get())) { - if (!F->Pattern) - return {}; - if (F->Pattern->binary_size() != 0 && !F->Size) - return "\"Size\" can't be 0 when \"Pattern\" is not empty"; + if (const auto *VD = dyn_cast(C.get())) { + if ((VD->Content || VD->Size) && VD->Entries) + return "\"Entries\" cannot be used with \"Content\" or \"Size\""; return {}; } - if (const auto *VD = dyn_cast(C.get())) { - if (VD->Entries && VD->Content) - return "SHT_GNU_verdef: \"Entries\" and \"Content\" can't be used " - "together"; + if (const auto *VN = dyn_cast(C.get())) { + if ((VN->Content || VN->Size) && VN->VerneedV) + return "\"Dependencies\" cannot be used with \"Content\" or \"Size\""; return {}; } - if (const auto *VD = dyn_cast(C.get())) { - if (VD->VerneedV && VD->Content) - return "SHT_GNU_verneed: \"Dependencies\" and \"Content\" can't be used " - "together"; + if (const auto *SV = dyn_cast(C.get())) { + if ((SV->Content || SV->Size) && SV->Entries) + return "\"Entries\" cannot be used with \"Content\" or \"Size\""; return {}; } if (const auto *RS = dyn_cast(C.get())) { - if (RS->Entries && RS->Content) - return "\"Entries\" and \"Content\" can't be used together"; + if ((RS->Content || RS->Size) && RS->Entries) + return "\"Entries\" cannot be used with \"Content\" or \"Size\""; return {}; } if (const auto *CGP = dyn_cast(C.get())) { - if (CGP->Entries && CGP->Content) - return "\"Entries\" and \"Content\" can't be used together"; + if ((CGP->Content || CGP->Size) && CGP->Entries) + return "\"Entries\" cannot be used with \"Content\" or \"Size\""; return {}; } if (const auto *IT = dyn_cast(C.get())) { - if (IT->Content || IT->Size) { - if (IT->Size && IT->Content && - (uint64_t)*IT->Size < IT->Content->binary_size()) - return "\"Size\" must be greater than or equal to the content " - "size"; - - if (IT->Entries) - return "\"Entries\" cannot be used with \"Content\" or \"Size\""; - return {}; - } + if ((IT->Content || IT->Size) && IT->Entries) + return "\"Entries\" cannot be used with \"Content\" or \"Size\""; + return {}; + } + + if (const auto *RS = dyn_cast(C.get())) { + if ((RS->Content || RS->Size) && RS->Relocations) + return "\"Relocations\" cannot be used with \"Content\" or \"Size\""; + return {}; + } + + if (const auto *SS = dyn_cast(C.get())) { + if ((SS->Content || SS->Size) && SS->Entries) + return "\"Entries\" cannot be used with \"Content\" or \"Size\""; + return {}; + } + + if (const auto *GS = dyn_cast(C.get())) { + if ((GS->Content || GS->Size) && GS->Members) + return "\"Members\" cannot be used with \"Content\" or \"Size\""; + return {}; + } + + if (const auto *NB = dyn_cast(C.get())) { + if (NB->Content) + return "SHT_NOBITS section cannot have \"Content\""; + return {}; + } + + if (const auto *DS = dyn_cast(C.get())) { + if ((DS->Content || DS->Size) && DS->Entries) + return "\"Entries\" cannot be used with \"Content\" or \"Size\""; + return {}; + } + if (const auto *MF = dyn_cast(C.get())) { + if (MF->Content) + return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS " + "sections"; + if (MF->Size) + return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections"; return {}; } Index: llvm/test/tools/yaml2obj/ELF/arm-exidx-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/arm-exidx-section.yaml +++ llvm/test/tools/yaml2obj/ELF/arm-exidx-section.yaml @@ -101,7 +101,7 @@ # RUN: not yaml2obj --docnum=3 -DCONTENT="'00'" -DSIZE=0 %s 2>&1 | \ # RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR -# CONTENT-SIZE-ERR: error: "Size" must be greater than or equal to the content size +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size # RUN: yaml2obj --docnum=3 -DCONTENT="'00'" -DSIZE=1 %s -o %t.cont.size.eq.o # RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ Index: llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml +++ llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml @@ -68,7 +68,7 @@ - Name: bar ## Check we can set arbitrary sh_link and sh_entsize values. -## Check we can specify neither "Content" nor "Entries" tags. +## Check we can specify none of "Content", "Entries", and "Size" tags. # RUN: yaml2obj --docnum=2 %s -o %t.link # RUN: llvm-readelf --sections %t.link | FileCheck %s --check-prefix=LINK @@ -91,23 +91,8 @@ Link: 0xFF EntSize: 0xFF -## Check we can't specify both "Content" and "Entries" tags. -# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=BOTH -# BOTH: error: "Entries" and "Content" can't be used together - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .llvm.foo - Type: SHT_LLVM_CALL_GRAPH_PROFILE - Content: "" - Entries: [] - ## Check we can refer to symbols by name. -# RUN: yaml2obj --docnum=4 %s -o %t.sym +# RUN: yaml2obj --docnum=3 %s -o %t.sym # RUN: llvm-readobj --cg-profile %t.sym | FileCheck %s --check-prefix=SYMBOL-NAMES # SYMBOL-NAMES: CGProfile [ @@ -146,7 +131,7 @@ - Name: 'foo (1)' ## Check we can describe SHT_LLVM_CALL_GRAPH_PROFILE sections using the "Content" tag. -# RUN: yaml2obj --docnum=5 %s -o %t.content +# RUN: yaml2obj --docnum=4 %s -o %t.content # RUN: llvm-readobj --sections --section-data %t.content | FileCheck %s --check-prefix=CONTENT # CONTENT: Name: .llvm.call-graph-profile @@ -165,8 +150,8 @@ Content: "11223344" ## Check we can't reference unknown symbols by name. +# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=UNKNOWN-NAME # RUN: not yaml2obj --docnum=6 %s 2>&1 | FileCheck %s --check-prefix=UNKNOWN-NAME -# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=UNKNOWN-NAME # UNKNOWN-NAME: error: unknown symbol referenced: 'bar' by YAML section '.llvm.call-graph-profile' --- !ELF @@ -202,7 +187,7 @@ - Name: foo ## Check we can specify arbitrary symbol indexes for an SHT_LLVM_CALL_GRAPH_PROFILE section entry. -# RUN: yaml2obj --docnum=8 %s -o %t.unk +# RUN: yaml2obj --docnum=7 %s -o %t.unk # RUN: llvm-readobj --sections --section-data %t.unk | FileCheck %s --check-prefix=UNKNOWN-INDEX # UNKNOWN-INDEX: Name: .llvm.call-graph-profile @@ -222,3 +207,69 @@ - From: 1 To: 2 Weight: 3 + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj --docnum=8 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .llvm.foo + Type: SHT_LLVM_CALL_GRAPH_PROFILE + Link: 0x1 + EntSize: 0x2 + Size: [[SIZE=]] + Content: [[CONTENT=]] + Entries: [[ENTRIES=]] + +# RUN: yaml2obj --docnum=8 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj --docnum=8 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .llvm.foo +# CHECK-CONTENT-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE +# CHECK-CONTENT-NEXT: Flags [ +# CHECK-CONTENT-NEXT: ] +# CHECK-CONTENT-NEXT: Address: +# CHECK-CONTENT-NEXT: Offset: +# CHECK-CONTENT-NEXT: Size: +# CHECK-CONTENT-NEXT: Link: 1 +# CHECK-CONTENT-NEXT: Info: +# CHECK-CONTENT-NEXT: AddressAlignment: +# CHECK-CONTENT-NEXT: EntrySize: 2 +# CHECK-CONTENT-NEXT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj --docnum=8 -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj --docnum=8 -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" + +## Check we can't use "Entries" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj --docnum=8 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR +# RUN: not yaml2obj --docnum=8 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR + +# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size" Index: llvm/test/tools/yaml2obj/ELF/comdat.yaml =================================================================== --- /dev/null +++ llvm/test/tools/yaml2obj/ELF/comdat.yaml @@ -0,0 +1,77 @@ +## Check how "Content", "Size" and "Members" keys can be used to +## describe a content for group sections. + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .group + Type: SHT_GROUP + Link: 0x1 + Info: 0x2 + Size: [[SIZE=]] + Content: [[CONTENT=]] + Members: [[MEMBERS=]] + +# RUN: yaml2obj -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .group +# CHECK-CONTENT-NEXT: Type: SHT_GROUP +# CHECK-CONTENT-NEXT: Flags [ +# CHECK-CONTENT-NEXT: ] +# CHECK-CONTENT-NEXT: Address: +# CHECK-CONTENT-NEXT: Offset: +# CHECK-CONTENT-NEXT: Size: +# CHECK-CONTENT-NEXT: Link: 1 +# CHECK-CONTENT-NEXT: Info: 2 +# CHECK-CONTENT-NEXT: AddressAlignment: +# CHECK-CONTENT-NEXT: EntrySize: 4 +# CHECK-CONTENT-NEXT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" + +## Check we can't use "Members" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj -DSIZE=0 -DMEMBERS="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=MEMBERS-ERR +# RUN: not yaml2obj -DCONTENT="'00'" -DMEMBERS="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=MEMBERS-ERR + +# MEMBERS-ERR: error: "Members" cannot be used with "Content" or "Size" + +## Check we create an empty section when neither "Size", "Content" nor "Members" are specified. + +# RUN: yaml2obj %s -o %t.empty.o +# RUN: llvm-readelf --sections --section-data %t.empty.o | \ +# RUN: FileCheck %s --check-prefix=EMPTY-SEC + +# EMPTY-SEC: [Nr] Name Type Address Off Size +# EMPTY-SEC: [ 1] .group GROUP 0000000000000000 000040 000000 Index: llvm/test/tools/yaml2obj/ELF/dynamic-section-raw-content.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/dynamic-section-raw-content.yaml +++ llvm/test/tools/yaml2obj/ELF/dynamic-section-raw-content.yaml @@ -1,19 +1,18 @@ -## Show that yaml2obj can handle a dynamic section with raw content instead of -## entries. Also show that it rejects raw content when entries are also provided. +## Check how "Content", "Size" and "Entries" keys can be used to +## describe a content for relocations sections. -# RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-readobj -x .dynamic --sections %t1 | FileCheck %s --check-prefix=RAW +## Check we can use the "Content" key alone. -# RAW: Name: .dynamic -# RAW-NEXT: Type: SHT_DYNAMIC -# RAW-NEXT: Flags [ -# RAW-NEXT: ] -# RAW-NEXT: Address: -# RAW-NEXT: Offset: -# RAW-NEXT: Size: 16 +# RUN: yaml2obj -DCONTENT="01234567" %s -o %t1.content +# RUN: llvm-readobj --sections --section-data %t1.content | \ +# RUN: FileCheck %s --check-prefix=RAW -DDATA="01234567" -# RAW: Hex dump of section '.dynamic': -# RAW-NEXT: 0x00000000 01234567 89012345 67890000 00000000 {{.*}} +# RAW: Name: .dynamic +# RAW: EntrySize: +# RAW-SAME: 255{{$}} +# RAW: SectionData ( +# RAW-NEXT: 0000: [[DATA]] | +# RAW-NEXT: ) --- !ELF FileHeader: @@ -21,30 +20,49 @@ Data: ELFDATA2LSB Type: ET_EXEC Sections: - - Name: .dynamic - Type: SHT_DYNAMIC - Content: "01234567890123456789000000000000" + - Name: .dynamic + Type: SHT_DYNAMIC + EntSize: 0xff + Content: [[CONTENT=]] + Size: [[SIZE=]] + Entries: [[ENTRIES=]] -# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=ERR +## Check we can use the "Size" key alone. -# ERR: cannot specify both raw content and explicit entries for dynamic section '.dynamic1' -# ERR: cannot specify both raw content and explicit entries for dynamic section '.dynamic2' +# RUN: yaml2obj -DSIZE=3 %s -o %t1.size +# RUN: llvm-readobj --sections --section-data %t1.size | \ +# RUN: FileCheck %s --check-prefix=RAW -DDATA="000000" ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC -Sections: - - Name: .dynamic1 - Type: SHT_DYNAMIC - Content: "0123456789" - Entries: - - Tag: DT_STRSZ - Value: 0 - - Name: .dynamic2 - Type: SHT_DYNAMIC - Content: "0123456789" - Entries: - - Tag: DT_STRSZ - Value: 0 +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +# RUN: yaml2obj -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=RAW -DDATA="0011" + +# RUN: yaml2obj -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=RAW -DDATA="001100" + +## Check we can't use "Entries" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENT-ERR +# RUN: not yaml2obj -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENT-ERR + +# ENT-ERR: error: "Entries" cannot be used with "Content" or "Size" + +## Check we create an empty section when neither "Size", "Content" nor "Entries" are specified. + +# RUN: yaml2obj %s -o %t.empty.o +# RUN: llvm-readelf --sections --section-data %t.empty.o | \ +# RUN: FileCheck %s --check-prefix=EMPTY-SEC + +# EMPTY-SEC: [Nr] Name Type Address Off Size +# EMPTY-SEC: [ 1] .dynamic DYNAMIC 0000000000000000 000040 000000 Index: llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml +++ llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml @@ -224,11 +224,11 @@ - Name: .gnu.hash Type: SHT_GNU_HASH -## Test that "Header", "BloomFilter", "HashBuckets" and "HashValues" can't be used together with "Content". +## Test that "Header", "BloomFilter", "HashBuckets" and "HashValues" can't be used together with "Content" or "Size" -# RUN: not yaml2obj --docnum=11 %s -o %t11 2>&1 | FileCheck %s --check-prefix=TOGETHER - -# TOGETHER: error: "Header", "BloomFilter", "HashBuckets" and "HashValues" can't be used together with "Content" +# RUN: not yaml2obj --docnum=11 -DCONTENT="" %s 2>&1 | FileCheck %s --check-prefix=TOGETHER +# RUN: not yaml2obj --docnum=11 -DSIZE=0 %s 2>&1 | FileCheck %s --check-prefix=TOGETHER +# TOGETHER: error: "Header", "BloomFilter", "HashBuckets" and "HashValues" can't be used together with "Content" or "Size" --- !ELF FileHeader: @@ -236,9 +236,10 @@ Data: ELFDATA2LSB Type: ET_DYN Sections: - - Name: .gnu.hash - Type: SHT_GNU_HASH - Content: "" + - Name: .gnu.hash + Type: SHT_GNU_HASH + Content: [[CONTENT=]] + Size: [[SIZE=]] Header: SymNdx: 0x0 Shift2: 0x0 @@ -273,3 +274,47 @@ BloomFilter: [] HashBuckets: [] HashValues: [] + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj --docnum=13 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .gnu.hash + Type: SHT_GNU_HASH + Size: [[SIZE=]] + Content: [[CONTENT=]] + +# RUN: yaml2obj --docnum=13 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj --docnum=13 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .gnu.hash +# CHECK-CONTENT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj --docnum=13 -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj --docnum=13 -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" Index: llvm/test/tools/yaml2obj/ELF/hash-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/hash-section.yaml +++ llvm/test/tools/yaml2obj/ELF/hash-section.yaml @@ -230,7 +230,7 @@ # RUN: not yaml2obj --docnum=11 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR -# SIZE-CONTENT-ERR: error: "Size" must be greater than or equal to the content size +# SIZE-CONTENT-ERR: error: Section size must be greater than or equal to the content size --- !ELF FileHeader: Index: llvm/test/tools/yaml2obj/ELF/linker-options.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/linker-options.yaml +++ llvm/test/tools/yaml2obj/ELF/linker-options.yaml @@ -1,7 +1,7 @@ ## Check we are able to produce a valid SHT_LLVM_LINKER_OPTIONS ## section from its description. -## Check we can use either "Options" or "Content" to describe the data. +## Check we can use "Options", "Size" and "Content" alone to describe the data. # RUN: yaml2obj --docnum=1 %s -o %t1 # RUN: llvm-readobj --string-dump .linker-options1 --sections --section-data %t1 \ @@ -25,6 +25,12 @@ # OPTIONS-NEXT: 0000: 00112233 | # OPTIONS-NEXT: ) +# OPTIONS: Name: .linker-options3 +# OPTIONS-NEXT: Type: SHT_LLVM_LINKER_OPTIONS +# OPTIONS: SectionData ( +# OPTIONS-NEXT: 0000: 00000000 | +# OPTIONS-NEXT: ) + # OPTIONS: String dump of section '.linker-options1': # OPTIONS-NEXT: [ 0] option 0 # OPTIONS-NEXT: [ 9] value 0 @@ -47,6 +53,9 @@ - Name: .linker-options2 Type: SHT_LLVM_LINKER_OPTIONS Content: "00112233" + - Name: .linker-options3 + Type: SHT_LLVM_LINKER_OPTIONS + Size: 4 ## Check that "Value" and "Name" fields are mandatory when using "Options" key. @@ -78,11 +87,15 @@ Options: - Value: value -## Check we can't use both "Options" and "Content" together. +## Check we can't use "Options" or "Size" keys together with the "Content" key. + +# RUN: not yaml2obj %s -DOPTIONS="[]" -DCONTENT="''" --docnum=4 2>&1 | \ +# RUN: FileCheck %s --check-prefix=TOGETHER -# RUN: not yaml2obj %s --docnum=4 2>&1 | FileCheck %s --check-prefix=BOTH +# RUN: not yaml2obj %s -DOPTIONS="[]" -DSIZE="0" --docnum=4 2>&1 | \ +# RUN: FileCheck %s --check-prefix=TOGETHER -# BOTH: error: "Options" and "Content" can't be used together +# TOGETHER: error: "Options" cannot be used with "Content" or "Size" --- !ELF FileHeader: @@ -90,26 +103,37 @@ Data: ELFDATA2LSB Type: ET_REL Sections: - - Name: .linker-options - Type: SHT_LLVM_LINKER_OPTIONS - Options: - - Name: name - Value: value - Content: "00112233" + - Name: .linker-options + Type: SHT_LLVM_LINKER_OPTIONS + Options: [[OPTIONS=]] + Content: [[CONTENT=]] + Size: [[SIZE=]] -## Check we can omit both "Options" and "Content". This produces an empty section. +## Check we can omit "Options", "Content" and "Size" keys. This produces an empty section. -# RUN: yaml2obj %s --docnum=5 2>&1 -o %t5 +# RUN: yaml2obj %s --docnum=4 2>&1 -o %t5 # RUN: llvm-readelf --sections %t5 | FileCheck %s --check-prefix=NONE # NONE: [Nr] Name Type Address Off Size # NONE: [ 1] .linker-options LLVM_LINKER_OPTIONS 0000000000000000 000040 000000 ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL -Sections: - - Name: .linker-options - Type: SHT_LLVM_LINKER_OPTIONS +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj --docnum=4 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +# RUN: yaml2obj --docnum=4 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# CHECK-CONTENT: Name: .linker-options (1) +# CHECK-CONTENT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +# RUN: yaml2obj --docnum=4 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" Index: llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml +++ llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml @@ -232,7 +232,7 @@ # RUN: not yaml2obj --docnum=11 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR -# SIZE-CONTENT-ERR: error: "Size" must be greater than or equal to the content size +# SIZE-CONTENT-ERR: error: Section size must be greater than or equal to the content size --- !ELF FileHeader: Index: llvm/test/tools/yaml2obj/ELF/llvm-deplibs-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/llvm-deplibs-section.yaml +++ llvm/test/tools/yaml2obj/ELF/llvm-deplibs-section.yaml @@ -1,7 +1,7 @@ ## Check how yaml2obj produces SHT_LLVM_DEPENDENT_LIBRARIES sections. ## Check we can describe SHT_LLVM_DEPENDENT_LIBRARIES using -## "Libraries" and "Content" properies. +## "Libraries", "Size" and "Content" properies. # RUN: yaml2obj --docnum=1 %s -o %t1 # RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=LIBRARIES @@ -36,6 +36,21 @@ # LIBRARIES-NEXT: 0000: 112233 # LIBRARIES-NEXT: ) +# LIBRARIES: Name: .deplibs.size +# LIBRARIES-NEXT: Type: SHT_LLVM_DEPENDENT_LIBRARIES +# LIBRARIES-NEXT: Flags [ (0x0) +# LIBRARIES-NEXT: ] +# LIBRARIES-NEXT: Address: 0x0 +# LIBRARIES-NEXT: Offset: 0x4F +# LIBRARIES-NEXT: Size: 3 +# LIBRARIES-NEXT: Link: 0 +# LIBRARIES-NEXT: Info: 0 +# LIBRARIES-NEXT: AddressAlignment: 0 +# LIBRARIES-NEXT: EntrySize: 0 +# LIBRARIES-NEXT: SectionData ( +# LIBRARIES-NEXT: 0000: 000000 | +# LIBRARIES-NEXT: ) + --- !ELF FileHeader: Class: ELFCLASS64 @@ -48,12 +63,16 @@ - Name: .deplibs.content Type: SHT_LLVM_DEPENDENT_LIBRARIES Content: "112233" + - Name: .deplibs.size + Type: SHT_LLVM_DEPENDENT_LIBRARIES + Size: 0x3 -## Check we report an error when "Libraries" and "Content" are used together. +## Check we report an error when "Libraries" and "Content"/"Size" keys are used together. -# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=LIBS-CONTENT +# RUN: not yaml2obj --docnum=2 -DCONTENT="FF" -DLIBS="[]" %s 2>&1 | FileCheck %s --check-prefix=LIBS-ERR +# RUN: not yaml2obj --docnum=2 -DSIZE=0 -DLIBS="[]" %s 2>&1 | FileCheck %s --check-prefix=LIBS-ERR -# LIBS-CONTENT: error: SHT_LLVM_DEPENDENT_LIBRARIES: "Libraries" and "Content" can't be used together +# LIBS-ERR: error: "Libraries" cannot be used with "Content" or "Size" --- !ELF FileHeader: @@ -63,22 +82,35 @@ Sections: - Name: .deplibs Type: SHT_LLVM_DEPENDENT_LIBRARIES - Content: "FF" - Libraries: [ foo ] + Content: [[CONTENT=]] + Size: [[SIZE=]] + Libraries: [[LIBS=]] -## Check we create an empty section when neither "Libraries" nor "Content" are specified. +## Check we create an empty section when neither "Libraries", "Size" nor "Content" are specified. -# RUN: yaml2obj --docnum=3 %s -o %t3 -# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=NOPROPS +# RUN: yaml2obj --docnum=2 %s -o %t2.empty +# RUN: llvm-readelf --sections %t2.empty | FileCheck %s --check-prefix=EMPTY -# NOPROPS: [Nr] Name Type Address Off Size -# NOPROPS: [ 1] .deplibs LLVM_DEPENDENT_LIBRARIES 0000000000000000 000040 000000 - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL -Sections: - - Name: .deplibs - Type: SHT_LLVM_DEPENDENT_LIBRARIES +# EMPTY: [Nr] Name Type Address Off Size +# EMPTY: [ 1] .deplibs LLVM_DEPENDENT_LIBRARIES 0000000000000000 000040 000000 + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj --docnum=2 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +# RUN: yaml2obj --docnum=2 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj --docnum=2 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .deplibs +# CHECK-CONTENT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) Index: llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml +++ llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml @@ -43,6 +43,8 @@ CPR2Size: REG_NONE Flags1: [ ODDSPREG ] Flags2: 0x0 + Content: [[CONTENT=]] + Size: [[SIZE=]] ## Check we don't recognize the SHT_MIPS_ABIFLAGS section for non-MIPS targets. @@ -50,3 +52,15 @@ # ERR: error: invalid hex32 number # ERR-NEXT: Type: SHT_MIPS_ABIFLAGS + +## Document we don't support the "Content" key yet. + +# RUN: not yaml2obj %s -DCONTENT="'00'" 2>&1 | FileCheck %s --check-prefix=ERR-CONTENT + +# ERR-CONTENT: error: "Content" key is not implemented for SHT_MIPS_ABIFLAGS section + +## Document we don't support the "Size" key yet. + +# RUN: not yaml2obj %s -DSIZE=0 2>&1 | FileCheck %s --check-prefix=ERR-SIZE + +# ERR-SIZE: error: "Size" key is not implemented for SHT_MIPS_ABIFLAGS section Index: llvm/test/tools/yaml2obj/ELF/nobits.yaml =================================================================== --- /dev/null +++ llvm/test/tools/yaml2obj/ELF/nobits.yaml @@ -0,0 +1,37 @@ +## Check how SHT_NOBITS sections are created. + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readelf --sections --section-data %t.size.o | FileCheck %s + +# CHECK: [Nr] Name Type Address Off Size ES Flg Lk Inf Al +# CHECK: [ 1] .nobits NOBITS 0000000000000000 000040 000003 00 0 0 0 +# CHECK-NEXT: [ 2] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .nobits + Type: SHT_NOBITS + Size: [[SIZE=]] + Content: [[CONTENT=]] + +## Check we can't use the "Content" key. + +# RUN: not yaml2obj -DCONTENT="'112233'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-ERR + +# CONTENT-ERR: error: SHT_NOBITS section cannot have "Content" + +## Check we create an empty section when neither "Size" nor "Content" are specified. + +# RUN: yaml2obj %s -o %t.empty.o +# RUN: llvm-readelf --sections --section-data %t.empty.o | \ +# RUN: FileCheck %s --check-prefix=EMPTY-SEC + +# EMPTY-SEC: [Nr] Name Type Address Off Size +# EMPTY-SEC: [ 1] .nobits NOBITS 0000000000000000 000040 000000 Index: llvm/test/tools/yaml2obj/ELF/note-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/note-section.yaml +++ llvm/test/tools/yaml2obj/ELF/note-section.yaml @@ -274,7 +274,7 @@ ## must be greater than or equal to the content size. # RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR -# SIZE-CONTENT-ERR: error: "Size" must be greater than or equal to the content size +# SIZE-CONTENT-ERR: error: Section size must be greater than or equal to the content size --- !ELF FileHeader: Index: llvm/test/tools/yaml2obj/ELF/reloc-sec.yaml =================================================================== --- /dev/null +++ llvm/test/tools/yaml2obj/ELF/reloc-sec.yaml @@ -0,0 +1,78 @@ +## Check how "Content", "Size" and "Entries" keys can be used to +## describe a content for relocations sections. + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .rela + Type: SHT_RELA + Link: 0x1 + Info: 0x2 + EntSize: 0x3 + Size: [[SIZE=]] + Content: [[CONTENT=]] + Relocations: [[RELS=]] + +# RUN: yaml2obj -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .rela +# CHECK-CONTENT-NEXT: Type: SHT_RELA +# CHECK-CONTENT-NEXT: Flags [ +# CHECK-CONTENT-NEXT: ] +# CHECK-CONTENT-NEXT: Address: +# CHECK-CONTENT-NEXT: Offset: +# CHECK-CONTENT-NEXT: Size: +# CHECK-CONTENT-NEXT: Link: 1 +# CHECK-CONTENT-NEXT: Info: 2 +# CHECK-CONTENT-NEXT: AddressAlignment: +# CHECK-CONTENT-NEXT: EntrySize: 3 +# CHECK-CONTENT-NEXT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" + +## Check we can't use "Relocations" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj -DSIZE=0 -DRELS="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=REL-ERR +# RUN: not yaml2obj -DCONTENT="'00'" -DRELS="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=REL-ERR + +# REL-ERR: error: "Relocations" cannot be used with "Content" or "Size" + +## Check we create an empty section when neither "Size", "Content" nor "Relocations" are specified. + +# RUN: yaml2obj %s -o %t.empty.o +# RUN: llvm-readelf --sections --section-data %t.empty.o | \ +# RUN: FileCheck %s --check-prefix=EMPTY-SEC + +# EMPTY-SEC: [Nr] Name Type Address Off Size +# EMPTY-SEC: [ 1] .rela RELA 0000000000000000 000040 000000 Index: llvm/test/tools/yaml2obj/ELF/relr-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/relr-section.yaml +++ llvm/test/tools/yaml2obj/ELF/relr-section.yaml @@ -1,172 +1,211 @@ -## Test how we create SHT_RELR sections. - -## Test that the content of SHT_RELR sections for 64-bit little endian targets is correct. -# RUN: yaml2obj --docnum=1 -D ENCODE=LSB %s -o %t.le64 -# RUN: llvm-readobj --sections --section-data %t.le64 | FileCheck %s --check-prefix=LE64 - -# LE64: Name: .relr.dyn -# LE64-NEXT: Type: SHT_RELR -# LE64-NEXT: Flags [ -# LE64-NEXT: SHF_ALLOC -# LE64-NEXT: ] -# LE64-NEXT: Address: 0x0 -# LE64-NEXT: Offset: 0x40 -# LE64-NEXT: Size: 32 -# LE64-NEXT: Link: 0 -# LE64-NEXT: Info: 0 -# LE64-NEXT: AddressAlignment: 0 -# LE64-NEXT: EntrySize: 8 -# LE64-NEXT: SectionData ( -# LE64-NEXT: 0000: DDCCBBAA 00000000 2211FFEE 00000000 -# LE64-NEXT: 0010: 66554433 00000010 AA998877 00000010 -# LE64-NEXT: ) - -## Test that the content of SHT_RELR sections for 64-bit big endian targets is correct. -# RUN: yaml2obj --docnum=1 -D ENCODE=MSB %s -o %t.be64 -# RUN: llvm-readobj --sections --section-data %t.be64 | FileCheck %s --check-prefix=BE64 - -# BE64: Name: .relr.dyn -# BE64: SectionData ( -# BE64-NEXT: 0000: 00000000 AABBCCDD 00000000 EEFF1122 -# BE64-NEXT: 0010: 10000000 33445566 10000000 778899AA -# BE64-NEXT: ) - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2[[ENCODE]] - Type: ET_DYN -Sections: - - Name: .relr.dyn - Type: SHT_RELR -## Set an arbitrary flag to demonstrate flags are set when requested. - Flags: [ SHF_ALLOC ] - Entries: [ 0x00000000AABBCCDD, 0x00000000EEFF1122, - 0x1000000033445566, 0x10000000778899AA ] - -## Test that the content of SHT_RELR sections for 32-bit little endian targets is correct. -# RUN: yaml2obj --docnum=2 -D ENCODE=LSB %s -o %t.le32 -# RUN: llvm-readobj --sections --section-data %t.le32 | FileCheck %s --check-prefix=LE32 - -# LE32: Name: .relr.dyn -# LE32-NEXT: Type: SHT_RELR -# LE32-NEXT: Flags [ -# LE32-NEXT: SHF_ALLOC -# LE32-NEXT: ] -# LE32-NEXT: Address: 0x0 -# LE32-NEXT: Offset: 0x34 -# LE32-NEXT: Size: 16 -# LE32-NEXT: Link: 0 -# LE32-NEXT: Info: 0 -# LE32-NEXT: AddressAlignment: 0 -# LE32-NEXT: EntrySize: 4 -# LE32-NEXT: SectionData ( -# LE32-NEXT: 0000: DDCCBBAA BBAAFFEE BBAAFFEE BCAAFFEE -# LE32-NEXT: ) - -## Test that the content of SHT_RELR sections for 32-bit big endian targets is correct. -# RUN: yaml2obj --docnum=2 -D ENCODE=MSB %s -o %t.be32 -# RUN: llvm-readobj --sections --section-data %t.be32 | FileCheck %s --check-prefix=BE32 - -# BE32: Name: .relr.dyn -# BE32: SectionData ( -# BE32-NEXT: 0000: AABBCCDD EEFFAABB EEFFAABB EEFFAABC | -# BE32-NEXT: ) - ---- !ELF -FileHeader: - Class: ELFCLASS32 - Data: ELFDATA2[[ENCODE]] - Type: ET_DYN -Sections: - - Name: .relr.dyn - Type: SHT_RELR -## Set an arbitrary flag to demonstrate flags are set when requested. - Flags: [ SHF_ALLOC ] - Entries: [ 0xAABBCCDD, 0xEEFFAABB, - 0xEEFFAABB, 0xEEFFAABC ] - -## Test we can use "Content" to describe SHT_RELR section. -# RUN: yaml2obj --docnum=3 %s -o %t.content -# RUN: llvm-readobj --sections --section-data %t.content | FileCheck %s --check-prefix=CONTENT - -# CONTENT: Name: .relr.dyn -# CONTENT: SectionData ( -# CONTENT-NEXT: 0000: 112233 | -# CONTENT-NEXT: ) - ---- !ELF -FileHeader: - Class: ELFCLASS32 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .relr.dyn - Type: SHT_RELR - Content: "112233" - -## Check we are able to set an arbitrary sh_entsize. -# RUN: yaml2obj --docnum=4 %s -o %t.entsize -# RUN: llvm-readelf --sections %t.entsize | FileCheck %s --check-prefix=ENTSIZE - -# ENTSIZE: [Nr] Name Type Address Off Size ES -# ENTSIZE: [ 1] .relr.dyn RELR 00000000 000034 000001 34 - ---- !ELF -FileHeader: - Class: ELFCLASS32 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .relr.dyn - Type: SHT_RELR - EntSize: 0x34 - Content: "12" - -## Test we can't use 64-bit offsets/bitmaps when creating a 32-bit object. -# RUN: yaml2obj --docnum=5 %s -o %t.nottoolarge -# RUN: llvm-readobj --sections --section-data %t.nottoolarge | FileCheck %s --check-prefix=NOT-TOO-LARGE - -# NOT-TOO-LARGE: Name: .relr.dyn -# NOT-TOO-LARGE: SectionData ( -# NOT-TOO-LARGE-NEXT: 0000: FFFFFFFF -# NOT-TOO-LARGE-NEXT: ) - -# RUN: not yaml2obj --docnum=6 %s 2>&1 | FileCheck %s --check-prefix=TOO-LARGE -# TOO-LARGE: error: .relr.dyn: the value is too large for 32-bits: 0x100000000 - ---- !ELF -FileHeader: - Class: ELFCLASS32 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .relr.dyn - Type: SHT_RELR - Entries: [ 0x00000000FFFFFFFF ] - ---- !ELF -FileHeader: - Class: ELFCLASS32 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .relr.dyn - Type: SHT_RELR - Entries: [ 0x0000000100000000 ] - -## Test we can't specify "Entries" and "Content" properties at the same time. -# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=BOTH - -# BOTH: error: "Entries" and "Content" can't be used together - ---- !ELF -FileHeader: - Class: ELFCLASS32 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .relr.dyn - Type: SHT_RELR - Entries: [ 0x0 ] - Content: "00" +## Test how we create SHT_RELR sections. + +## Test that the content of SHT_RELR sections for 64-bit little endian targets is correct. +# RUN: yaml2obj --docnum=1 -D ENCODE=LSB %s -o %t.le64 +# RUN: llvm-readobj --sections --section-data %t.le64 | FileCheck %s --check-prefix=LE64 + +# LE64: Name: .relr.dyn +# LE64-NEXT: Type: SHT_RELR +# LE64-NEXT: Flags [ +# LE64-NEXT: SHF_ALLOC +# LE64-NEXT: ] +# LE64-NEXT: Address: 0x0 +# LE64-NEXT: Offset: 0x40 +# LE64-NEXT: Size: 32 +# LE64-NEXT: Link: 0 +# LE64-NEXT: Info: 0 +# LE64-NEXT: AddressAlignment: 0 +# LE64-NEXT: EntrySize: 8 +# LE64-NEXT: SectionData ( +# LE64-NEXT: 0000: DDCCBBAA 00000000 2211FFEE 00000000 +# LE64-NEXT: 0010: 66554433 00000010 AA998877 00000010 +# LE64-NEXT: ) + +## Test that the content of SHT_RELR sections for 64-bit big endian targets is correct. +# RUN: yaml2obj --docnum=1 -D ENCODE=MSB %s -o %t.be64 +# RUN: llvm-readobj --sections --section-data %t.be64 | FileCheck %s --check-prefix=BE64 + +# BE64: Name: .relr.dyn +# BE64: SectionData ( +# BE64-NEXT: 0000: 00000000 AABBCCDD 00000000 EEFF1122 +# BE64-NEXT: 0010: 10000000 33445566 10000000 778899AA +# BE64-NEXT: ) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2[[ENCODE]] + Type: ET_DYN +Sections: + - Name: .relr.dyn + Type: SHT_RELR +## Set an arbitrary flag to demonstrate flags are set when requested. + Flags: [ SHF_ALLOC ] + Entries: [ 0x00000000AABBCCDD, 0x00000000EEFF1122, + 0x1000000033445566, 0x10000000778899AA ] + +## Test that the content of SHT_RELR sections for 32-bit little endian targets is correct. +# RUN: yaml2obj --docnum=2 -D ENCODE=LSB %s -o %t.le32 +# RUN: llvm-readobj --sections --section-data %t.le32 | FileCheck %s --check-prefix=LE32 + +# LE32: Name: .relr.dyn +# LE32-NEXT: Type: SHT_RELR +# LE32-NEXT: Flags [ +# LE32-NEXT: SHF_ALLOC +# LE32-NEXT: ] +# LE32-NEXT: Address: 0x0 +# LE32-NEXT: Offset: 0x34 +# LE32-NEXT: Size: 16 +# LE32-NEXT: Link: 0 +# LE32-NEXT: Info: 0 +# LE32-NEXT: AddressAlignment: 0 +# LE32-NEXT: EntrySize: 4 +# LE32-NEXT: SectionData ( +# LE32-NEXT: 0000: DDCCBBAA BBAAFFEE BBAAFFEE BCAAFFEE +# LE32-NEXT: ) + +## Test that the content of SHT_RELR sections for 32-bit big endian targets is correct. +# RUN: yaml2obj --docnum=2 -D ENCODE=MSB %s -o %t.be32 +# RUN: llvm-readobj --sections --section-data %t.be32 | FileCheck %s --check-prefix=BE32 + +# BE32: Name: .relr.dyn +# BE32: SectionData ( +# BE32-NEXT: 0000: AABBCCDD EEFFAABB EEFFAABB EEFFAABC | +# BE32-NEXT: ) + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2[[ENCODE]] + Type: ET_DYN +Sections: + - Name: .relr.dyn + Type: SHT_RELR +## Set an arbitrary flag to demonstrate flags are set when requested. + Flags: [ SHF_ALLOC ] + Entries: [ 0xAABBCCDD, 0xEEFFAABB, + 0xEEFFAABB, 0xEEFFAABC ] + +## Check we are able to set an arbitrary sh_entsize. +# RUN: yaml2obj --docnum=3 %s -o %t.entsize +# RUN: llvm-readelf --sections %t.entsize | FileCheck %s --check-prefix=ENTSIZE + +# ENTSIZE: [Nr] Name Type Address Off Size ES +# ENTSIZE: [ 1] .relr.dyn RELR 00000000 000034 000001 34 + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .relr.dyn + Type: SHT_RELR + EntSize: 0x34 + Content: "12" + +## Test we can't use 64-bit offsets/bitmaps when creating a 32-bit object. +# RUN: yaml2obj --docnum=4 %s -o %t.nottoolarge +# RUN: llvm-readobj --sections --section-data %t.nottoolarge | FileCheck %s --check-prefix=NOT-TOO-LARGE + +# NOT-TOO-LARGE: Name: .relr.dyn +# NOT-TOO-LARGE: SectionData ( +# NOT-TOO-LARGE-NEXT: 0000: FFFFFFFF +# NOT-TOO-LARGE-NEXT: ) + +# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=TOO-LARGE +# TOO-LARGE: error: .relr.dyn: the value is too large for 32-bits: 0x100000000 + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .relr.dyn + Type: SHT_RELR + Entries: [ 0x00000000FFFFFFFF ] + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .relr.dyn + Type: SHT_RELR + Entries: [ 0x0000000100000000 ] + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj --docnum=6 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .relr.dyn + Type: SHT_RELR + EntSize: 0xff + Size: [[SIZE=]] + Content: [[CONTENT=]] + Entries: [[ENTRIES=]] + +# RUN: yaml2obj --docnum=6 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj --docnum=6 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .relr.dyn +# CHECK-CONTENT-NEXT: Type: SHT_RELR +# CHECK-CONTENT-NEXT: Flags [ +# CHECK-CONTENT-NEXT: ] +# CHECK-CONTENT-NEXT: Address: +# CHECK-CONTENT-NEXT: Offset: +# CHECK-CONTENT-NEXT: Size: +# CHECK-CONTENT-NEXT: Link: +# CHECK-CONTENT-NEXT: Info: +# CHECK-CONTENT-NEXT: AddressAlignment: +# CHECK-CONTENT-NEXT: EntrySize: 255 +# CHECK-CONTENT-NEXT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj --docnum=6 -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj --docnum=6 -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" + +## Check we can't use "Entries" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj --docnum=6 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR +# RUN: not yaml2obj --docnum=6 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR + +# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size" + +## Check we create an empty section when neither "Size", "Content" nor "Entries" are specified. + +# RUN: yaml2obj %s --docnum=6 -o %t.empty.o +# RUN: llvm-readelf --sections --section-data %t.empty.o | \ +# RUN: FileCheck %s --check-prefix=EMPTY-SEC + +# EMPTY-SEC: [Nr] Name Type Address Off Size +# EMPTY-SEC: [ 1] .relr.dyn RELR 0000000000000000 000040 000000 Index: llvm/test/tools/yaml2obj/ELF/sht-symtab-shndx.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/sht-symtab-shndx.yaml +++ llvm/test/tools/yaml2obj/ELF/sht-symtab-shndx.yaml @@ -121,3 +121,70 @@ Type: SHT_SYMTAB_SHNDX Entries: [ 0 ] EntSize: 2 + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj --docnum=6 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .symtab_shndx + Type: SHT_SYMTAB_SHNDX + Link: .symtab + Size: [[SIZE=]] + Content: [[CONTENT=]] + Entries: [[ENTRIES=]] + - Name: .symtab + Type: SHT_SYMTAB + Size: [[SYMTAB=0x24]] + +# RUN: yaml2obj --docnum=6 -DSIZE=4 -DCONTENT="'00112233'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="00112233" + +# RUN: yaml2obj --docnum=6 -DSIZE=8 -DSYMTAB=0x36 -DCONTENT="'00112233'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="00112233 00000000" + +# CHECK-CONTENT: Name: .symtab_shndx +# CHECK-CONTENT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj --docnum=6 -DSIZE=4 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="00000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj --docnum=6 -DCONTENT="'11223344'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="11223344" + +## Check we can't use "Entries" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj --docnum=6 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR +# RUN: not yaml2obj --docnum=6 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR + +# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size" + +## Check we create an empty section when neither "Size", "Entries" nor "Content" are specified. + +# RUN: yaml2obj --docnum=6 -DSYMTAB=0x12 %s -o %t.empty +# RUN: llvm-readelf --sections --section-data %t.empty | \ +# RUN: FileCheck %s --check-prefix=EMPTY + +# EMPTY: [Nr] Name Type Address Off Size +# EMPTY: [ 1] .symtab_shndx SYMTAB SECTION INDICES 0000000000000000 000040 000000 Index: llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml +++ llvm/test/tools/yaml2obj/ELF/stack-sizes.yaml @@ -244,7 +244,7 @@ # RUN: not yaml2obj --docnum=10 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR -# SIZE-CONTENT-ERR: error: .stack_sizes: Size must be greater than or equal to the content size +# SIZE-CONTENT-ERR: error: Section size must be greater than or equal to the content size --- !ELF FileHeader: Index: llvm/test/tools/yaml2obj/ELF/verdef-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/verdef-section.yaml +++ llvm/test/tools/yaml2obj/ELF/verdef-section.yaml @@ -127,11 +127,13 @@ Flags: [ SHF_ALLOC ] Info: 0x0000000000000001 -## Check we can't use both "Entries" and "Content" together. +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. -# RUN: not yaml2obj --docnum=4 %s -o %t4 2>&1 | FileCheck %s --check-prefix=BOTH +# RUN: not yaml2obj --docnum=4 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR -# BOTH: error: SHT_GNU_verdef: "Entries" and "Content" can't be used together +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size --- !ELF FileHeader: @@ -141,13 +143,41 @@ Sections: - Name: .gnu.version_d Type: SHT_GNU_verdef - Flags: [ SHF_ALLOC ] - Info: 0x0000000000000001 - Content: "112233" - Entries: - - Version: 0 - Flags: 0 - VersionNdx: 0 - Hash: 0 - Names: - - foo + Info: 0x1 + Size: [[SIZE=]] + Content: [[CONTENT=]] + Entries: [[ENTRIES=]] + +# RUN: yaml2obj --docnum=4 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj --docnum=4 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .gnu.version_d +# CHECK-CONTENT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj --docnum=4 -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj --docnum=4 -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" + +## Check we can't use "Entries" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj --docnum=4 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR +# RUN: not yaml2obj --docnum=4 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR + +# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size" Index: llvm/test/tools/yaml2obj/ELF/verneed-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/verneed-section.yaml +++ llvm/test/tools/yaml2obj/ELF/verneed-section.yaml @@ -82,42 +82,10 @@ - Name: f1 Binding: STB_GLOBAL -## Check we can use "Content" to describe the content. - -# RUN: yaml2obj --docnum=2 %s -o %t2 -# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=CONTENT - -# CONTENT: Name: .gnu.version_r -# CONTENT-NEXT: Type: SHT_GNU_verneed -# CONTENT-NEXT: Flags [ (0x2) -# CONTENT-NEXT: SHF_ALLOC (0x2) -# CONTENT-NEXT: ] -# CONTENT-NEXT: Address: 0x0 -# CONTENT-NEXT: Offset: 0x40 -# CONTENT-NEXT: Size: 3 -# CONTENT-NEXT: Link: 0 -# CONTENT-NEXT: Info: 1 -# CONTENT-NEXT: AddressAlignment: 0 -# CONTENT-NEXT: EntrySize: 0 -# CONTENT-NEXT: SectionData ( -# CONTENT-NEXT: 0000: 112233 -# CONTENT-NEXT: ) +## Check we can omit "Content", "Size" and "Dependencies" fields to +## produce an empty SHT_GNU_verneed section. ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC -Sections: - - Name: .gnu.version_r - Type: SHT_GNU_verneed - Flags: [ SHF_ALLOC ] - Info: 0x1 - Content: "112233" - -## Check we can omit "Content" and "Dependencies" fields to produce an empty SHT_GNU_verneed section. - -# RUN: yaml2obj --docnum=3 %s -o %t3 +# RUN: yaml2obj --docnum=2 %s -o %t3 # RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=NO-PROPS # NO-PROPS: [Nr] Name Type Address Off Size @@ -133,22 +101,48 @@ Type: SHT_GNU_verneed Flags: [ SHF_ALLOC ] Info: 0x0 + Size: [[SIZE=]] + Content: [[CONTENT=]] + Dependencies: [[DEPS=]] -## Check we can't use both "Dependencies" and "Content" together. +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. -# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=BOTH +# RUN: not yaml2obj --docnum=2 -DCONTENT="'00'" -DSIZE=0 %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR -# BOTH: error: SHT_GNU_verneed: "Dependencies" and "Content" can't be used together +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC -Sections: - - Name: .gnu.version_r - Type: SHT_GNU_verneed - Flags: [ SHF_ALLOC ] - Info: 0x0 - Content: "" - Dependencies: [] +# RUN: yaml2obj --docnum=2 -DCONTENT="'00'" -DSIZE=1 %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="00" + +# RUN: yaml2obj --docnum=2 -DCONTENT="'00'" -DSIZE=2 %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0000" + +# CHECK-CONTENT: Name: .gnu.version_r +# CHECK-CONTENT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj --docnum=2 -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj --docnum=2 -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" + +## Check we can't use "Dependencies" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj --docnum=2 -DSIZE=0 -DDEPS="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=DEPS-ERR +# RUN: not yaml2obj --docnum=2 -DCONTENT="'00'" -DDEPS="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=DEPS-ERR + +# DEPS-ERR: error: "Dependencies" cannot be used with "Content" or "Size" Index: llvm/test/tools/yaml2obj/ELF/versym-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/versym-section.yaml +++ llvm/test/tools/yaml2obj/ELF/versym-section.yaml @@ -105,3 +105,57 @@ Type: SHT_GNU_versym EntSize: 0x0000000000000003 Entries: [ ] + +## Check we can use "Content" key with "Size" key when the size is greater +## than or equal to the content size. + +# RUN: not yaml2obj --docnum=3 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR + +# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .gnu.version + Type: SHT_GNU_versym + Size: [[SIZE=]] + Content: [[CONTENT=]] + Entries: [[ENTRIES=]] + +# RUN: yaml2obj --docnum=3 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" + +# RUN: yaml2obj --docnum=3 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o +# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" + +# CHECK-CONTENT: Name: .gnu.version +# CHECK-CONTENT: SectionData ( +# CHECK-CONTENT-NEXT: 0000: [[DATA]] | +# CHECK-CONTENT-NEXT: ) + +## Check we can use the "Size" key alone to create the section. + +# RUN: yaml2obj --docnum=3 -DSIZE=3 %s -o %t.size.o +# RUN: llvm-readobj --sections --section-data %t.size.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" + +## Check we can use the "Content" key alone to create the section. + +# RUN: yaml2obj --docnum=3 -DCONTENT="'112233'" %s -o %t.content.o +# RUN: llvm-readobj --sections --section-data %t.content.o | \ +# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" + +## Check we can't use "Entries" key together with "Content" or "Size" keys. + +# RUN: not yaml2obj --docnum=3 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR +# RUN: not yaml2obj --docnum=3 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ENTRIES-ERR + +# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size" Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -929,8 +929,9 @@ if (!DynTagsOrErr) return DynTagsOrErr.takeError(); + S->Entries.emplace(); for (const Elf_Dyn &Dyn : *DynTagsOrErr) - S->Entries.push_back({(ELFYAML::ELF_DYNTAG)Dyn.getTag(), Dyn.getVal()}); + S->Entries->push_back({(ELFYAML::ELF_DYNTAG)Dyn.getTag(), Dyn.getVal()}); return S.release(); } @@ -945,7 +946,9 @@ auto SymTabOrErr = Obj.getSection(Shdr->sh_link); if (!SymTabOrErr) return SymTabOrErr.takeError(); - const Elf_Shdr *SymTab = *SymTabOrErr; + + if (Shdr->sh_size != 0) + S->Relocations.emplace(); if (Shdr->sh_type == ELF::SHT_REL) { auto Rels = Obj.rels(*Shdr); @@ -953,9 +956,9 @@ return Rels.takeError(); for (const Elf_Rel &Rel : *Rels) { ELFYAML::Relocation R; - if (Error E = dumpRelocation(&Rel, SymTab, R)) + if (Error E = dumpRelocation(&Rel, *SymTabOrErr, R)) return std::move(E); - S->Relocations.push_back(R); + S->Relocations->push_back(R); } } else { auto Rels = Obj.relas(*Shdr); @@ -963,10 +966,10 @@ return Rels.takeError(); for (const Elf_Rela &Rel : *Rels) { ELFYAML::Relocation R; - if (Error E = dumpRelocation(&Rel, SymTab, R)) + if (Error E = dumpRelocation(&Rel, *SymTabOrErr, R)) return std::move(E); R.Addend = Rel.r_addend; - S->Relocations.push_back(R); + S->Relocations->push_back(R); } } @@ -1031,8 +1034,10 @@ auto EntriesOrErr = Obj.template getSectionContentsAsArray(*Shdr); if (!EntriesOrErr) return EntriesOrErr.takeError(); + + S->Entries.emplace(); for (const Elf_Word &E : *EntriesOrErr) - S->Entries.push_back(E); + S->Entries->push_back(E); return S.release(); } @@ -1042,8 +1047,8 @@ auto S = std::make_unique(); if (Error E = dumpCommonSection(Shdr, *S)) return std::move(E); - S->Size = Shdr->sh_size; - + if (Shdr->sh_size) + S->Size = static_cast(Shdr->sh_size); return S.release(); } @@ -1239,8 +1244,10 @@ auto VersionsOrErr = Obj.template getSectionContentsAsArray(*Shdr); if (!VersionsOrErr) return VersionsOrErr.takeError(); + + S->Entries.emplace(); for (const Elf_Half &E : *VersionsOrErr) - S->Entries.push_back(E); + S->Entries->push_back(E); return S.release(); } @@ -1339,9 +1346,10 @@ if (!MembersOrErr) return MembersOrErr.takeError(); + S->Members.emplace(); for (Elf_Word Member : *MembersOrErr) { if (Member == llvm::ELF::GRP_COMDAT) { - S->Members.push_back({"GRP_COMDAT"}); + S->Members->push_back({"GRP_COMDAT"}); continue; } @@ -1351,7 +1359,7 @@ auto NameOrErr = getUniquedSectionName(*SHdrOrErr); if (!NameOrErr) return NameOrErr.takeError(); - S->Members.push_back({*NameOrErr}); + S->Members->push_back({*NameOrErr}); } return S.release(); }