aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ObjectYAML/MachOYAML.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-06[SystemZ][z/OS] add back headers needed for strnlen, autoconversionAbhina Sreeskantharajan1-0/+1
2025-06-04[llvm] Remove unused includes (NFC) (#142733)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-01-23[YAML] Don't validate `Fill::Size` after error (#123280)Vitaly Buka1-1/+4
Size is required, so we don't know if it's in uninitialized state after the previous error. Triggers msan on llvm/test/tools/yaml2obj/ELF/custom-fill.yaml NOSIZE test. We have `Fill` Section with Pattern, but no size. Before the fix it produced error: ``` YAML:169:5: error: missing required key 'Size' - Type: Fill ^ YAML:169:5: error: "Size" can't be 0 when "Pattern" is not empty - Type: Fill ``` The same applies to `MachOYAML::Section` fields `content` and `size`. However `MachOYAML::Section` matches size first, so on error, content is not set anyway. Added error checking just in case.
2024-11-17[ObjectYAML] Remove unused includes (NFC) (#116530)Kazu Hirata1-2/+0
Identified with misc-include-cleaner.
2023-12-13[SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures ↵Abhina Sree1-0/+1
(#75339) This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files.
2023-09-05[llvm-nm][MachO] Add support for `MH_FILESET`Antonio Frighetto1-1/+2
Support printing of symbols for MachO of `MH_FILESET` type. This is achieved by extending `dumpSymbolNamesFromObject` to encompass fileset handling, and including an offset in `MachOObjectFile` class to locate embedded MachO headers. Differential Revision: https://reviews.llvm.org/D159294
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2022-11-11[ObjectYAML] Basic support for chained fixups.Daniel Rodríguez Troitiño1-1/+2
Add basic binary support for chained fixups. This allows basic tests with chained fixups without trying to create a format for them until the work on the Object library is considered finished. Reviewed By: pete Differential Revision: https://reviews.llvm.org/D134250
2022-10-04[ObjectYAML] Support for basic data in code.Daniel Rodríguez Troitiño1-1/+10
This is a split of D134250. Supports for parsing and dumping the LC_DATA_IN_CODE contents (as binary data). This allows more complete testing of llvm-objdump in D133974. Reviewed By: Higuoxing Differential Revision: https://reviews.llvm.org/D134569
2022-08-24[llvm] Teach LLVM about filesetsJonas Devlieghere1-0/+7
Teach LLVM about filesets. Filesets were added in macOS 11 (Big Sur) to combine multiple Mach-O files. They introduce a new load command (LC_FILESET_ENTRY) consisting of a fileset_entry_command. struct fileset_entry_command { uint32_t cmd; /* LC_FILESET_ENTRY */ uint32_t cmdsize; /* includes entry_id string */ uint64_t vmaddr; /* memory address of the entry */ uint64_t fileoff; /* file offset of the entry */ union lc_str entry_id; /* contained entry id */ uint32_t reserved; /* reserved */ }; This patch teaches LLVM about the new load command and the corresponding data. Differential revision: https://reviews.llvm.org/D132432
2022-02-13[ObjectYAML][MachO] Add LC_FUNCTION_STARTS supportKeith Smiley1-4/+5
This adds support for encoding and decoding the LC_FUNCTION_STARTS load command payload. Differential Revision: https://reviews.llvm.org/D119205
2021-11-30[ObjectYAML/obj2yaml/yaml2obj][MachO] Support indirect symbol tableVincent Lee1-0/+1
Tools such as `llvm-objdump` or `llvm-readobj` support indirect symbol tables. Here, support it for `obj2yaml` and `yaml2obj`. Reviewed By: jhenderson, drodriguez Differential Revision: https://reviews.llvm.org/D114410
2021-11-08Extend obj2yaml to optionally preserve raw __LINKEDIT/__DATA segments.Adrian Prantl1-0/+3
I am planning to upstream MachOObjectFile code to support Darwin chained fixups. In order to test the new parser features we need a way to produce correct (and incorrect) chained fixups. Right now the only tool that can produce them is the Darwin linker. To avoid having to check in binary files, this patch allows obj2yaml to print a hexdump of the raw LINKEDIT and DATA segment, which both allows to bootstrap the parser and enables us to easily create malformed inputs to test error handling in the parser. This patch adds two new options to obj2yaml: -raw-data-segment -raw-linkedit-segment Differential Revision: https://reviews.llvm.org/D113234
2021-07-28[llvm-objcopy][MachO] Ignore all LC_SUB_* commands.Daniel Rodríguez Troitiño1-0/+24
The LC_SUB_FRAMEWORK, LC_SUB_UMBRELLA, LC_SUB_CLIENT, and LC_SUB_LIBRARY are used to indicate related libraries, binaries or framework names. Their only payload is the string with the name of the object. Adding those commands to the list of ignored/skipped load commands will avoid an error that stop the process of copying/stripping and will copy their contents verbatim. Additionally, in order to have a test for this case, `yaml2obj` now allows those four commands to contain a `Content`. Differential Revision: https://reviews.llvm.org/D106412
2021-07-26[yaml2obj][MachO] Rename PayloadString to ContentFangrui Song1-3/+3
The new name is conciser and matches yaml2obj ELF & DWARF. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D106759
2020-10-20Reland "[yaml2obj][ELF] - Simplify the code that performs sections validation."Georgii Rymar1-2/+2
This reverts commit 1b589f4d4db27e3fcd81fdc5abeb9407753ab790 and relands the D89463 with the fix: update `MappingTraits<FileFilter>::validate()` in ClangTidyOptions.cpp to match the new signature (change the return type to "std::string" from "StringRef"). Original commit message: This: Changes the return type of MappingTraits<T>>::validate to std::string instead of StringRef. It allows to create more complex error messages. It introduces std::vector<std::pair<StringRef, bool>> getEntries(): a new virtual method of Section, which is the base class for all sections. It returns names of special section specific keys (e.g. "Entries") and flags that says if them exist in a YAML. The code in validate() uses this list of entries descriptions to generalize validation. This approach was discussed in the D89039 thread. Differential revision: https://reviews.llvm.org/D89463
2020-10-20Revert "[yaml2obj][ELF] - Simplify the code that performs sections validation."Georgii Rymar1-2/+2
This reverts commit b9e2b59680ad1bbfd2b9110b3ebf3d2b22cad51b.
2020-10-20[yaml2obj][NFCI] - Address post commit comments for "[yaml2obj][ELF] - ↵Georgii Rymar1-1/+1
Simplify the code that performs sections validation." This addresses post commit comments for D89463.
2020-10-20[yaml2obj][ELF] - Simplify the code that performs sections validation.Georgii Rymar1-1/+1
This: 1) Changes the return type of `MappingTraits<T>>::validate` to `std::string` instead of `StringRef`. It allows to create more complex error messages. 2) It introduces std::vector<std::pair<StringRef, bool>> getEntries(): a new virtual method of Section, which is the base class for all sections. It returns names of special section specific keys (e.g. "Entries") and flags that says if them exist in a YAML. The code in validate() uses this list of entries descriptions to generalize validation. This approach was discussed in the D89039 thread. Differential revision: https://reviews.llvm.org/D89463
2020-07-14[DWARFYAML] Replace Is64bit with Is64BitAddrSize. NFC.Xing GUO1-2/+2
Is64bit is ambiguous. In this patch, we replace it with Is64BitAddrSize to make it clearer.
2020-06-14[ObjectYAML][DWARF] Let the target address size be inferred from FileHeader.Xing GUO1-0/+2
This patch adds a new field `bool Is64bit` in `DWARFYAML::Data` to indicate the address size of target. It's helpful for inferring the `AddrSize` in some DWARF sections. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D81709
2020-04-22[ObjectYAML][MachO] Add support for relocationsAlexander Shaposhnikov1-0/+13
Add support for relocations for MachO to ObjectYAML / yaml2obj / obj2yaml. Test plan: make check-all Differential revision: https://reviews.llvm.org/D77844
2019-08-20[yaml2obj/obj2yaml][MachO] Allow setting custom section dataSeiya Nuta1-0/+9
Reviewers: alexshap, jhenderson, rupprecht Reviewed By: alexshap, jhenderson Subscribers: abrachet, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65799 llvm-svn: 369348
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2017-12-18[YAML] Add support for non-printable charactersFrancis Visoiu Mistrih1-2/+6
LLVM IR function names which disable mangling start with '\01' (https://www.llvm.org/docs/LangRef.html#identifiers). When an identifier like "\01@abc@" gets dumped to MIR, it is quoted, but only with single quotes. http://www.yaml.org/spec/1.2/spec.html#id2770814: "The allowed character range explicitly excludes the C0 control block allowed), the surrogate block #xD800-#xDFFF, #xFFFE, and #xFFFF." http://www.yaml.org/spec/1.2/spec.html#id2776092: "All non-printable characters must be escaped. [...] Note that escape sequences are only interpreted in double-quoted scalars." This patch adds support for printing escaped non-printable characters between double quotes if needed. Should also fix PR31743. Differential Revision: https://reviews.llvm.org/D41290 llvm-svn: 320996
2017-09-13llvm-dwarfdump: support dumping UUIDs of Mach-O binaries.Adrian Prantl1-5/+1
This is a feature supported by Darwin dwarfdump. UUIDs are used to associate executables with their .dSYM bundles. llvm-svn: 313165
2017-07-01[ObjectYAML] Fix some Clang-tidy modernize and Include What You Use ↵Eugene Zelenko1-38/+12
warnings; other minor fixes (NFC). llvm-svn: 306925
2017-06-07Move Object format code to lib/BinaryFormat.Zachary Turner1-2/+2
This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
2017-01-23Add LC_BUILD_VERSION load commandSteven Wu1-0/+21
Summary: Add a new load command LC_BUILD_VERSION. It is a generic version of LC_*_VERSION_MIN load_command used on Apple platforms. Instead of having a seperate load command for each platform, LC_BUILD_VERSION is recording platform info as an enum. It also records SDK version, min_os, and tools that used to build the binary. rdar://problem/29781291 Reviewers: enderby Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29044 llvm-svn: 292824
2017-01-19Add support for the new LC_NOTE load command.Kevin Enderby1-0/+8
It describes a region of arbitrary data included in a Mach-O file. Its initial use is to record extra data in MH_CORE files. rdar://30001545 rdar://30001731 llvm-svn: 292500
2016-12-22[ObjectYAML] MachO support for endiannessChris Bieneman1-0/+5
This patch adds support to the macho<->yaml tools for preserving endianness in MachO structures and DWARF data. llvm-svn: 290381
2016-12-07[ObjectYAML] Pull DWARF support into DWARFYAML namespaceChris Bieneman1-24/+0
Since DWARF formatting is agnostic to the object file it is stored in, it doesn't make sense for this to be in the MachOYAML implementation. Pulling it into its own namespace means we could modify the ELF and COFF YAML tools to emit DWARF as well. In a follow-up patch I will better abstract this in obj2yaml and yaml2obj so that the DWARF bits in the tools can be re-used too. llvm-svn: 288984
2016-12-07[ObjectYAML] Rename DWARF entries to match section namesChris Bieneman1-2/+2
This change makes the yaml tags for the members of the DWARF data match the names of the DWARF sections. llvm-svn: 288981
2016-12-07[ObjectYAML] Support for DWARF __debug_abbrev sectionChris Bieneman1-2/+17
This patch adds support for round-tripping DWARF debug abbreviations through the obj<->yaml tools. llvm-svn: 288955
2016-12-06[ObjectYAML] First bit of support for encoding DWARF in MachOChris Bieneman1-1/+16
This patch adds the starting support for encoding data from the MachO __DWARF segment. The first section supported is the __debug_str section because it is the simplest. llvm-svn: 288774
2016-08-17[macho2yaml] Don't write empty linkedit dataChris Bieneman1-1/+6
Since I stopped writing empty export tries it causes LinkEdit to potentially be completely empty which results in invalid yaml being generated. To prevent this we skip linkedit data if it is empty. llvm-svn: 278985
2016-08-11[MachOYAML] Don't output empty ExportTrieChris Bieneman1-1/+2
The YAML representation was always outputting the root node of an export trie even if the trie was empty. While this doesn't really have any functional impact, it does add visual clutter to the yaml file. llvm-svn: 278307
2016-06-28[YAML] Fix YAML tags appearing before the start of sequence elementsChris Bieneman1-1/+1
Our existing yaml::Output code writes tags immediately when mapTag is called, without any state handling. This results in tags on sequence elements being written before the element itself. For example, we see this: SomeArray: !elem_type - key1: 1 key2: 2 !elem_type2 - key3: 3 key4: 4 We should instead see: SomeArray: - !elem_type key1: 1 key2: 2 - !elem_type2 key3: 3 key4: 4 Our reader handles reading properly, so this bug only impacts writing yaml sequences with tagged elements. As a test for this I've modified the Mach-O yaml encoding to allways apply the !mach-o tag when encoding MachOYAML::Object entries. This results in the !mach-o tag appearing as expected in dumped fat files. llvm-svn: 274067
2016-06-27[yaml2obj] Remove --format option in favor of YAML tagsChris Bieneman1-28/+0
Summary: Our YAML library's handling of tags isn't perfect, but it is good enough to get rid of the need for the --format argument to yaml2obj. This patch does exactly that. Instead of requiring --format, it infers the format based on the tags found in the object file. The supported tags are: !ELF !COFF !mach-o !fat-mach-o I have a corresponding patch that is quite large that fixes up all the in-tree test cases. Reviewers: rafael, Bigcheese, compnerd, silvas Subscribers: compnerd, llvm-commits Differential Revision: http://reviews.llvm.org/D21711 llvm-svn: 273915
2016-06-24[obj2yaml] [yaml2obj] Support for MachO Universal binariesChris Bieneman1-1/+62
This patch adds round-trip support for MachO Universal binaries to obj2yaml and yaml2obj. Universal binaries have a header and list of architecture structures, followed by a the individual object files at specified offsets. llvm-svn: 273719
2016-06-23[MachOYAML] Use a temporary to avoid gcc strict-aliasing warningChris Bieneman1-2/+4
GCC complains about this with -Wstrict-aliasing. Using a temporary here should prevent the warning. llvm-svn: 273627
2016-06-23[yaml2macho] Removing asserts in favor of explicit yaml parse errorChris Bieneman1-2/+4
32-bit Mach headers don't have reserved fields. When generating the mapping for 32-bit headers leaving off the reserved field will result in parse errors if the field is present in the yaml. Added a CHECK-NOT line to ensure that mach_header.yaml isn't adding a reserved field, and a test to ensure that the parser error gets hit with 32-bit headers. llvm-svn: 273623
2016-06-02[obj2yaml] [yaml2obj] Support for MachO nlist and string tableChris Bieneman1-0/+11
This commit adds round tripping for MachO symbol data. Symbols are entries in the name list, that contain offsets into the string table which is at the end of the __LINKEDIT segment. llvm-svn: 271604
2016-05-31[obj2yaml][yaml2obj] Support for reading and dumping the MachO export trieChris Bieneman1-0/+19
The MachO export trie is a serially encoded trie keyed by symbol name. This code parses the trie and preserves the structure so that it can be dumped again. llvm-svn: 271300
2016-05-26[obj2yaml][yaml2obj] Support for MachO lazy bindingsChris Bieneman1-0/+1
This adds support for YAML round tripping dyld info lazy bindings. The storage and format of these is the same as regular bind opcodes, they are just interpreted differently by dyld, and can have DONE opcodes in the middle of the opcode lists. llvm-svn: 270920
2016-05-26[obj2yaml][yaml2obj] Support for MachO weak bindingsChris Bieneman1-0/+1
This adds support for YAML round tripping dyld info weak bindings. The storage and format of these is the same as regular bind opcodes, they are just interpreted differently by dyld. llvm-svn: 270911
2016-05-26[obj2yaml][yaml2obj] Support for MachO bind opcodesChris Bieneman1-4/+14
This adds support for YAML round tripping dyld info bind opcodes. Bind opcodes can have signed or unsigned LEB128 data, and they can have symbols associated with them. llvm-svn: 270901
2016-05-25[obj2yaml] [yaml2obj] MachO support for rebase opcodesChris Bieneman1-0/+13
This is the first bit of support for MachO __LINKEDIT segment data. llvm-svn: 270724
2016-05-20[MachOYAML] Removing duplicated field from LC_UUID YAMLChris Bieneman1-1/+0
The uuid_command was duplicating the load_command.cmdsize field. This removes the duplicate from the YAML mapping and from the test cases. llvm-svn: 270248
2016-05-19[obj2yaml] [yaml2obj] Support for MachO Load Command dataChris Bieneman1-4/+30
This re-applies r270115. Many of the MachO load commands can have data appended after the command structure. This data is frequently strings, but can actually be anything. This patch adds support for three optional fields on load command yaml descriptions. The new PayloadString YAML field is populated with the data after load commands known to have strings as extra data. The new ZeroPadBytes YAML field is a count of zero'd bytes after the end of the load command structure before the next command. This can apply anywhere in the file. MachO2YAML verifies that bytes are zero before populating this field, and YAML2MachO will add zero'd bytes. The new PayloadBytes YAML field stores all bytes after the end of the load command structure before the next command if they are non-zero. This is a catch all for all unhandled bytes. If MachO2Yaml populates PayloadBytes it will not populate ZeroPadBytes, instead zero'd bytes will be in the PayloadBytes structure. llvm-svn: 270124