[llvm] r373473 - [yaml2obj] - Alow Size tag for describing SHT_HASH sections.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 2 06:52:37 PDT 2019
Author: grimar
Date: Wed Oct 2 06:52:37 2019
New Revision: 373473
URL: http://llvm.org/viewvc/llvm-project?rev=373473&view=rev
Log:
[yaml2obj] - Alow Size tag for describing SHT_HASH sections.
This is a follow-up for D68085 which allows using "Size"
tag together with "Content" tag or alone.
Differential revision: https://reviews.llvm.org/D68216
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-hash-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=373473&r1=373472&r2=373473&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h Wed Oct 2 06:52:37 2019
@@ -223,6 +223,7 @@ struct NoBitsSection : Section {
struct HashSection : Section {
Optional<yaml::BinaryRef> Content;
+ Optional<llvm::yaml::Hex64> Size;
Optional<std::vector<uint32_t>> Bucket;
Optional<std::vector<uint32_t>> Chain;
Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=373473&r1=373472&r2=373473&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Wed Oct 2 06:52:37 2019
@@ -824,8 +824,8 @@ void ELFState<ELFT>::writeSectionContent
if (Section.Link.empty() && SN2I.lookup(".dynsym", 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=373473&r1=373472&r2=373473&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Wed Oct 2 06:52:37 2019
@@ -1029,6 +1029,7 @@ static void sectionMapping(IO &IO, ELFYA
IO.mapOptional("Content", Section.Content);
IO.mapOptional("Bucket", Section.Bucket);
IO.mapOptional("Chain", Section.Chain);
+ IO.mapOptional("Size", Section.Size);
}
static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
@@ -1210,14 +1211,20 @@ StringRef MappingTraits<std::unique_ptr<
}
if (const auto *HS = dyn_cast<ELFYAML::HashSection>(Section.get())) {
- if (!HS->Content && !HS->Bucket && !HS->Chain)
- return "one of \"Content\", \"Bucket\" or \"Chain\" must be specified";
+ if (!HS->Content && !HS->Bucket && !HS->Chain && !HS->Size)
+ return "one of \"Content\", \"Size\", \"Bucket\" or \"Chain\" must be "
+ "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->Content) {
if (HS->Bucket)
- return "\"Content\" and \"Bucket\" cannot be used together";
+ return "\"Bucket\" cannot be used with \"Content\" or \"Size\"";
if (HS->Chain)
- return "\"Content\" and \"Chain\" cannot be used together";
+ return "\"Chain\" cannot be used with \"Content\" or \"Size\"";
return {};
}
Modified: llvm/trunk/test/tools/yaml2obj/elf-hash-section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-hash-section.yaml?rev=373473&r1=373472&r2=373473&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-hash-section.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-hash-section.yaml Wed Oct 2 06:52:37 2019
@@ -66,7 +66,7 @@ Sections:
# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-BUCKET
-# CONTENT-BUCKET: error: "Content" and "Bucket" cannot be used together
+# CONTENT-BUCKET: "Bucket" cannot be used with "Content" or "Size"
--- !ELF
FileHeader:
@@ -84,7 +84,7 @@ Sections:
# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-CHAIN
-# CONTENT-CHAIN: error: "Content" and "Chain" cannot be used together
+# CONTENT-CHAIN: "Chain" cannot be used with "Content" or "Size"
--- !ELF
FileHeader:
@@ -134,7 +134,7 @@ Sections:
# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=NO-TAGS
-# NO-TAGS: error: one of "Content", "Bucket" or "Chain" must be specified
+# NO-TAGS: error: one of "Content", "Size", "Bucket" or "Chain" must be specified
--- !ELF
FileHeader:
@@ -177,3 +177,102 @@ Sections:
## SHT_HASH is linked to dynamic symbol table by default if it exists.
- Name: .dynsym
Type: SHT_DYNSYM
+
+## Check we can use only "Size" to create a SHT_HASH section.
+
+# RUN: yaml2obj --docnum=9 %s -o %t9
+# RUN: llvm-readobj --sections --section-data %t9 | FileCheck %s --check-prefix=SIZE
+
+# SIZE: Name: .hash
+# 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: .hash
+ Type: SHT_HASH
+ Size: 0x11
+
+## Check we can use "Size" and "Content" together to create a SHT_HASH section.
+
+# RUN: yaml2obj --docnum=10 %s -o %t10
+# RUN: llvm-readobj --sections --section-data %t10 | FileCheck %s --check-prefix=SIZE-CONTENT
+
+# SIZE-CONTENT: Name: .hash
+# SIZE-CONTENT: Size:
+# SIZE-CONTENT-SAME: 5
+# SIZE-CONTENT: SectionData (
+# SIZE-CONTENT-NEXT: 0000: 11223300 00 |
+# SIZE-CONTENT-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .hash
+ Type: SHT_HASH
+ Size: 0x5
+ 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=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
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .hash
+ Type: SHT_HASH
+ Size: 0x1
+ Content: "1122"
+
+## Check we can't use "Size" and "Bucket" tags together.
+
+# RUN: not yaml2obj --docnum=12 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-BUCKET
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .hash
+ Type: SHT_HASH
+ Size: 0x1
+ Bucket: [ 1 ]
+
+## Check we can't use "Size" and "Chain" tags together.
+
+# RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-CHAIN
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .hash
+ Type: SHT_HASH
+ Size: 0x1
+ Chain: [ 1 ]
More information about the llvm-commits
mailing list