[llvm] r373610 - [yaml2obj] - Add a Size tag support for SHT_LLVM_ADDRSIG sections.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 08:02:18 PDT 2019
Author: grimar
Date: Thu Oct 3 08:02:18 2019
New Revision: 373610
URL: http://llvm.org/viewvc/llvm-project?rev=373610&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
llvm/trunk/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml
Modified: llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h?rev=373610&r1=373609&r2=373610&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h Thu Oct 3 08:02:18 2019
@@ -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) {}
Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=373610&r1=373609&r2=373610&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Thu Oct 3 08:02:18 2019
@@ -1007,8 +1007,8 @@ void ELFState<ELFT>::writeSectionContent
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;
}
Modified: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFYAML.cpp?rev=373610&r1=373609&r2=373610&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Thu Oct 3 08:02:18 2019
@@ -1074,6 +1074,7 @@ static void sectionMapping(IO &IO, ELFYA
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<
}
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 {};
}
Modified: llvm/trunk/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml?rev=373610&r1=373609&r2=373610&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-llvm-addrsig-section.yaml Thu Oct 3 08:02:18 2019
@@ -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: [ ]
More information about the llvm-commits
mailing list