summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ObjectYAML
diff options
context:
space:
mode:
authorGeorgii Rymar <grimar@accesssoftek.com>2019-12-12 15:47:29 +0300
committerGeorgii Rymar <grimar@accesssoftek.com>2019-12-13 11:54:37 +0300
commit86e652f8284d44c0e3fa9b27421a671e89bfe0a0 (patch)
tree246a8e5190e435b2b2ae46143cb18588954c8620 /llvm/lib/ObjectYAML
parent422b078c69ee7ae5c2529992eed4fd8a21aedda4 (diff)
downloadbcm5719-llvm-86e652f8284d44c0e3fa9b27421a671e89bfe0a0.tar.gz
bcm5719-llvm-86e652f8284d44c0e3fa9b27421a671e89bfe0a0.zip
[yaml2obj] - Add a way to override sh_flags section field.
Currently we have the `Flags` property that allows to set flags for a section. The problem is that it does not allow us to set an arbitrary value, because of bit fields validation under the hood. An arbitrary values can be used to test specific broken cases. We probably do not want to relax the validation, so this patch adds a `ShSize` property that allows to override the `sh_size`. It is inline with others `Sh*` properties we have already. Differential revision: https://reviews.llvm.org/D71411
Diffstat (limited to 'llvm/lib/ObjectYAML')
-rw-r--r--llvm/lib/ObjectYAML/ELFEmitter.cpp37
-rw-r--r--llvm/lib/ObjectYAML/ELFYAML.cpp9
2 files changed, 24 insertions, 22 deletions
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index d2e6fdfea00..69f5510fc7f 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -350,6 +350,20 @@ unsigned ELFState<ELFT>::toSymbolIndex(StringRef S, StringRef LocSec,
}
template <class ELFT>
+static void overrideFields(ELFYAML::Section *From, typename ELFT::Shdr &To) {
+ if (!From)
+ return;
+ if (From->ShFlags)
+ To.sh_flags = *From->ShFlags;
+ if (From->ShName)
+ To.sh_name = *From->ShName;
+ if (From->ShOffset)
+ To.sh_offset = *From->ShOffset;
+ if (From->ShSize)
+ To.sh_size = *From->ShSize;
+}
+
+template <class ELFT>
bool ELFState<ELFT>::initImplicitHeader(ContiguousBlobAccumulator &CBA,
Elf_Shdr &Header, StringRef SecName,
ELFYAML::Section *YAMLSec) {
@@ -370,16 +384,8 @@ bool ELFState<ELFT>::initImplicitHeader(ContiguousBlobAccumulator &CBA,
else
return false;
- // Override the fields if requested.
- if (YAMLSec) {
- if (YAMLSec->ShName)
- Header.sh_name = *YAMLSec->ShName;
- if (YAMLSec->ShOffset)
- Header.sh_offset = *YAMLSec->ShOffset;
- if (YAMLSec->ShSize)
- Header.sh_size = *YAMLSec->ShSize;
- }
-
+ // Override section fields if requested.
+ overrideFields<ELFT>(YAMLSec, Header);
return true;
}
@@ -484,15 +490,8 @@ void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
llvm_unreachable("Unknown section type");
}
- // Override the fields if requested.
- if (Sec) {
- if (Sec->ShName)
- SHeader.sh_name = *Sec->ShName;
- if (Sec->ShOffset)
- SHeader.sh_offset = *Sec->ShOffset;
- if (Sec->ShSize)
- SHeader.sh_size = *Sec->ShSize;
- }
+ // Override section fields if requested.
+ overrideFields<ELFT>(Sec, SHeader);
}
}
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index c8de7a662fc..aa871af79b1 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1017,10 +1017,12 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
// are producing YAML, because yaml2obj sets appropriate values for them
// automatically when they are not explicitly defined.
assert(!IO.outputting() ||
- (!Section.ShOffset.hasValue() && !Section.ShSize.hasValue()));
+ (!Section.ShOffset.hasValue() && !Section.ShSize.hasValue() &&
+ !Section.ShName.hasValue() && !Section.ShFlags.hasValue()));
IO.mapOptional("ShName", Section.ShName);
IO.mapOptional("ShOffset", Section.ShOffset);
IO.mapOptional("ShSize", Section.ShSize);
+ IO.mapOptional("ShFlags", Section.ShFlags);
}
static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) {
@@ -1283,11 +1285,12 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
StringRef MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
IO &io, std::unique_ptr<ELFYAML::Chunk> &C) {
- if (const auto *RawSection =
- dyn_cast<ELFYAML::RawContentSection>(C.get())) {
+ if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) {
if (RawSection->Size && RawSection->Content &&
(uint64_t)(*RawSection->Size) < RawSection->Content->binary_size())
return "Section size must be greater than or equal to the content size";
+ if (RawSection->Flags && RawSection->ShFlags)
+ return "ShFlags and Flags cannot be used together";
return {};
}
OpenPOWER on IntegriCloud