summaryrefslogtreecommitdiff
path: root/tools
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
commit19ab8f850f2937915598958b7c54957eed1a94c5 (patch)
tree9b58523f685b0ba1fdc815c7789cbd76eb67b74c /tools
parentb32cee560d91bb2ec4325ad348ee322a42a3a3cf (diff)
downloadllvm-19ab8f850f2937915598958b7c54957eed1a94c5.tar.gz
llvm-19ab8f850f2937915598958b7c54957eed1a94c5.tar.bz2
llvm-19ab8f850f2937915598958b7c54957eed1a94c5.tar.xz
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208995 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/obj2yaml/elf2yaml.cpp1
-rw-r--r--tools/yaml2obj/yaml2elf.cpp9
2 files changed, 8 insertions, 2 deletions
diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp
index 38afa138d9..7642921b48 100644
--- a/tools/obj2yaml/elf2yaml.cpp
+++ b/tools/obj2yaml/elf2yaml.cpp
@@ -254,6 +254,7 @@ ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) {
if (error_code EC = ContentOrErr.getError())
return EC;
S->Content = object::yaml::BinaryRef(ContentOrErr.get());
+ S->Size = S->Content.binary_size();
return S.release();
}
diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp
index 3190b27d32..bb52cda7c1 100644
--- a/tools/yaml2obj/yaml2elf.cpp
+++ b/tools/yaml2obj/yaml2elf.cpp
@@ -314,9 +314,14 @@ void
ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::RawContentSection &Section,
ContiguousBlobAccumulator &CBA) {
- Section.Content.writeAsBinary(CBA.getOSAndAlignedOffset(SHeader.sh_offset));
+ assert(Section.Size >= Section.Content.binary_size() &&
+ "Section size and section content are inconsistent");
+ raw_ostream &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
+ Section.Content.writeAsBinary(OS);
+ for (auto i = Section.Content.binary_size(); i < Section.Size; ++i)
+ OS.write(0);
SHeader.sh_entsize = 0;
- SHeader.sh_size = Section.Content.binary_size();
+ SHeader.sh_size = Section.Size;
}
template <class ELFT>