diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-10-03 15:02:18 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-10-03 15:02:18 +0000 |
commit | c18585e32eb0f69849ddb01f7aeb2cf7836b6a5c (patch) | |
tree | 12c67795e9d87f474efffe5fa2188b9cda07daa8 /llvm | |
parent | 069cb6282db8bd378f411bb19e65db30a47cd879 (diff) | |
download | bcm5719-llvm-c18585e32eb0f69849ddb01f7aeb2cf7836b6a5c.tar.gz bcm5719-llvm-c18585e32eb0f69849ddb01f7aeb2cf7836b6a5c.zip |
[yaml2obj] - Add a Size tag support for SHT_LLVM_ADDRSIG sections.
It allows using "Size" with or without "Content" in YAML descriptions of
SHT_LLVM_ADDRSIG sections.
Differential revision: https://reviews.llvm.org/D68334
llvm-svn: 373610
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/ObjectYAML/ELFYAML.h | 1 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/ELFEmitter.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/ELFYAML.cpp | 14 | ||||
-rw-r--r-- | llvm/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml | 98 |
4 files changed, 109 insertions, 8 deletions
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h index 592b5021bd6..ef2b4fba031 100644 --- a/llvm/include/llvm/ObjectYAML/ELFYAML.h +++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -268,6 +268,7 @@ struct AddrsigSymbol { struct AddrsigSection : Section { Optional<yaml::BinaryRef> Content; + Optional<llvm::yaml::Hex64> Size; Optional<std::vector<AddrsigSymbol>> Symbols; AddrsigSection() : Section(SectionKind::Addrsig) {} diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index 3f3b27c5bfa..f9c31f335f1 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -1007,8 +1007,8 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader, if (Section.Link.empty() && SN2I.lookup(".symtab", Link)) SHeader.sh_link = Link; - if (Section.Content) { - SHeader.sh_size = writeContent(OS, Section.Content, None); + if (Section.Content || Section.Size) { + SHeader.sh_size = writeContent(OS, Section.Content, Section.Size); return; } diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index e295a000ef8..29585abe6e8 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1074,6 +1074,7 @@ static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) { 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,12 +1246,17 @@ StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate( } if (const auto *Sec = dyn_cast<ELFYAML::AddrsigSection>(Section.get())) { - if (!Sec->Symbols && !Sec->Content) - return "one of \"Symbols\" or \"Content\" must be specified"; + 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->Content) { if (Sec->Symbols) - return "\"Content\" and \"Symbols\" cannot be used together"; + return "\"Symbols\" cannot be used with \"Content\" or \"Size\""; return {}; } diff --git a/llvm/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml b/llvm/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml index 98496d30fa8..1433d6dbc13 100644 --- a/llvm/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml +++ b/llvm/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml @@ -161,7 +161,7 @@ Sections: # RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=NO-TAGS -# NO-TAGS: error: one of "Symbols" or "Content" must be specified +# NO-TAGS: error: one of "Content", "Size" or "Symbols" must be specified --- !ELF FileHeader: @@ -177,7 +177,7 @@ Sections: # RUN: not yaml2obj --docnum=8 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS -# CONTENT-SYMBOLS: error: "Content" and "Symbols" cannot be used together +# CONTENT-SYMBOLS: "Symbols" cannot be used with "Content" or "Size" --- !ELF FileHeader: @@ -211,3 +211,97 @@ Sections: Type: SHT_LLVM_ADDRSIG Link: 123 Content: "" + +## Check we can use only "Size" to create a SHT_LLVM_ADDRSIG section. + +# RUN: yaml2obj --docnum=10 %s -o %t10 +# RUN: llvm-readobj --sections --section-data %t10 | FileCheck %s --check-prefix=SIZE + +# SIZE: Name: .llvm_addrsig +# SIZE: Size: +# SIZE-SAME: 17 +# SIZE: SectionData ( +# SIZE-NEXT: 0000: 00000000 00000000 00000000 00000000 | +# SIZE-NEXT: 0010: 00 | +# SIZE-NEXT: ) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .llvm_addrsig + Type: SHT_LLVM_ADDRSIG + Size: 0x11 + +## Check we can use "Size" and "Content" together to create a SHT_LLVM_ADDRSIG section. + +# RUN: yaml2obj --docnum=11 %s -o %t11 +# RUN: llvm-readobj --sections --section-data %t11 | FileCheck %s --check-prefix=SIZE-CONTENT + +# SIZE-CONTENT: Name: .llvm_addrsig_sizegr +# SIZE-CONTENT: Size: +# SIZE-CONTENT-SAME: 5 +# SIZE-CONTENT: SectionData ( +# SIZE-CONTENT-NEXT: 0000: 11223300 00 | +# SIZE-CONTENT-NEXT: ) + +# SIZE-CONTENT: Name: .llvm_addrsig_sizeeq +# SIZE-CONTENT: Size: +# SIZE-CONTENT-SAME: 3 +# SIZE-CONTENT: SectionData ( +# SIZE-CONTENT-NEXT: 0000: 112233 | +# SIZE-CONTENT-NEXT: ) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .llvm_addrsig_sizegr + Type: SHT_LLVM_ADDRSIG + Size: 0x5 + Content: "112233" + - Name: .llvm_addrsig_sizeeq + Type: SHT_LLVM_ADDRSIG + Size: 0x3 + Content: "112233" + +## Check that when "Size" and "Content" are used together, the size +## must be greater than or equal to the content size. + +# RUN: not yaml2obj --docnum=12 %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 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .llvm_addrsig + Type: SHT_LLVM_ADDRSIG + Size: 0x1 + Content: "1122" + +## Check we can't use "Size" and "Symbols" tags together. + +# RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .llvm_addrsig + Type: SHT_LLVM_ADDRSIG + Size: 0x1 + Symbols: [ ] |