summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/ELFYAML.cpp
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2014-05-16 16:01:00 +0000
committerSimon Atanasyan <simon@atanasyan.com>2014-05-16 16:01:00 +0000
commitb83f380ae4b7657cc741a4ba4442847334a570cf (patch)
tree4b7be01cf021d8274188da0d946875b2ff23f028 /llvm/lib/Object/ELFYAML.cpp
parenta70697e10eaff415a7c93e7bf4d4875cb2e32ebf (diff)
downloadbcm5719-llvm-b83f380ae4b7657cc741a4ba4442847334a570cf.tar.gz
bcm5719-llvm-b83f380ae4b7657cc741a4ba4442847334a570cf.zip
[yaml2obj][ELF] Add an optional `Size` field to the YAML section declaration.
Now the only method to configure ELF section's content and size is to assign a hexadecimal string to the `Content` field. Unfortunately this way is completely useless when you need to declare a really large section. To solve this problem this patch adds one more optional field `Size` to the `RawContentSection` structure. When yaml2obj generates an ELF file it uses the following algorithm: 1. If both `Content` and `Size` fields are missed create an empty section. 2. If only `Content` field is missed take section length from the `Size` field and fill the section by zero. 3. If only `Size` field is missed create a section using data from the `Content` field. 4. If both `Content` and `Size` fields are provided validate that the `Size` value is not less than size of `Content` data. Than take section length from the `Size`, fill beginning of the section by `Content` and the rest by zero. Examples -------- * Create a section 0x10000 bytes long filled by zero Name: .data Type: SHT_PROGBITS Flags: [ SHF_ALLOC ] Size: 0x10000 * Create a section 0x10000 bytes long starting from 'CA' 'FE' 'BA' 'BE' Name: .data Type: SHT_PROGBITS Flags: [ SHF_ALLOC ] Content: CAFEBABE Size: 0x10000 The patch reviewed by Michael Spencer. llvm-svn: 208995
Diffstat (limited to 'llvm/lib/Object/ELFYAML.cpp')
-rw-r--r--llvm/lib/Object/ELFYAML.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Object/ELFYAML.cpp b/llvm/lib/Object/ELFYAML.cpp
index c396f66ee65..547720ddc32 100644
--- a/llvm/lib/Object/ELFYAML.cpp
+++ b/llvm/lib/Object/ELFYAML.cpp
@@ -658,6 +658,7 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
commonSectionMapping(IO, Section);
IO.mapOptional("Content", Section.Content);
+ IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
}
static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
@@ -687,6 +688,14 @@ void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping(
}
}
+StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate(
+ IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
+ const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
+ if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
+ return StringRef();
+ return "Section size must be greater or equal to the content size";
+}
+
void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
ELFYAML::Relocation &Rel) {
IO.mapRequired("Offset", Rel.Offset);
OpenPOWER on IntegriCloud