summaryrefslogtreecommitdiffstats
path: root/llvm/tools/yaml2obj
Commit message (Collapse)AuthorAgeFilesLines
* [yaml2obj/ObjectYAML] - Cleanup the error reporting API, add custom errors ↵George Rimar2019-09-131-10/+9
| | | | | | | | | | | | | | | | | | | | | handlers. This is a continuation of the YAML library error reporting refactoring/improvement and the idea by itself was mentioned in the following thread: https://reviews.llvm.org/D67182?id=218714#inline-603404 This performs a cleanup of all object emitters in the library. It allows using the custom one provided by the caller. One of the nice things is that each tool can now print its tool name, e.g: "yaml2obj: error: <text>" Also, the code became a bit simpler. Differential revision: https://reviews.llvm.org/D67445 llvm-svn: 371865
* [yaml2obj] Move core yaml2obj code into lib and include for use in unit testsAlex Brachet2019-08-078-3067/+8
| | | | | | | | | | | | | | Reviewers: jhenderson, rupprecht, MaskRay, grimar, labath Reviewed By: rupprecht Subscribers: gribozavr, mgrang, seiya, mgorny, sbc100, hiraditya, aheejin, jakehehrlich, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65255 llvm-svn: 368119
* Revert "[yaml2obj] Move core yaml2obj code into lib and include for use in ↵Dmitri Gribenko2019-08-068-8/+3067
| | | | | | | | unit tests" This reverts commit r368021, it broke tests. llvm-svn: 368035
* [yaml2obj] Move core yaml2obj code into lib and include for use in unit testsAlex Brachet2019-08-068-3067/+8
| | | | | | | | | | | | | | Reviewers: jhenderson, rupprecht, MaskRay, grimar, labath Reviewed By: rupprecht Subscribers: seiya, mgorny, sbc100, hiraditya, aheejin, jakehehrlich, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65255 llvm-svn: 368021
* [yaml2obj] - Allow overriding sh_entsize for SHT_GNU_versym sections.George Rimar2019-08-051-1/+1
| | | | | | | | | | | This allows to write a test case for one of untested errors in llvm/Object/ELF.h. I did it in this patch to demonstrate. Differential revision: https://reviews.llvm.org/D65394 llvm-svn: 367860
* Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song2019-08-051-1/+1
| | | | | | F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
* Recommit "rL366894: [yaml2obj] - Allow custom fields for the SHT_UNDEF ↵George Rimar2019-07-251-20/+18
| | | | | | | | | | | | | | | | | | sections." With fix: do not use `stat` tool. Original commit message: This is a follow-up refactoring patch for recently introduced functionality which which reduces the code duplication and also makes possible to redefine all possible fields of the first SHT_NULL section (previously it was only possible to set sh_link and sh_size). Differential revision: https://reviews.llvm.org/D65140 llvm-svn: 367003
* Revert "[yaml2obj] - Allow custom fields for the SHT_UNDEF sections."JF Bastien2019-07-241-18/+20
| | | | | | | It fails on macOS with the following error: https://reviews.llvm.org/D65140#1599522 llvm-svn: 366937
* [yaml2obj] - Allow custom fields for the SHT_UNDEF sections.George Rimar2019-07-241-20/+18
| | | | | | | | | | | | This is a follow-up refactoring patch for recently introduced functionality which which reduces the code duplication and also makes possible to redefine all possible fields of the first SHT_NULL section (previously it was only possible to set sh_link and sh_size). Differential revision: https://reviews.llvm.org/D65140 llvm-svn: 366894
* Recommit rr366796 "[Object/ELF.h] - Improve testing of the fields in ↵George Rimar2019-07-241-1/+1
| | | | | | | | | | | | | | | | ELFFile<ELFT>::sections()." With a fix of the issue found by UBSan. Original commit message: This eliminates a one error untested and also introduces a error for one more possible case which lead to crash previously. Differential revision: https://reviews.llvm.org/D64987 llvm-svn: 366886
* Revert "[Object/ELF.h] - Improve testing of the fields in ↵Vlad Tsyrklevich2019-07-231-1/+1
| | | | | | | | | ELFFile<ELFT>::sections()." This reverts commit r366796 because it was causing ubsan buildbot failures. llvm-svn: 366815
* [Object/ELF.h] - Improve testing of the fields in ELFFile<ELFT>::sections().George Rimar2019-07-231-1/+1
| | | | | | | | | | This eliminates a one error untested and also introduces a error for one more possible case which lead to crash previously. Differential revision: https://reviews.llvm.org/D64987 llvm-svn: 366796
* [yaml2obj] - Add a support for defining null sections in YAMLs.George Rimar2019-07-231-5/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | ELF spec shows (Figure 4-10: Section Header Table Entry:Index 0, http://www.sco.com/developers/gabi/latest/ch4.sheader.html) that section header at index 0 (null section) can have sh_size and sh_link fields set to non-zero values. It says (https://docs.oracle.com/cd/E19683-01/817-3677/6mj8mbtc9/index.html): "If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), this member has the value zero and the actual number of section header table entries is contained in the sh_size field of the section header at index 0. Otherwise, the sh_size member of the initial entry contains 0." and: "If the section name string table section index is greater than or equal to SHN_LORESERVE (0xff00), this member has the value SHN_XINDEX (0xffff) and the actual index of the section name string table section is contained in the sh_link field of the section header at index 0. Otherwise, the sh_link member of the initial entry contains 0." At this moment it is not possible to create custom section headers at index 0 using yaml2obj. This patch implements this. Differential revision: https://reviews.llvm.org/D64913 llvm-svn: 366794
* [yaml2elf] - Treat the SHN_UNDEF section as kind of regular section.George Rimar2019-07-231-10/+13
| | | | | | | | | | | | | | We have a logic that adds a few sections implicitly. Though the SHT_NULL section with section number 0 is an exception. In D64913 I want to teach yaml2obj to redefine the null section. And in this patch I add it to the sections list, to make it kind of a regular section. Differential revision: https://reviews.llvm.org/D65087 llvm-svn: 366785
* [yaml2obj] - Change how we handle implicit sections.George Rimar2019-07-221-36/+35
| | | | | | | | | | | | | Instead of having the special list of implicit sections, that are mixed with the sections read from YAML on late stages, I just create the placeholders and add them to the main sections list early. That allows to significantly simplify the code. Differential revision: https://reviews.llvm.org/D64999 llvm-svn: 366677
* [yaml2obj] - Allow overriding the sh_size field.George Rimar2019-07-111-6/+14
| | | | | | | | | | There is no way to set broken sh_size field currently for sections. It can be usefull for writing the test cases. Differential revision: https://reviews.llvm.org/D64401 llvm-svn: 365766
* [yaml2obj] - Allow overriding sh_offset field from the YAML.George Rimar2019-07-021-0/+9
| | | | | | | | | | | Some of our test cases are using objects which has sections with a broken sh_offset field. There was no way to set it from YAML until this patch. Differential revision: https://reviews.llvm.org/D63879 llvm-svn: 364898
* [yaml2obj] - Allow overriding e_shentsize, e_shoff, e_shnum and e_shstrndx ↵George Rimar2019-06-271-4/+10
| | | | | | | | | | | | fields in the YAML. This allows setting different values for e_shentsize, e_shoff, e_shnum and e_shstrndx fields and is useful for producing broken inputs for various test cases. Differential revision: https://reviews.llvm.org/D63771 llvm-svn: 364517
* [yaml2obj/obj2yaml] - Allow having the symbols and sections with duplicated ↵George Rimar2019-06-251-5/+12
| | | | | | | | | | | | names. The patch teaches yaml2obj/obj2yaml to support parsing/dumping the sections and symbols with the same name. A special suffix is added to a name to make it unique. Differential revision: https://reviews.llvm.org/D63596 llvm-svn: 364282
* [yaml2obj] - Convert `ELFState<ELFT>::addSymbols` method to `toELFSymbols` ↵George Rimar2019-06-201-47/+44
| | | | | | | | | | | | | | helper. NFCI. ELFState<ELFT>::addSymbols method looks a bit strange. User code have to create the destination symbols vector outside, add a null symbol and then pass it to addSymbols when it seems the more natural logic is to isolate all work with symbols inside some function, build the list right there and return it. Differential revision: https://reviews.llvm.org/D63493 llvm-svn: 363930
* [yaml2obj/obj2yaml] - Make RawContentSection::Info Optional<>George Rimar2019-06-191-3/+9
| | | | | | | | This allows to customize this field for "implicit" sections properly. Differential revision: https://reviews.llvm.org/D63487 llvm-svn: 363777
* [yaml2obj][MachO] Don't fill dummy data for virtual sectionsSeiya Nuta2019-06-171-3/+15
| | | | | | | | | | | | | | | | | | | Summary: Currently, MachOWriter::writeSectionData writes dummy data (0xdeadbeef) to fill section data areas in the file even if the section is a virtual one. Since virtual sections don't occupy any space in the file, writing dummy data could results the "OS.tell() - fileStart <= Sec.offset" assertion failure. This patch fixes the bug by simply not writing any dummy data for virtual sections. Reviewers: beanz, jhenderson, rupprecht, alexshap Reviewed By: alexshap Subscribers: compnerd, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62991 llvm-svn: 363525
* Revert "Revert r363377: [yaml2obj] - Allow setting custom section types for ↵George Rimar2019-06-141-2/+6
| | | | | | | | | | | | | | | | | | | | implicit sections." LLD test case will be fixed in a following commit. Original commit message: [yaml2obj] - Allow setting custom section types for implicit sections. We were hardcoding the final section type for sections that are usually implicit. The patch fixes that. This also fixes a few issues in existent test cases and removes one precompiled object. Differential revision: https://reviews.llvm.org/D63267 llvm-svn: 363401
* Revert r363377: [yaml2obj] - Allow setting custom section types for implicit ↵Rui Ueyama2019-06-141-6/+2
| | | | | | | | | sections. This reverts commit r363377 because lld's ELF/invalid/undefined-local-symbol-in-dso.test test started failing after this commit. llvm-svn: 363394
* [yaml2obj] - Allow setting custom section types for implicit sections.George Rimar2019-06-141-2/+6
| | | | | | | | | | | | We were hardcoding the final section type for sections that are usually implicit. The patch fixes that. This also fixes a few issues in existent test cases and removes one precompiled object. Differential revision: https://reviews.llvm.org/D63267 llvm-svn: 363377
* [yaml2obj] - Allow setting the custom Address for .strtabGeorge Rimar2019-06-141-3/+2
| | | | | | | | | | | | | Despite the fact that .strtab is non-allocatable, there is no reason to disallow setting the custom address for it. The patch also adds a test case showing we can set any address we want for other implicit sections. Differential revision: https://reviews.llvm.org/D63137 llvm-svn: 363368
* [yaml2obj] - Allow setting cutom Flags for implicit sections.George Rimar2019-06-141-9/+14
| | | | | | | | | With this patch we get ability to set any flags we want for implicit sections defined in YAML. Differential revision: https://reviews.llvm.org/D63136 llvm-svn: 363367
* [yaml2elf] - Check we are able to set custom sh_link for .symtab/.dynsymGeorge Rimar2019-06-111-10/+19
| | | | | | | | | Allow using both custom numeric and string values for Link field of the dynamic and regular symbol tables. Differential revision: https://reviews.llvm.org/D63077 llvm-svn: 363042
* [yaml2obj/obj2yaml] - Make RawContentSection::Content and ↵George Rimar2019-06-101-35/+59
| | | | | | | | | | | | | | | | RawContentSection::Size optional This is a follow-up for D62809. Content and Size fields should be optional as was discussed in comments of the D62809's thread. With that, we can describe a specific string table and symbol table sections in a more correct way and also show appropriate errors. The patch adds lots of test cases where the behavior is described in details. Differential revision: https://reviews.llvm.org/D62957 llvm-svn: 362931
* [yaml2obj] - Do not assert when .dynsym is specified explicitly, but .dynstr ↵George Rimar2019-06-101-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | is not present. We have a code in buildSectionIndex() that adds implicit sections: // Add special sections after input sections, if necessary. for (StringRef Name : implicitSectionNames()) if (SN2I.addName(Name, SecNo)) { // Account for this section, since it wasn't in the Doc ++SecNo; DotShStrtab.add(Name); } The problem arises when .dynsym is specified explicitly and no DynamicSymbols is used. In that case, we do not add .dynstr implicitly and will assert later when will try to set Link for .dynsym. Seems, in this case, reasonable behavior is to allow Link field to be zero. This is what this patch does. Differential revision: https://reviews.llvm.org/D63001 llvm-svn: 362929
* [yaml2obj] - Remove helper methods that are probably excessive. NFC.George Rimar2019-06-101-17/+4
| | | | | | | | These methods are used only once. One of them is not used at all. Differential revision: https://reviews.llvm.org/D63002 llvm-svn: 362925
* [yaml2elf] - Refactoring followup for D62809George Rimar2019-06-071-44/+35
| | | | | | | | | | This is a refactoring follow-up for D62809 "Change how we handle implicit sections.". It allows to simplify the code. Differential revision: https://reviews.llvm.org/D62912 llvm-svn: 362777
* [yaml2obj] - Change how we handle implicit sections.George Rimar2019-06-051-62/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have a few sections that can be added implicitly to the output: ".dynsym", ".dynstr", ".symtab", ".strtab" and ".shstrtab". Problem appears when such section is listed explicitly in YAML. In that case it's content is written twice: first time during writing of regular sections listed in the document and second time during special handling. Because of that their file offsets can become unexpectedly broken: (yaml file for sample below lists .dynsym explicitly before .text.foo) Before patch: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .dynsym DYNSYM 0000000000000100 00000250 0000000000000030 0000000000000018 A 6 0 8 [ 2] .text.foo PROGBITS 0000000000000200 00000200 0000000000000000 0000000000000000 AX 0 0 0 After patch: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .dynsym DYNSYM 0000000000000100 00000200 0000000000000030 0000000000000018 A 6 0 8 [ 2] .text.foo PROGBITS 0000000000000200 00000230 0000000000000000 0000000000000000 AX 0 0 0 This patch reorganizes our code and fixes the issue described. Differential revision: https://reviews.llvm.org/D62809 llvm-svn: 362602
* [NFC] yaml2obj/yam2elf.cpp whitespace changes: dos2unix removed CRs.Puyan Lotfi2019-05-111-32/+32
| | | | llvm-svn: 360527
* [COFF] Fix .bss section size bug in obj2yaml / yaml2objReid Kleckner2019-05-101-2/+3
| | | | | | | | | We need to serialize SizeOfRawData through even when there is no data, as in a .bss section. Fixes PR41836 llvm-svn: 360473
* [yaml2obj] - Allow setting st_value explicitly for Symbol.George Rimar2019-05-071-46/+53
| | | | | | | | | | In some cases it is useful to explicitly set symbol's st_name value. For example, I am using it in a patch for LLD to remove the broken binary from a test case and replace it with a YAML test. Differential revision: https://reviews.llvm.org/D61180 llvm-svn: 360137
* [WebAssembly] Add more test coverage for reloctions against section symbolsSam Clegg2019-05-071-5/+0
| | | | | | | | | | | | | The only known user of this relocation type and symbol type is the debug info sections, but we were not testing the `--relocatable` output path. This change adds a minimal test case to cover relocations against section symbols includes `--relocatable` output. Differential Revision: https://reviews.llvm.org/D61623 llvm-svn: 360110
* [yaml2obj] - Make interface of `NameToIdxMap` class be human friendly and ↵George Rimar2019-05-021-77/+78
| | | | | | | | | | | | | fix users. This patch inverses the values returned by `addName` and `lookup` methods of the class mentioned so that they now return true on success and false on failure. Also, it does minor code cleanup. Differential revision: https://reviews.llvm.org/D61190 llvm-svn: 359818
* [yaml2obj] - Report when unknown section is referenced from program header ↵George Rimar2019-05-011-28/+24
| | | | | | | | | | | | declaration block. Previously we did not report this. Also this removes multiple lookups in the map what cleanups the code. Differential revision: https://reviews.llvm.org/D61322 llvm-svn: 359663
* [yaml2obj] - Simplify and reduce the code. NFC.George Rimar2019-04-291-17/+8
| | | | | | | | | | | This inlines 2 single line static methods and simplifies the code. It is also possible to remove the `Is64Bit` variable since it is used only once, but I am not sure it will be better for readability. llvm-svn: 359445
* [yaml2obj] - Replace a loop with write_zeros(). NFCI.George Rimar2019-04-291-2/+1
| | | | | | This looks better. llvm-svn: 359444
* [yaml2obj] - Cleanup and simplify the code. NFCI.George Rimar2019-04-291-12/+15
| | | | | | | | | | | | | | The current code has the following problems: `initSymtabSectionHeader` and `initStrtabSectionHeader` method names saying us they are going to initialize the section headers. Though for a few cases sh_flags field is initialized outside of them. It does not look clean. This patch moves initialization of the sh_flags inside these methods. Also, it removes an excessive variable, what together with the above change hopefully makes the code a bit more readable. llvm-svn: 359443
* [yaml2obj] - Make implicitSectionNames() return std::vector<StringRef>. NFCI.George Rimar2019-04-261-4/+4
| | | | | | | No need to use SmallVector of char* here. This simplifies the code. llvm-svn: 359301
* [yaml2obj] - Remove excessive variable. NFC.George Rimar2019-04-261-3/+3
| | | | | | `auto &Strtab` was used only once. llvm-svn: 359300
* [yaml2obj] - Make the code to match the LLVM style. NFCI.George Rimar2019-04-261-7/+7
| | | | | | | This renames the variables to uppercase and removes use of `auto` for unobvious type. llvm-svn: 359298
* [yaml2elf] - Cleanup the initSectionHeaders(). NFCI.George Rimar2019-04-261-67/+74
| | | | | | | | This encapsulates the section specific code inside the corresponding writeSectionContent methods. Making the code a bit more consistent. llvm-svn: 359297
* [yaml2obj] - Don't crash on invalid inputs.George Rimar2019-04-251-5/+1
| | | | | | | | | | | | | | yaml2obj might crash on invalid input when unable to parse the YAML. Recently a crash with a very similar nature was fixed for an empty files. This patch revisits the fix and does it in yaml::Input instead. It seems to be more correct way to handle such situation. With that crash for invalid inputs is also fixed now. Differential revision: https://reviews.llvm.org/D61059 llvm-svn: 359178
* [yaml2obj] Replace num_zeros with write_zerosFangrui Song2019-04-241-35/+24
| | | | llvm-svn: 359091
* [yaml2elf] - Replace a loop with write_zeros(). NFC.George Rimar2019-04-241-6/+5
| | | | | | And apply clang-format to the method changed. llvm-svn: 359090
* [yaml2elf/obj2yaml] - Allow normal parsing/dumping of the .rela.dyn sectionGeorge Rimar2019-04-181-2/+3
| | | | | | | | | | | | | | | .rela.dyn is a section that has sh_info normally set to zero. And Info is an optional field in the description of the relocation section in YAML. But currently, yaml2obj would fail to produce the object when Info is not explicitly listed. The patch fixes the issue. Differential revision: https://reviews.llvm.org/D60820 llvm-svn: 358656
OpenPOWER on IntegriCloud