summaryrefslogtreecommitdiff
path: root/tools/yaml2obj/yaml2elf.cpp
Commit message (Collapse)AuthorAge
* [yaml2obj][obj2yaml] Support ELF symbol's visibility flags ↵Simon Atanasyan2014-06-06
| | | | | | (default/hidden/protected). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210316 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj] Add new command line option `-docnum`.Simon Atanasyan2014-05-31
| | | | | | | | | | Input YAML file might contain multiple object file definitions. New option `-docnum` allows to specify an ordinal number (starting from 1) of definition used for an object file generation. Patch reviewed by Sean Silva. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209967 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Add an optional `Size` field to the YAML section declaration.Simon Atanasyan2014-05-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [yaml2obj] Add "-o" command line option to specify an output file name.Simon Atanasyan2014-05-15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208900 91177308-0d34-0410-b5e6-96231b3b80d8
* Use the new StringTableBuilder in yaml2elfHans Wennborg2014-04-30
| | | | | | http://reviews.llvm.org/D3574 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207694 91177308-0d34-0410-b5e6-96231b3b80d8
* ELFObjectWriter: deduplicate suffices in strtabHans Wennborg2014-04-30
| | | | | | | | | | | | | | | We already do this for shstrtab, so might as well do it for strtab. This extracts the string table building code into a separate class. The idea is to use it for other object formats too. I mostly wanted to do this for the general principle, but it does save a little bit on object file size. I tried this on a clang bootstrap and saved 0.54% on the sum of object file sizes (1.14 MB out of 212 MB for a release build). Differential Revision: http://reviews.llvm.org/D3533 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207670 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] ELF Relocations Support.Simon Atanasyan2014-04-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch implements support for both relocation record formats: Elf_Rel and Elf_Rela. It is possible to define relocation against symbol only. Relocations against sections will be implemented later. Now yaml2obj recognizes X86_64, MIPS and Hexagon relocation types. Example of relocation section specification: Sections: - Name: .text Type: SHT_PROGBITS Content: "0000000000000000" AddressAlign: 16 Flags: [SHF_ALLOC] - Name: .rel.text Type: SHT_REL Info: .text AddressAlign: 4 Relocations: - Offset: 0x1 Symbol: glob1 Type: R_MIPS_32 - Offset: 0x2 Symbol: glob2 Type: R_MIPS_CALL16 The patch reviewed by Michael Spencer, Sean Silva, Shankar Easwaran. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206017 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Rename class SectionNameToIdxMap => NameToIdxMap. It canSimon Atanasyan2014-04-06
| | | | | | | | be used for indexing not only section's names. No functional changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205687 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Convert some static functions into class members toSimon Atanasyan2014-04-02
| | | | | | | | reduce number of arguments. No functional changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205434 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Remove unused typedef.Simon Atanasyan2014-04-02
| | | | | | No functional changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205433 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Move section index to the ELFState class.Simon Atanasyan2014-04-02
| | | | | | No functional changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205432 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Remove relationship between ELFStateSimon Atanasyan2014-04-02
| | | | | | | | | and ContiguousBlobAccumulator classes. Pass ContiguousBlobAccumulator to the handleSymtabSectionHeader function directly. No functional changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205431 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj] Add support for ELF e_flags.Daniel Sanders2014-03-31
| | | | | | | | | | | | | | | | Summary: The FileHeader mapping now accepts an optional Flags sequence that accepts the EF_<arch>_<flag> constants. When not given, Flags defaults to zero. Reviewers: atanasyan Reviewed By: atanasyan CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3213 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205173 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Use range-based for loops.Simon Atanasyan2014-03-14
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203900 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Refer to a section in the error message by its name notSimon Atanasyan2014-03-14
| | | | | | index. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203899 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Remove unused ELFState class field.Simon Atanasyan2014-03-14
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203898 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Assign name (.shstrtab) to the section holds sections names.Simon Atanasyan2014-03-14
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203897 91177308-0d34-0410-b5e6-96231b3b80d8
* yaml2coff/elf: Touchup for compatibility.Will Dietz2013-10-12
| | | | | | | * std::string::append(int, int) can be ambiguous. * std::vector<>::data() is a C++11 feature, use ArrayRef abstraction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192542 91177308-0d34-0410-b5e6-96231b3b80d8
* [Object] Split the ELF interface into 3 parts.Michael J. Spencer2013-08-08
| | | | | | | | * ELFTypes.h contains template magic for defining types based on endianess, size, and alignment. * ELFFile.h defines the ELFFile class which provides low level ELF specific access. * ELFObjectFile.h contains ELFObjectFile which uses ELFFile to implement the ObjectFile interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188022 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Make symbol table top-level key.Sean Silva2013-06-22
| | | | | | | | | Although in reality the symbol table in ELF resides in a section, the standard requires that there be no more than one SHT_SYMTAB. To enforce this constraint, it is cleaner to group all the symbols under a top-level `Symbols` key on the object file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184627 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Narrow parameter.Sean Silva2013-06-22
| | | | | | The full ELFYAML::Section isn't needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184626 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Don't special case writing these.Sean Silva2013-06-22
| | | | | | | Just add them to the vector of section headers like the rest of the section headers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184624 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Make this "type switch" actually readable.Sean Silva2013-06-22
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184623 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Align section contents in the output.Sean Silva2013-06-22
| | | | | | | | | | The improperly aligned section content in the output was causing buildbot failures. This should fix them. Incidentally, this results in a simpler and more robust API for ContiguousBlobAccumulator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184621 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Allow expressing undefined symbols.Sean Silva2013-06-21
| | | | | | | | | | Previously we unconditionally enforced that section references in symbols in the YAML had a name that was a section name present in the object, and linked the references to that section. Now, permit empty section names (already the default, if the `Section` key is not provided) to indicate SHN_UNDEF. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184513 91177308-0d34-0410-b5e6-96231b3b80d8
* Unbreak bots. Didn't realize this was a C++11 feature.Sean Silva2013-06-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184508 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Don't explicitly set `Binding` with STB_*Sean Silva2013-06-21
| | | | | | | | | | | | | | | Instead, just have 3 sub-lists, one for each of {STB_LOCAL,STB_GLOBAL,STB_WEAK}. This allows us to be a lot more explicit w.r.t. the symbol ordering in the object file, because if we allowed explicitly setting the STB_* `Binding` key for the symbol, then we might have ended up having to shuffle STB_LOCAL symbols to the front of the list, which is likely to cause confusion and potential for error. Also, this new approach is simpler ;) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184506 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Add support for st_value and st_size.Sean Silva2013-06-20
| | | | | | | | | After this patch, the ELF file produced by `yaml2obj-elf-symbol-basic.yaml`, when linked and executed on x86_64 (under SysV ABI, obviously; I tested on Linux), produces a working executable that goes into an infinite loop! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184469 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Allow symbols to reference sections.Sean Silva2013-06-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184468 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Add the section name -> section index map to State.Sean Silva2013-06-20
| | | | | | | | | | | | | | One of the key things that the YAML format abstracts over is the use of section numbers for referencing sections. Instead, textual section names are used, which yaml2obj then translates into appropriate section numbers. (Technically ELF doesn't care about section names (only section numbers), but since this is a testing tool, readability counts). This simplifies using section names as symbolic references in various parts of the code. An upcoming commit will use this to allow symbols to reference sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184467 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Start factoring into "single point of truth".Sean Silva2013-06-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184457 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Just let this class own its buffer.Sean Silva2013-06-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184456 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove `using namespace` and use explicit qualification.Sean Silva2013-06-19
| | | | | | There were only two places it was actually making anything shorter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184273 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove spurious space.Sean Silva2013-06-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184272 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove unused parameter.Sean Silva2013-06-19
| | | | | | | | Not sure why we weren't catching this with -Wunused-parameter... Spotted by inspection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184271 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Support ELFOSABI_* enum.Sean Silva2013-06-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184268 91177308-0d34-0410-b5e6-96231b3b80d8
* There is no ELF ABI version enum.Sean Silva2013-06-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184267 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Support st_info through `Binding` and `Type` YAML keys.Sean Silva2013-06-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184263 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Don't monkeypatch the YAML sections.Sean Silva2013-06-18
| | | | | | | | | | | | | Previously, we would monkeypatch the vector of YAML::Section's in order to ensure that the SHT_NULL entry is present. Now we just add it unconditionally. The proliferation of small numerical adjustments is beginning to frighten me, but I can't think of a way having a single point of truth for them without introducing a whole new layer of data structures (i.e. lots of code and complexity) between the YAML and binary ELF formats. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184260 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Ensure STN_UNDEF entry is present.Sean Silva2013-06-18
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184258 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Rudimentary symbol table support.Sean Silva2013-06-18
| | | | | | Currently, we only output the name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184255 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Add dummy .strtab section.Sean Silva2013-06-18
| | | | | | | This will be needed later for holding symbol names, due to the libObject issue mentioned in the commit message of r184161. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184242 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Factor out string table section creation.Sean Silva2013-06-18
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184162 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Refer specifically to the section header string table.Sean Silva2013-06-18
| | | | | | | | | | | | | | | A bug in libObject will cause it to assert() if a symbol table's string table and the section header string table are the same section, so we need to ensure that we emit two different string tables (among other things). The problematic code is the hardcoded usage of ".strtab" (`dot_strtab_sec`) for looking up symbol names in ELFObjectFile<ELFT>::getSymbolName. I discussed this with Michael, and he has some local improvements to the ELF code in libObject that, among other things, should fix our handling of this scenario. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184161 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Ensure more fields are zero'd.Sean Silva2013-06-18
| | | | | | | | | | | | I was spotting garbage in the output. I'd like to just zero the entire ELFYAML::Section to be sure, but it contains non-POD types. (I'm also trying to avoid bloating the ELFYAML::Foo classes with a bunch of constructor code). No test, since this is by its very nature unpredictable. I'm pretty sure that one of the sanitizers would catch it immediately though. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184160 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj][ELF] Exit with error status on error.Sean Silva2013-06-17
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184115 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj] Move some classes into anonymous namespaces.Sean Silva2013-06-15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184025 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj] Add support for sh_link via `Link` key.Sean Silva2013-06-15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184022 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj] Add support for sh_addralign via `AddressAlign` key.Sean Silva2013-06-14
| | | | | | | For consistency, change the address in the test case from 0xDEADBEEF to 0xCAFEBABE since 0xCAFEBABE that actually has a 2-byte alignment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183962 91177308-0d34-0410-b5e6-96231b3b80d8
* [yaml2obj] Add support for specifying raw section content.Sean Silva2013-06-13
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183955 91177308-0d34-0410-b5e6-96231b3b80d8