aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/yaml2obj
AgeCommit message (Collapse)AuthorFilesLines
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-3/+3
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2022-12-06[YAML] Convert Optional to std::optionalKrzysztof Parzyszek1-3/+4
2022-11-26[yaml2obj] Use std::optional in yaml2obj.cpp (NFC)Kazu Hirata1-1/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-02[yaml2obj] Add a `-E` flag to preprocess only.Simon Tatham1-4/+12
If you're having trouble getting a yaml2obj macro expansion to do what you want, it's useful to be able to print the output of the preprocessing to see what your macros expanded to //before// going into the YAML processing phase. yaml2obj has its own preprocessing system which isn't the same as any other well-known thing like cpp. So there's no way to do this macro expansion via another tool: yaml2obj will have to do it itself. In this commit I add an `-E` flag to yaml2obj to do that. Differential Revision: https://reviews.llvm.org/D130981
2021-11-24Have yaml2obj describe all options in --helpPaul Robinson1-2/+4
Differential Revision: https://reviews.llvm.org/D114538
2020-10-19[llvm] Make obj2yaml and yaml2obj LLVM utilities instead of toolsJonas Devlieghere1-1/+1
For testing purposes I need a way to build and install FileCheck and yaml2obj. I had to choose between making FileCheck an LLVM tool and making obj2yaml and yaml2obj utilities. I think the distinction is rather arbitrary but my understanding is that tools are things meant for the toolchain while utilities are more used for things like testing, which is the case here. The functional difference is that these tools now end up in the ${LLVM_UTILS_INSTALL_DIR}, which defaults to the ${LLVM_TOOLS_INSTALL_DIR}. Unless you specified a different value or you added obj2yaml and yaml2obj to ${LLVM_TOOLCHAIN_TOOLS}, this patch shouldn't change anything. Differential revision: https://reviews.llvm.org/D89357
2020-06-30[yaml2obj] - Add a way to set default values for macros used in a YAML.Georgii Rymar1-3/+15
Currently we have to override all macros that are declared. But in many cases it is convenient to use default values and to override only a particular one or two. This provides a way to set a default value for any macro: ``` Symbols: - Name: [[FOO=foo]] ``` Differential revision: https://reviews.llvm.org/D82455
2020-06-10[yaml2obj] - Introduce a 10 Mb limit of the output by default and a ↵Georgii Rymar1-1/+8
--max-size option. Multiple times we faced an issue of huge outputs due to unexpected behavior or incorrect test cases. The last one was https://reviews.llvm.org/D80629#2073066. This patch limits the output to 10 Mb for ELF and introduces the --max-size to change this limit. I've tried to keep the implementation non-intrusive. The current logic we have is that we prepare section content in a buffer first and write it to the output later. This patch checks the available limit on each writing attempt to this buffer and stops writing when the limit is reached and raises the internal error flag. Later, this flag is is checked before the actual writing to a file happens and an error is reported. Differential revision: https://reviews.llvm.org/D81258
2020-02-07[yaml2obj] Add -D k=v to preprocess the input YAMLFangrui Song1-1/+47
Examples: ``` yaml2obj -D MACHINE=EM_386 a.yaml -o a.o yaml2obj -D MACHINE=0x1234 a.yaml -o a.o ``` where a.yaml contains: ``` --- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2MSB Type: ET_REL Machine: [[MACHINE]] ``` Reviewed By: grimar, jhenderson Differential Revision: https://reviews.llvm.org/D73821
2020-02-06[yaml2obj] Refactor command line parsingFangrui Song1-10/+16
* Hide unrelated options. * Add "OVERVIEW: " to yaml2obj -h/--help. * Place options under a yaml2obj category. * Disallow -docnum. Currently -docnum is the only yaml2obj specific long option that is affected. * Specify `cl::init("-")` and `cl::Prefix` for OutputFilename. The latter allows `-ofile` Reviewed By: grimar, jhenderson Differential Revision: https://reviews.llvm.org/D73982
2020-01-31[yaml2obj] Internlize DocNum. NFCFangrui Song1-3/+3
2019-09-13[yaml2obj/ObjectYAML] - Cleanup the error reporting API, add custom errors ↵George Rimar1-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
2019-08-07[yaml2obj] Move core yaml2obj code into lib and include for use in unit testsAlex Brachet8-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
2019-08-06Revert "[yaml2obj] Move core yaml2obj code into lib and include for use in ↵Dmitri Gribenko8-8/+3067
unit tests" This reverts commit r368021, it broke tests. llvm-svn: 368035
2019-08-06[yaml2obj] Move core yaml2obj code into lib and include for use in unit testsAlex Brachet8-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
2019-08-05[yaml2obj] - Allow overriding sh_entsize for SHT_GNU_versym sections.George Rimar1-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
2019-08-05Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song1-1/+1
F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
2019-07-25Recommit "rL366894: [yaml2obj] - Allow custom fields for the SHT_UNDEF ↵George Rimar1-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
2019-07-24Revert "[yaml2obj] - Allow custom fields for the SHT_UNDEF sections."JF Bastien1-18/+20
It fails on macOS with the following error: https://reviews.llvm.org/D65140#1599522 llvm-svn: 366937
2019-07-24[yaml2obj] - Allow custom fields for the SHT_UNDEF sections.George Rimar1-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
2019-07-24Recommit rr366796 "[Object/ELF.h] - Improve testing of the fields in ↵George Rimar1-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
2019-07-23Revert "[Object/ELF.h] - Improve testing of the fields in ↵Vlad Tsyrklevich1-1/+1
ELFFile<ELFT>::sections()." This reverts commit r366796 because it was causing ubsan buildbot failures. llvm-svn: 366815
2019-07-23[Object/ELF.h] - Improve testing of the fields in ELFFile<ELFT>::sections().George Rimar1-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
2019-07-23[yaml2obj] - Add a support for defining null sections in YAMLs.George Rimar1-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
2019-07-23[yaml2elf] - Treat the SHN_UNDEF section as kind of regular section.George Rimar1-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
2019-07-22[yaml2obj] - Change how we handle implicit sections.George Rimar1-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
2019-07-11[yaml2obj] - Allow overriding the sh_size field.George Rimar1-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
2019-07-02[yaml2obj] - Allow overriding sh_offset field from the YAML.George Rimar1-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
2019-06-27[yaml2obj] - Allow overriding e_shentsize, e_shoff, e_shnum and e_shstrndx ↵George Rimar1-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
2019-06-25[yaml2obj/obj2yaml] - Allow having the symbols and sections with duplicated ↵George Rimar1-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
2019-06-20[yaml2obj] - Convert `ELFState<ELFT>::addSymbols` method to `toELFSymbols` ↵George Rimar1-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
2019-06-19[yaml2obj/obj2yaml] - Make RawContentSection::Info Optional<>George Rimar1-3/+9
This allows to customize this field for "implicit" sections properly. Differential revision: https://reviews.llvm.org/D63487 llvm-svn: 363777
2019-06-17[yaml2obj][MachO] Don't fill dummy data for virtual sectionsSeiya Nuta1-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
2019-06-14Revert "Revert r363377: [yaml2obj] - Allow setting custom section types for ↵George Rimar1-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
2019-06-14Revert r363377: [yaml2obj] - Allow setting custom section types for implicit ↵Rui Ueyama1-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
2019-06-14[yaml2obj] - Allow setting custom section types for implicit sections.George Rimar1-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
2019-06-14[yaml2obj] - Allow setting the custom Address for .strtabGeorge Rimar1-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
2019-06-14[yaml2obj] - Allow setting cutom Flags for implicit sections.George Rimar1-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
2019-06-11[yaml2elf] - Check we are able to set custom sh_link for .symtab/.dynsymGeorge Rimar1-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
2019-06-10[yaml2obj/obj2yaml] - Make RawContentSection::Content and ↵George Rimar1-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
2019-06-10[yaml2obj] - Do not assert when .dynsym is specified explicitly, but .dynstr ↵George Rimar1-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
2019-06-10[yaml2obj] - Remove helper methods that are probably excessive. NFC.George Rimar1-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
2019-06-07[yaml2elf] - Refactoring followup for D62809George Rimar1-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
2019-06-05[yaml2obj] - Change how we handle implicit sections.George Rimar1-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
2019-05-11[NFC] yaml2obj/yam2elf.cpp whitespace changes: dos2unix removed CRs.Puyan Lotfi1-32/+32
llvm-svn: 360527
2019-05-10[COFF] Fix .bss section size bug in obj2yaml / yaml2objReid Kleckner1-2/+3
We need to serialize SizeOfRawData through even when there is no data, as in a .bss section. Fixes PR41836 llvm-svn: 360473
2019-05-07[yaml2obj] - Allow setting st_value explicitly for Symbol.George Rimar1-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
2019-05-07[WebAssembly] Add more test coverage for reloctions against section symbolsSam Clegg1-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
2019-05-02[yaml2obj] - Make interface of `NameToIdxMap` class be human friendly and ↵George Rimar1-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
2019-05-01[yaml2obj] - Report when unknown section is referenced from program header ↵George Rimar1-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