aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
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.
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-9/+9
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-12-13[llvm][Object] set SF_Hidden flag for MachO filesCyndy Ishida1-2/+6
Reviewed By: pete, ributzka Differential Revision: https://reviews.llvm.org/D139862
2022-12-10Don't include None.h (NFC)Kazu Hirata1-1/+0
I've converted all known uses of None to std::nullopt, so we no longer need to include None.h. 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-12-09Revert D139098 "[Alignment] Use Align for ObjectFile::getSectionAlignment"Guillaume Chatelet1-3/+10
This breaks lld. This reverts commit 10c47465e2505ddfee4e62a2ab2e535abea3ec56.
2022-12-09[Alignment] Use Align for ObjectFile::getSectionAlignmentGuillaume Chatelet1-10/+3
Differential Revision: https://reviews.llvm.org/D139098
2022-12-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-1/+1
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-12-04[Object] llvm::Optional => std::optionalFangrui Song1-2/+2
2022-12-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata1-16/+16
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. 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-11-22[MachO] Support exports trie in both LC_DYLD_INFO and LC_DYLD_EXPORTS_TRIEDaniel Rodríguez Troitiño1-9/+34
The exports trie used to be pointed by the information in LC_DYLD_INFO, but when chained fixups are present, the exports trie is pointed by LC_DYLD_EXPORTS_TRIE instead. Modify the Object library to give access to the information pointed by each of the load commands, and to fallback from one into the other when the exports are requested. Modify ObjectYAML to support dumping the export trie when pointed by LC_DYLD_EXPORTS_TRIE and to parse the existence of a export trie also when the load command is present. This is a split of D134250 with improvements on top. Reviewed By: alexander-shaposhnikov Differential Revision: https://reviews.llvm.org/D134571
2022-09-23[objdump] Fix typo in error message.Daniel Rodríguez Troitiño1-1/+1
Change "inconsistant" for "inconsistent" in the message, the file name and the test output. Reviewed By: pete, MaskRay Differential Revision: https://reviews.llvm.org/D134562
2022-09-08[llvm] Use std::size instead of llvm::array_lengthofJoe Loser1-1/+1
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133429
2022-08-28[llvm-objdump] Add -dyld_info to llvm-otoolDaniel Bertalan1-10/+176
This option outputs the location, encoded value and target of chained fixups, using the same format as `otool -dyld_info`. This initial implementation only supports the DYLD_CHAINED_PTR_64 and DYLD_CHAINED_PTR_64_OFFSET pointer encodings, which are used in x86_64 and arm64 userspace binaries. When Apple's effort to upstream their chained fixups code continues, we'll replace this code with the then-upstreamed code. But we need something in the meantime for testing ld64.lld's chained fixups code. Differential Revision: https://reviews.llvm.org/D132036
2022-08-24[llvm-objdump] Complete -chained_fixups supportDaniel Bertalan1-2/+110
This commit adds definitions for the `dyld_chained_import*` structs. The imports array is now printed with `llvm-otool -chained_fixups`. This completes this option's implementation. A slight difference from cctools otool is that we don't yet dump the raw bytes of the imports entries. When Apple's effort to upstream their chained fixups code continues, we'll replace this code with the then-upstreamed code. But we need something in the meantime for testing ld64.lld's chained fixups code. Differential Revision: https://reviews.llvm.org/D131982
2022-08-18[llvm-objdump] Support dumping segment information with -chained_fixupsDaniel Bertalan1-7/+111
This commit adds the definitions for `dyld_chained_starts_in_image`, `dyld_chained_starts_in_segment`, and related enums. Dumping their contents is possible with the -chained_fixups flag of llvm-otool. The chained-fixups.yaml test was changed to cover bindings/rebases, as well as weak imports, weak symbols and flat namespace symbols. Now that we have actual fixup entries, the __DATA segment contains data that would need to be hexdumped in YAML. We also test empty pages (to look for the "DYLD_CHAINED_PTR_START_NONE" annotation), so the YAML would end up quite large. So instead, this commit includes a binary file. When Apple's effort to upstream their chained fixups code continues, we'll replace this code with the then-upstreamed code. But we need something in the meantime for testing ld64.lld's chained fixups code. Differential Revision: https://reviews.llvm.org/D131961
2022-06-15[llvm] Fix MachO exports trie parsing.Juergen Ributzka1-1/+3
The exports trie parser ordinal validation check doesn't consider the case where the ordinal can be zero or negative for certain special values that are defined in BindSpecialDylib. Update the validation to account for that fact and add a test case. This fixes rdar://94844233. Differential Revision: https://reviews.llvm.org/D127806
2022-03-17[dsymutil] Apply relocations present in Swift reflection sectionsAugusto Noronha1-0/+20
The strippable Swift reflection sections contain subtractor relocations that need to be applied. There are two situations we need to support. 1) Both symbols used in the relocation come from the .o file (for example, one symbol lives in __swift5_fieldmd and the second in __swift5_reflstr). 2) One symbol comes from th .o file and the second from the main binary (for example, __swift5_fieldmd and __swift5_typeref). Differential Revision: https://reviews.llvm.org/D120574
2022-02-25Validate chained fixup image formatsAdrian Prantl1-13/+41
This is part of a series of patches to upstream support for Mach-O chained fixups. Differential Revision: https://reviews.llvm.org/D113725
2022-02-22[NFC] Remove dead code (try 2)Arthur Eubanks1-7/+5
This is causing ../../llvm/include/llvm/Object/MachO.h:379:13: warning: private field 'Kind' is not used [-Wunused-private-field] FixupKind Kind; Previous attempt in a23f7c0cb6b42a06bc9707fdf46ce2a90080f61f.
2022-02-22Add support for chained fixup load commands to MachOObjectFileAdrian Prantl1-3/+158
This is part of a series of patches to upstream support for Mach-O chained fixups. This patch adds support for parsing the chained fixup load command and parsing the chained fixups header. It also puts into place the abstract interface that will be used to iterate over the fixups. Differential Revision: https://reviews.llvm.org/D113630
2022-02-13[ObjectYAML][MachO] Add LC_FUNCTION_STARTS supportKeith Smiley1-1/+15
This adds support for encoding and decoding the LC_FUNCTION_STARTS load command payload. Differential Revision: https://reviews.llvm.org/D119205
2022-02-10Cleanup LLVMObject headersserge-sans-paille1-1/+1
Most notably, llvm/Object/Binary.h no longer includes llvm/Support/MemoryBuffer.h llvm/Object/MachOUniversal*.h no longer include llvm/Object/Archive.h llvm/Object/TapiUniversal.h no longer includes llvm/Object/TapiFile.h llvm-project preprocessed size: before: 1068185081 after: 1068324320 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119457
2022-02-01Change namespace llvm::swift to namespace llvm::binaryformat because of ↵Shubham Sandeep Rastogi1-4/+5
clashes with the apple/llvm-project repository The namespace llvm::swift is causing errors to pop up in the apple/llvm-project build when cherry-picking 4ce1f3d47c33 into apple/llvm-project Differential Review: https://reviews.llvm.org/D118716
2022-01-28Emit swift5 reflection section data in dsym bundle generated by dsymutil in ↵Shubham Sandeep Rastogi1-0/+12
the Dwarf section. Add support for Swift reflection metadata to dsymutil. This patch adds support for copying Swift reflection metadata (__swift5_.* sections) from .o files to into the symbol-rich binary in the output .dSYM. The functionality is automatically enabled only if a .o file has reflection metadata sections and the binary doesn't. When copying dsymutil moves the section from the __TEXT segment to the __DWARF segment. rdar://76973336 Differential Revision: https://reviews.llvm.org/D115007
2022-01-26Revert "Emit swift5 reflection section data in dsym bundle generated by ↵Shubham Sandeep Rastogi1-12/+0
dsymutil in the Dwarf section." This reverts commit 50f50f2582993a079dbcfb8e7ba48920f41e6be0.
2022-01-26Emit swift5 reflection section data in dsym bundle generated by dsymutil in ↵Shubham Sandeep Rastogi1-0/+12
the Dwarf section. Add support for Swift reflection metadata to dsymutil. This patch adds support for copying Swift reflection metadata (__swift5_.* sections) from .o files to into the symbol-rich binary in the output .dSYM. The functionality is automatically enabled only if a .o file has reflection metadata sections and the binary doesn't. When copying dsymutil moves the section from the __TEXT segment to the __DWARF segment. rdar://76973336 Differential Revision: https://reviews.llvm.org/D115007
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-1/+1
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-1/+1
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2022-01-21Revert "Emit swift5 reflection section data in dsym bundle generated by ↵Shubham Sandeep Rastogi1-12/+0
dsymutil in the Dwarf section." This reverts commit d84d1135d80c1dead6564347943ba56eed5aac3b. to investigate buildbot failures
2022-01-21Emit swift5 reflection section data in dsym bundle generated by dsymutil in ↵Shubham Sandeep Rastogi1-0/+12
the Dwarf section. Add support for Swift reflection metadata to dsymutil. This patch adds support for copying Swift reflection metadata (__swift5_.* sections) from .o files to into the symbol-rich binary in the output .dSYM. The functionality is automatically enabled only if a .o file has reflection metadata sections and the binary doesn't. When copying dsymutil moves the section from the __TEXT segment to the __DWARF segment. rdar://76973336 https://reviews.llvm.org/D115007
2021-12-15[dwarf][NFC] Move expandBundle() to MachO.hEllis Hoag1-0/+46
The function `expandBundle()` is defined both in `llvm-dwarfdump.cpp` and `llvm-gsymutil.cpp` in the exact same way. Reduce code duplication by moving this function to the `MachOObjectFile` class. Reviewed By: jhenderson, clayborg Differential Revision: https://reviews.llvm.org/D115418
2021-11-08Extend obj2yaml to optionally preserve raw __LINKEDIT/__DATA segments.Adrian Prantl1-0/+40
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-09-20MachOObjectFile - checkOverlappingElement - use const-ref to avoid ↵Simon Pilgrim1-3/+3
unnecessary copies. NFCI. Reported by MSVC static analyzer.
2021-06-13MachOObjectFile.cpp - remove unused <string> include. NFCI.Simon Pilgrim1-1/+0
2021-05-26[NFC][object] Change the input parameter of the method isDebugSection.Esme-Yi1-1/+8
Summary: This is a NFC patch to change the input parameter of the method SectionRef::isDebugSection(), by replacing the StringRef SectionName with DataRefImpl Sec. This allows us to determine if a section is debug type in more ways than just by section name. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D102601
2021-03-17[Object][MachO] Handle end iterator in getSymbolType()Steven Wu1-0/+2
Fix a bug in MachOObjectFile::getSymbolType() that it is not checking if the iterator is end() before deference the iterator. Instead, return `Other` type, which aligns with the behavior of `llvm-nm`. rdar://75291638 Reviewed By: davide, ab Differential Revision: https://reviews.llvm.org/D98739
2020-12-18[MCA, ExecutionEngine, Object] Use llvm::is_contained (NFC)Kazu Hirata1-1/+1
2020-12-03[Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.Ahmed Bougacha1-5/+26
This also teaches MachO writers/readers about the MachO cpu subtype, beyond the minimal subtype reader support present at the moment. This also defines a preprocessor macro to allow users to distinguish __arm64__ from __arm64e__. arm64e defaults to an "apple-a12" CPU, which supports v8.3a, allowing pointer-authentication codegen. It also currently defaults to ios14 and macos11. Differential Revision: https://reviews.llvm.org/D87095
2020-11-11[MachO] Allow the LC_IDENT load commandVedant Kumar1-0/+3
xnu coredumps include an LC_IDENT load command. It's helpful to be able to just ignore these. IIUC an interested client can grab the identifier using the MachOObjectFile::load_commands() API. The status quo is that llvm bails out when it finds an LC_IDENT because the command is obsolete (see isLoadCommandObsolete). Differential Revision: https://reviews.llvm.org/D91221
2020-11-02[MachO] Also recongize __swift_ast as a debug info sectionJonas Devlieghere1-1/+2
Address post-commit review from Adrian.
2020-10-29[dwarfdump] Recognize __apple sections as debug info sectionsJonas Devlieghere1-1/+2
Recognize the __apple_ sections as debug info sections and make sure they're included in the --show-sections-sizes output. Differential revision: https://reviews.llvm.org/D90433
2020-04-18[Object] Change uint32_t getSymbolFlags() to Expected<uint32_t> ↵vgxbj1-3/+3
getSymbolFlags(). This change enables getSymbolFlags() to return errors which benefit error reporting in clients. Differential Revision: https://reviews.llvm.org/D77860
2020-04-02[Object] Add the method for checking if a section is a debug sectionDjordje Todorovic1-0/+5
Different file formats have different naming style for the debug sections. The method is implemented for ELF, COFF and Mach-O formats. Differential Revision: https://reviews.llvm.org/D76276
2020-03-04Fix dyld opcode *_ADD_ADDR_IMM_SCALED error detection.Michael Trent1-26/+4
Summary: Move the check for malformed REBASE_OPCODE_ADD_ADDR_IMM_SCALED and BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED opcodes after the immediate has been applied to the SegmentOffset. This fixes specious errors where SegmentOffset is pointing between two sections when trying to correct the SegmentOffset value. Update the regression tests to verify the proper error message. Reviewers: pete, ab, lhames, steven_wu, jhenderson Reviewed By: pete Subscribers: hiraditya, dexonsmith, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75629
2020-02-20Revert "[macho][NFC] Extract all CPU_(SUB_)TYPE logic to libObject"Francis Visoiu Mistrih1-89/+0
This reverts commit 726c342ce27ada28efe90cb04ffb69c75065710a. This breaks the windows bots with linker errors.
2020-02-20[macho][NFC] Extract all CPU_(SUB_)TYPE logic to libObjectFrancis Visoiu Mistrih1-0/+89
This moves all the logic of converting LLVM Triples to MachO::CPU_(SUB_)TYPE from the specific target (Target)AsmBackend to more convenient functions in libObject. This also gets rid of the separate two X86AsmBackend classes. Differential Revision: https://reviews.llvm.org/D74808
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling1-2/+2
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling1-2/+2
2019-11-18[macho] Allow CPUSubtype to contribute to architecture identificationDaniel Sanders1-2/+6
Summary: Sometimes the CPUSubtype determines the Triple::ArchType that must be used. Add the subtype to the API's to allow targets that need this to correctly identify the contents of the binary. Reviewers: pete Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70345