[llvm] r372845 - [yaml2obj] - Add a Size field for StackSizesSection.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 04:40:11 PDT 2019
Author: grimar
Date: Wed Sep 25 04:40:11 2019
New Revision: 372845
URL: http://llvm.org/viewvc/llvm-project?rev=372845&view=rev
Log:
[yaml2obj] - Add a Size field for StackSizesSection.
It is a follow-up requested in the review comment
for D67757. Allows to use Content + Size or just Size
when describing .stack_sizes sections in YAML document
Differential revision: https://reviews.llvm.org/D67958
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-stack-sizes.yaml
Modified: llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h?rev=372845&r1=372844&r2=372845&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h Wed Sep 25 04:40:11 2019
@@ -171,6 +171,7 @@ struct Section {
struct StackSizesSection : Section {
Optional<yaml::BinaryRef> Content;
+ Optional<llvm::yaml::Hex64> Size;
Optional<std::vector<StackSizeEntry>> Entries;
StackSizesSection() : Section(SectionKind::StackSizes) {}
Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=372845&r1=372844&r2=372845&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Wed Sep 25 04:40:11 2019
@@ -440,19 +440,20 @@ static size_t findFirstNonGlobal(ArrayRe
return Symbols.size();
}
-static uint64_t writeRawSectionData(raw_ostream &OS,
- const ELFYAML::RawContentSection &RawSec) {
+static uint64_t writeContent(raw_ostream &OS,
+ const Optional<yaml::BinaryRef> &Content,
+ const Optional<llvm::yaml::Hex64> &Size) {
size_t ContentSize = 0;
- if (RawSec.Content) {
- RawSec.Content->writeAsBinary(OS);
- ContentSize = RawSec.Content->binary_size();
+ if (Content) {
+ Content->writeAsBinary(OS);
+ ContentSize = Content->binary_size();
}
- if (!RawSec.Size)
+ if (!Size)
return ContentSize;
- OS.write_zeros(*RawSec.Size - ContentSize);
- return *RawSec.Size;
+ OS.write_zeros(*Size - ContentSize);
+ return *Size;
}
template <class ELFT>
@@ -554,7 +555,7 @@ void ELFState<ELFT>::initSymtabSectionHe
auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
if (RawSec && (RawSec->Content || RawSec->Size)) {
assert(Symbols.empty());
- SHeader.sh_size = writeRawSectionData(OS, *RawSec);
+ SHeader.sh_size = writeContent(OS, RawSec->Content, RawSec->Size);
return;
}
@@ -579,7 +580,7 @@ void ELFState<ELFT>::initStrtabSectionHe
auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
if (RawSec && (RawSec->Content || RawSec->Size)) {
- SHeader.sh_size = writeRawSectionData(OS, *RawSec);
+ SHeader.sh_size = writeContent(OS, RawSec->Content, RawSec->Size);
} else {
STB.write(OS);
SHeader.sh_size = STB.getSize();
@@ -675,7 +676,7 @@ void ELFState<ELFT>::writeSectionContent
ContiguousBlobAccumulator &CBA) {
raw_ostream &OS =
CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
- SHeader.sh_size = writeRawSectionData(OS, Section);
+ SHeader.sh_size = writeContent(OS, Section.Content, Section.Size);
if (Section.EntSize)
SHeader.sh_entsize = *Section.EntSize;
@@ -795,9 +796,8 @@ void ELFState<ELFT>::writeSectionContent
raw_ostream &OS =
CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
- if (Section.Content) {
- Section.Content->writeAsBinary(OS);
- SHeader.sh_size = Section.Content->binary_size();
+ 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=372845&r1=372844&r2=372845&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Wed Sep 25 04:40:11 2019
@@ -1020,6 +1020,7 @@ static void sectionMapping(IO &IO, ELFYA
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);
}
@@ -1176,10 +1177,22 @@ StringRef MappingTraits<std::unique_ptr<
}
if (const auto *SS = dyn_cast<ELFYAML::StackSizesSection>(Section.get())) {
- if (SS->Content && SS->Entries)
+ 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 {};
+
+ if (SS->Size)
+ return ".stack_sizes: Size and Entries cannot be used together";
+ if (SS->Content)
return ".stack_sizes: Content and Entries cannot be used together";
- if (!SS->Content && !SS->Entries)
- return ".stack_sizes: either Content or Entries tag must be specified";
return {};
}
return {};
Modified: llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml?rev=372845&r1=372844&r2=372845&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml Wed Sep 25 04:40:11 2019
@@ -212,11 +212,11 @@ Sections:
- Address: 0x10
Size: 0x20
-## Check we must specify either "Content" or "Entries" tag when describing .stack_sizes.
+## Check we must specify either "Content", "Entries" or "Size" tag when describing .stack_sizes.
# RUN: not yaml2obj --docnum=9 %s 2>&1 | FileCheck %s --check-prefix=NO-TAGS
-# NO-TAGS: error: .stack_sizes: either Content or Entries tag must be specified
+# NO-TAGS: .stack_sizes: one of Content, Entries and Size must be specified
--- !ELF
FileHeader:
@@ -227,3 +227,87 @@ FileHeader:
Sections:
- Name: .stack_sizes
Type: SHT_PROGBITS
+
+## Check we can't use both "Size" and "Entries" tags at the same time.
+
+# RUN: not yaml2obj --docnum=10 %s 2>&1 | FileCheck %s --check-prefix=ENTRIES-AND-SIZE
+
+# ENTRIES-AND-SIZE: .stack_sizes: Size and Entries cannot be used together
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .stack_sizes
+ Type: SHT_PROGBITS
+ Size: 0x1
+ Entries:
+ - Address: 0x10
+ Size: 0x20
+
+## Check we can use only "Size" to create .stack_sizes section.
+
+# RUN: yaml2obj --docnum=11 %s -o %t11
+# RUN: llvm-readobj --sections --section-data %t11 | FileCheck %s --check-prefix=SIZE
+
+# SIZE: Name: .stack_sizes
+# 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: .stack_sizes
+ Type: SHT_PROGBITS
+ Size: 0x11
+
+## Check we can use "Size" and "Content" together to create .stack_sizes section.
+
+# RUN: yaml2obj --docnum=12 %s -o %t12
+# RUN: llvm-readobj --sections --section-data %t12 | FileCheck %s --check-prefix=SIZE-CONTENT
+
+# SIZE-CONTENT: Name: .stack_sizes
+# 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: .stack_sizes
+ Type: SHT_PROGBITS
+ Size: 0x5
+ Content: "112233"
+
+# RUN: not yaml2obj --docnum=13 %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
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .stack_sizes
+ Type: SHT_PROGBITS
+ Size: 0x1
+ Content: "1122"
More information about the llvm-commits
mailing list