aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2019-09-25[NFC] Add { } to silence compiler warning [-Wmissing-braces].Huihui Zhang1-2/+2
/local/mnt/workspace/huihuiz/llvm-comm-git-2/llvm-project/llvm/lib/Object/MachOObjectFile.cpp:2731:7: warning: suggest braces around initialization of subobject [-Wmissing-braces] "i386", "x86_64", "x86_64h", "armv4t", "arm", "armv5e", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { 1 warning generated. /local/mnt/workspace/huihuiz/llvm-comm-git-2/llvm-project/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp:355:46: warning: suggest braces around initialization of subobject [-Wmissing-braces] return addMappingFromTable<1>(MI, MRI, { 0 }, Table); ^ {} 1 warning generated. /local/mnt/workspace/huihuiz/llvm-comm-git-2/llvm-project/llvm/tools/llvm-objcopy/ELF/Object.cpp:400:57: warning: suggest braces around initialization of subobject [-Wmissing-braces] static constexpr std::array<uint8_t, 4> ZlibGnuMagic = {'Z', 'L', 'I', 'B'}; ^~~~~~~~~~~~~~~~~~ { } 1 warning generated. llvm-svn: 372811
2019-08-20[yaml2obj/obj2yaml][MachO] Allow setting custom section dataSeiya Nuta1-1/+6
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-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-2/+2
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-08-14Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar1-6/+9
Expected<>" Changes: no changes. A fix for the clang code will be landed right on top. Original commit message: SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368826
2019-08-14Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar1-9/+6
Expected<>" It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455 llvm-svn: 368813
2019-08-14[llvm/Object] - Convert SectionRef::getName() to return Expected<>George Rimar1-6/+9
SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368812
2019-08-06Switch LLVM to use 64-bit offsets (2/5)Igor Kudrin1-1/+1
This updates all libraries and tools in LLVM Core to use 64-bit offsets which directly or indirectly come to DataExtractor. Differential Revision: https://reviews.llvm.org/D65638 llvm-svn: 368014
2019-07-18Remove the static initialize introduced in r365099Steven Wu1-9/+11
Summary: Some polish for r365099 which adds a static initializer to MachOObjectFile. Remove it by moving it to file scope. Reviewers: smeenai, alexshap, compnerd, mtrent, anushabasana Reviewed By: smeenai Subscribers: hiraditya, jkorous, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64873 llvm-svn: 366496
2019-07-04[MachO] Add valid architecture functionShoaib Meenai1-19/+10
Added array of valid architectures and function returning array. Modified llvm-lipo to include list of valid architectures in error message for invalid arch. Patch by Anusha Basana <anusha.basana@gmail.com> Differential Revision: https://reviews.llvm.org/D63735 llvm-svn: 365099
2019-06-04[MACHO] Replaced calls to getStruct with getStructOrErr in functions ↵Alex Brachet1-33/+88
returning Error or Expected or similar llvm-svn: 362526
2019-05-14AArch64: support binutils-like things on arm64_32.Tim Northover1-2/+20
This adds support for the arm64_32 watchOS ABI to LLVM's low level tools, teaching them about the specific MachO choices and constants needed to disassemble things. llvm-svn: 360663
2019-05-14[Object] Change ObjectFile::getSectionContents to return ↵Fangrui Song1-4/+3
Expected<ArrayRef<uint8_t>> Change std::error_code getSectionContents(DataRefImpl, StringRef &) const; to Expected<ArrayRef<uint8_t>> getSectionContents(DataRefImpl) const; Many object formats use ArrayRef<uint8_t> as the underlying type, which is generally better than StringRef to represent binary data, so change the type to decrease the number of type conversions. Reviewed By: ruiu, sbc100 Differential Revision: https://reviews.llvm.org/D61781 llvm-svn: 360648
2019-05-02[Object] Change getSectionName() to return Expected<StringRef>Fangrui Song1-7/+4
Summary: It currently receives an output parameter and returns std::error_code. Expected<StringRef> fits for this purpose perfectly. Differential Revision: https://reviews.llvm.org/D61421 llvm-svn: 359774
2019-04-29Remove duplicate line. NFCI.Simon Pilgrim1-1/+0
Reported in https://www.viva64.com/en/b/0629/ llvm-svn: 359483
2019-03-20Fix Mach-O bind and rebase validation errors in libObjectMichael Trent1-116/+62
Summary: llvm-objdump (via libObject) validates DYLD_INFO rebase and bind entries against the basic structure found in the Mach-O file before evaluating the contents of those entries. Certain malformed Mach-Os can defeat the validation check and force llvm-objdump (libObject) to crash. The previous logic verified a rebase or bind started in a valid Mach-O section, but did not verify that the section wholely contained the fixup. It also generally allows rebases or binds to start immediately after a valid section even if that range is not itself part of a valid section. Finally, bind and rebase opcodes that indicate more than one fixup (apply N times...) are not completely validated: only the first and final fixups are checked. The previous logic also rejected certain binaries as false positives. Some bind and rebase opcodes can modify the state machine such that the next bind or rebase will fail. libObject will reject these opcodes as invalid in order to be helpful and print an error message associated with the instruction that caused the problem, even though the binary is not actually illegal until it consumes the invalid state in the state machine. In other words, libObject may reject a Mach-O binary that Apple's dynamic linker may consider legal. The original version of macho-rebase-add-addr-uleb-too-big is an example of such a binary. I have replaced the existing checkSegAndOffset and checkCountAndSkip functions with a single function, checkSegAndOffsets, which validates all of the fixups realized by a DYLD_INFO opcode. checkSegAndOffsets verifies that a Mach-O section fully contains each fixup. Every fixup realized by an opcode is validated, and some (but not all!) inconsistencies in the state machine are allowed until a fixup is realized. This means that libObject may fail on an opcode that realizes a fixup, not on the opcode that introduced the arithmetic error. Existing test cases have been modified to reflect the changes in error messages returned by libObject. What's more, the test case for macho-rebase-add-addr-uleb-too-big has been modified so that it actually triggers the error condition; the new code in libObject considers the original test binary "legal". rdar://47797757 Reviewers: lhames, pete, ab Reviewed By: pete Subscribers: rupprecht, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59574 llvm-svn: 356629
2019-03-11Detect malformed LC_LINKER_COMMANDs in Mach-O binariesMichael Trent1-0/+4
Summary: llvm-objdump can be tricked into reading beyond valid memory and segfaulting if LC_LINKER_COMMAND strings are not null terminated. libObject does have code to validate the integrity of the LC_LINKER_COMMAND struct, but this validator improperly assumes linker command strings are null terminated. The solution is to report an error if a string extends beyond the end of the LC_LINKER_COMMAND struct. Reviewers: lhames, pete Reviewed By: pete Subscribers: rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59179 llvm-svn: 355851
2019-02-23objdump fails to parse Mach-O binaries with n_desc bearing stabsMichael Trent1-23/+23
Summary: The objdump Mach-O parser uses MachOObjectFile::checkSymbolTable() to verify the symbol table is in a legal state before dereferencing the offsets in the table. This routine missed a test for N_STAB symbols when validating the two-level name space library ordinal for undefined symbols. If the binary in question contained a value in the n_desc high byte that is larger than the list of loaded dylibs, checkSymbolTable() will flag the library ordinal as being out of range. Most of the time the n_desc field is set to 0 or to small values, but old final linked binaries exist with N_STAB symbols bearing non-trivial n_desc fields. The change here is simply to verify a symbol is not an N_STAB symbol before consulting the values of n_other or n_desc. rdar://44977336 Reviewers: lhames, pete, ab Reviewed By: pete Subscribers: llvm-commits, rupprecht Tags: #llvm Differential Revision: https://reviews.llvm.org/D58568 llvm-svn: 354722
2019-01-24Limit dyld image suffixes guessed by guessLibraryShortName()Michael Trent1-3/+18
Summary: guessLibraryShortName() separates a full Mach-O dylib install name path into a short name and a dyld image suffix. The short name is the name of the dylib without its path or extension. The dyld image suffix is a string used by dyld to load variants of dylibs if available at runtime; for example, "when binding this process, load 'debug' variants of all required dylibs." dyld knows exactly what the image suffix is, but by convention diagnostic tools such as llvm-nm attempt to guess suffix names by looking at the install name path. These dyld image suffixes are separated from the short name by a '_' character. Because the '_' character is commonly used to separate words in filenames guessLibraryShortName() cannot reliably separate a dylib's short name from an arbitrary image suffix; imagine if both the short name and the suffix contains an '_' character! To better deal with this ambiguity, guessLibraryShortName() will recognize only "_debug" and "_profile" as valid Suffix values. Calling code needs to be tolerant of guessLibraryShortName() guessing incorrectly. The previous implementation of guessLibraryShortName() did not allow '_' characters to appear in short names. When present, the short name would be truncated, e.g., "libcompiler_rt" => "libcompiler". This change allows "libcompiler_rt" and "libcompiler_rt_debug" to both be recognized as "libcompiler_rt". rdar://47412244 Reviewers: kledzik, lhames, pete Reviewed By: pete Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D56978 llvm-svn: 352104