aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
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
2019-01-14[Object] Return a symbol_iterator, rather than a basic_symbol_iterator, fromLang Hames1-1/+1
MachOObjectFile::getSymbolByIndex. ObjectFile derivatives should prefer symbol_iterator/SymbolRef over basic_symbol_iterator/BasicSymbolRef where possible, as the former retain their link to the ObjectFile (rather than a SymbolicFile) and provide more functionality. No test for this: Existing code is working, and we don't have (m)any libObject unit tests. I'll think about how we can test more systematically going forward. llvm-svn: 351128
2018-09-04[MachO] Fix inconsistency between error messages when validating LC_DYSYMTABFrancis Visoiu Mistrih1-2/+2
llvm-svn: 341379
2018-09-04[MachO] Fix LC_DYSYMTAB validation for external symbolsFrancis Visoiu Mistrih1-1/+1
We were validating the same index (ilocalsym) twice, while iextdefsym was never validated. llvm-svn: 341378
2018-07-11[llvm-readobj] Add -hex-dump (-x) optionPaul Semel1-0/+21
Differential Revision: https://reviews.llvm.org/D48281 llvm-svn: 336782
2018-06-04[MachO] Add out-of-bounds check to MachOObjectFile.cppSam Clegg1-0/+1
This is a followup to rL333496. Differential Revision: https://reviews.llvm.org/D47544 llvm-svn: 333929
2018-05-30MC: Remove redundant substr() callSam Clegg1-1/+1
Differential Revision: https://reviews.llvm.org/D47047 llvm-svn: 333496
2018-04-19[llvm-objdump] Print "..." instead of random data for virtual sectionsFrancis Visoiu Mistrih1-2/+4
When disassembling with -D, skip virtual sections by printing "..." for each symbol. This patch also implements `MachOObjectFile::isSectionVirtual`. Test case comes from: ``` .zerofill __DATA,__common,_data64unsigned,472,3 ``` Differential Revision: https://reviews.llvm.org/D45824 llvm-svn: 330342
2018-03-08For llvm-objdump and Mach-O files, update the printing of some thread statesKevin Enderby1-1/+49
from core files. I tested this against the couple of core files that were getting errors about unknown thread flavors and it now produce the same output as the Xcode otool-classic(1) tool. Since the core files are huge I didn’t include them as test cases. rdar://38216356 llvm-svn: 327077
2018-01-03Do not look up symbol names when n_strx == 0Michael Trent1-0/+4
Summary: Historical tools for working with mach-o binaries verify the nlist field n_strx has a non-zero value before using that value to retrieve symbol names. Under some cirumstances, llvm-nm will attempt to display the symbol name at position 0, even though symbol names at that position are not well defined. This change addresses this problem by returning an empty string when n_strx is zero. rdar://problem/35750548 Reviewers: enderby, davide Reviewed By: enderby, davide Subscribers: davide, llvm-commits, JDevlieghere Differential Revision: https://reviews.llvm.org/D41657 llvm-svn: 321773
2017-12-15Updated llvm-objdump to display local relocations in Mach-O binariesMichael Trent1-1/+23
Summary: llvm-objdump's Mach-O parser was updated in r306037 to display external relocations for MH_KEXT_BUNDLE file types. This change extends the Macho-O parser to display local relocations for MH_PRELOAD files. When used with the -macho option relocations will be displayed in a historical format. All tests are passing for llvm, clang, and lld. llvm-objdump builds without compiler warnings. rdar://35778019 Reviewers: enderby Reviewed By: enderby Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41199 llvm-svn: 320832
2017-12-14Fix many -Wsign-compare and -Wtautological-constant-compare warnings.Zachary Turner1-1/+1
Most of the -Wsign-compare warnings are due to the fact that enums are signed by default in the MS ABI, while the tautological comparison warnings trigger on x86 builds where sizeof(size_t) is 4 bytes, so N > numeric_limits<unsigned>::max() is always false. Differential Revision: https://reviews.llvm.org/D41256 llvm-svn: 320750
2017-12-13reverting out -r320532 because a warning is breaking the lld buildMichael Trent1-23/+1
llvm-svn: 320534