[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
llvm-svn: 373473
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 1651d60..c85cf4c 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -824,8 +824,8 @@
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;
}
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 3a09a11..0dd6854 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1029,6 +1029,7 @@
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 @@
}
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) {
+ 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 "\"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 {};
}