summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix a bug in llvm-objdump’s printing of Objective-C meta dataKevin Enderby2015-10-081-3/+26
| | | | | | | | | from malformed Mach-O files that caused a crash because of a section header had a size that extended past the end of the file. rdar://22983603 llvm-svn: 249768
* Prune trailing whitespaces.NAKAMURA Takumi2015-09-221-10/+10
| | | | llvm-svn: 248265
* Untabify.NAKAMURA Takumi2015-09-221-2/+1
| | | | llvm-svn: 248264
* Reformat blank lines.NAKAMURA Takumi2015-09-221-3/+0
| | | | llvm-svn: 248263
* Reformat comment lines.NAKAMURA Takumi2015-09-221-2/+2
| | | | llvm-svn: 248262
* Reformat.NAKAMURA Takumi2015-09-221-30/+27
| | | | llvm-svn: 248261
* Use makeArrayRef or None to avoid unnecessarily mentioning the ArrayRef type ↵Craig Topper2015-09-211-12/+12
| | | | | | extra times. NFC llvm-svn: 248140
* [MachO] Move trivial accessors to header.Davide Italiano2015-08-251-18/+0
| | | | | | Requested by: Jim Grosbach. llvm-svn: 245963
* [MachO] Introduce MinVersion API.Davide Italiano2015-08-251-0/+18
| | | | | | | | | | | | | While introducing support for MinVersionLoadCommand in llvm-readobj I noticed there's no API to extract Major/Minor/Update components conveniently. Currently consumers do the bit twiddling on their own, but this will change from now on. I'll convert llvm-objdump (and llvm-readobj) in a later commit. Differential Revision: http://reviews.llvm.org/D12282 Reviewed by: rafael llvm-svn: 245938
* Convert getSymbolSection to return an ErrorOr.Rafael Espindola2015-08-071-13/+9
| | | | | | | This function can actually fail since the symbol contains an index to the section and that can be invalid. llvm-svn: 244375
* Delete UnknownAddress. It is a perfectly valid symbol value.Rafael Espindola2015-07-071-4/+1
| | | | | | | | | | | getSymbolValue now returns a value that in convenient for most callers: * 0 for undefined * symbol size for common symbols * offset/address for symbols the rest Code that needs something more specific can check getSymbolFlags. llvm-svn: 241605
* Common symbols don't have a value.Rafael Espindola2015-07-071-3/+2
| | | | | | | | | | | | | At least not in the interface exposed by ObjectFile. This matches what ELF and COFF implement. Adjust existing code that was expecting them to have values. No overall functionality change intended. Another option would be to change the interface and the ELF and COFF implementations to say that the value of a common symbol is its size. llvm-svn: 241593
* Common symbols are not undefined, at least for ObjectFile.Rafael Espindola2015-07-071-3/+2
| | | | | | | | | They are implemented like that in some object formats, but for the interface provided by lib/Object, SF_Undefined and SF_Common are different things. This matches the ELF and COFF implementation and fixes llvm-nm for MachO. llvm-svn: 241587
* Simplify, NFC.Rafael Espindola2015-07-071-3/+2
| | | | | | | | In these two contexts we really just want the raw n_value. No need to use getSymbolValue which checks for special cases where, semantically, the symbol has no value. llvm-svn: 241584
* Remove getRelocationAddress.Rafael Espindola2015-07-061-9/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally added in r139314. Back then it didn't actually get the address, it got whatever value the relocation used: address or offset. The values in different object formats are: * MachO: Always an offset. * COFF: Always an address, but when talking about the virtual address of sections it says: "for simplicity, compilers should set this to zero". * ELF: An offset for .o files and and address for .so files. In the case of the .so, the relocation in not linked to any section (sh_info is 0). We can't really compute an offset. Some API mappings would be: * Use getAddress for everything. It would be quite cumbersome. To compute the address elf has to follow sh_info, which can be corrupted and therefore the method has to return an ErrorOr. The address of the section is also the same for every relocation in a section, so we shouldn't have to check the error and fetch the value for every relocation. * Use a getValue and make it up to the user to know what it is getting. * Use a getOffset and: * Assert for dynamic ELF objects. That is a very peculiar case and it is probably fair to ask any tool that wants to support it to use ELF.h. The only tool we have that reads those (llvm-readobj) already does that. The only other use case I can think of is a dynamic linker. * Check that COFF .obj files have sections with zero virtual address spaces. If it turns out that some assembler/compiler produces these, we can change COFFObjectFile::getRelocationOffset to subtract it. Given COFF format, this can be done without the need for ErrorOr. The getRelocationAddress method was never implemented for COFF. It also had exactly one use in a very peculiar case: a shortcut for adding the section value to a pcrel reloc on MachO. Given that, I don't expect that there is any use out there of the C API. If that is not the case, let me know and I will add it back with the implementation inlined and do a proper deprecation. llvm-svn: 241450
* Return ErrorOr from getSymbolAddress.Rafael Espindola2015-07-031-4/+2
| | | | | | | It can fail trying to get the section on ELF and COFF. This makes sure the error is handled. llvm-svn: 241366
* Use getValue instead of getAddress in a few MachO only cases.Rafael Espindola2015-07-031-5/+2
| | | | | | | In MachO the value of the symbol is always the address, so we can use the simpler function. llvm-svn: 241364
* Return ErrorOr from SymbolRef::getName.Rafael Espindola2015-07-021-4/+2
| | | | | | | | | | | | This function can really fail since the string table offset can be out of bounds. Using ErrorOr makes sure the error is checked. Hopefully a lot of the boilerplate code in tools/* can go away once we have a diagnostic manager in Object. llvm-svn: 241297
* Use ErrorOr in getRelocationAdress.Rafael Espindola2015-06-301-4/+2
| | | | | | | We can probably do better in this method, but this is an improvement and enables further ErrorOr cleanups. llvm-svn: 241114
* Implement containsSymbol with other lower level methods.Rafael Espindola2015-06-301-15/+0
| | | | llvm-svn: 241112
* Don't return error_code from a function that doesn't fail.Rafael Espindola2015-06-301-4/+2
| | | | llvm-svn: 241042
* Move function to the only file that uses it.Rafael Espindola2015-06-301-24/+0
| | | | llvm-svn: 241040
* Don't return error_code from a function that doesn't fail.Rafael Espindola2015-06-301-7/+5
| | | | llvm-svn: 241039
* Don't return error_code from a function that doesn't fail.Rafael Espindola2015-06-301-10/+5
| | | | llvm-svn: 241033
* Don't return error_code from function that never fails.Rafael Espindola2015-06-291-6/+3
| | | | llvm-svn: 241021
* Simplify getSymbolType.Rafael Espindola2015-06-261-15/+7
| | | | | | | | This is still a really odd function. Most calls are in object format specific contexts and should probably be replaced with a more direct query, but at least now this is not too obnoxious to use. llvm-svn: 240777
* Make computeSymbolSizes never fail.Rafael Espindola2015-06-241-0/+10
| | | | | | | | | | | On ELF that was already the case since getting the size of a symbol never fails. On MachO and COFF we could fail trying to get the section of a symbol. But we don't really need the section, just the section number to know if two symbols are in the same section or not. llvm-svn: 240580
* Add a SymbolRef::getValue.Rafael Espindola2015-06-241-7/+10
| | | | | | | | | This returns either the symbol offset or address. Since it is not defined which one, it never has to lookup the section and so never fails. I will add users in the next commit. llvm-svn: 240569
* Refactor duplicated code. NFC.Rafael Espindola2015-06-241-27/+19
| | | | llvm-svn: 240563
* Change how symbol sizes are handled in lib/Object.Rafael Espindola2015-06-241-8/+5
| | | | | | | | | | | | | | COFF and MachO only define symbol sizes for common symbols. Reflect that in the class hierarchy by having a method for common symbols only in the base and a general one in ELF. This avoids the need of using a magic value for the size, which had a few problems * Most callers didn't check for it. * The ones that did could not tell the magic value from a file actually having that value. llvm-svn: 240529
* Improve the --expand-relocs handling of MachO.Rafael Espindola2015-06-181-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In a relocation target can take 3 basic forms * A r_value in scattered relocations. * A symbol in external relocations. * A section is non-external relocations. Have the dump reflect that. With this change we go from CHECK-NEXT: Extern: 0 CHECK-NEXT: Type: X86_64_RELOC_SUBTRACTOR (5) CHECK-NEXT: Symbol: 0x2 CHECK-NEXT: Scattered: 0 To just // CHECK-NEXT: Type: X86_64_RELOC_SUBTRACTOR (5) // CHECK-NEXT: Section: __data (2) Since the relocation is with a section, we print the seciton name and don't need to say that it is not scattered or external. Someone motivated can add further special cases for things like ARM64_RELOC_ADDEND and ARM_RELOC_PAIR. llvm-svn: 240073
* Have MachOObjectFile::isValidArch() accept armv7Frederic Riss2015-06-161-0/+1
| | | | llvm-svn: 239833
* Remove object_error::success and use std::error_code() insteadRui Ueyama2015-06-091-15/+15
| | | | | | | | | | | | make_error_code(object_error) is slow because object::object_category() uses a ManagedStatic variable. But the real problem is that the function is called too frequently. This patch uses std::error_code() instead of object_error::success. In most cases, we return "success", so this patch reduces number of function calls to that function. http://reviews.llvm.org/D10333 llvm-svn: 239409
* [Object, MachO] Fixup for r239075: use union to store mach_header and ↵Alexey Samsonov2015-06-041-8/+2
| | | | | | mach_header_64. llvm-svn: 239110
* [Object, MachO] Don't crash on incomplete MachO segment load commands.Alexey Samsonov2015-06-041-1/+4
| | | | | | | | Report proper error code from MachOObjectFile constructor if we can't parse another segment load command (we already return a proper error if segment load command contents is suspicious). llvm-svn: 239109
* [Object, MachO] Simplify load segment parsing code. NFC.Alexey Samsonov2015-06-041-52/+30
| | | | llvm-svn: 239106
* [Object, MachO] Don't crash on invalid MachO segment load commands.Alexey Samsonov2015-06-041-11/+15
| | | | | | | | | | | | | | | Summary: Properly report the error in segment load commands from MachOObjectFile constructor instead of crashing the program. Adjust the test case accordingly. Test Plan: regression test suite Reviewers: rafael, filcab Subscribers: llvm-commits llvm-svn: 239081
* [Object, MachO] Don't crash on invalid MachO load commands.Alexey Samsonov2015-06-041-9/+23
| | | | | | | | | | | | | | | Summary: Currently all load commands are parsed in MachOObjectFile constructor. If the next load command cannot be parsed, or if command size is too small, properly report it through the error code and fail to construct the object, instead of crashing the program. Test Plan: regression test suite Reviewers: rafael, filcab Subscribers: llvm-commits llvm-svn: 239080
* [Object, MachO] Don't crash on parsing invalid MachO header.Alexey Samsonov2015-06-041-4/+29
| | | | | | | | | | | Summary: Instead, properly report this error from MachOObjectFile constructor. Test Plan: regression test suite Reviewers: rafael Subscribers: llvm-commits llvm-svn: 239078
* [Object, MachO] Remove some code duplication. NFC.Alexey Samsonov2015-06-041-25/+25
| | | | llvm-svn: 239077
* [Object, MachO] Cache parsed MachO header in MachOObjectFile. NFC.Alexey Samsonov2015-06-041-20/+20
| | | | | | | | | | | | | | | Summary: Avoid parsing object file each time MachOObjectFile::getHeader() is called. Instead, cache the header in MachOObjectFile constructor, where it's parsed anyway. In future, we must avoid constructing the object at all if the header can't be parsed. Test Plan: regression test suite. Reviewers: rafael Subscribers: llvm-commits llvm-svn: 239075
* [Object, MachO] Introduce MachOObjectFile::load_commands() range iterator.Alexey Samsonov2015-06-031-6/+21
| | | | | | | | | | | | | | | | | | Summary: Now users don't have to manually deal with getFirstLoadCommandInfo() / getNextLoadCommandInfo(), calculate the number of load segments, etc. No functionality change. Test Plan: regression test suite Reviewers: rafael, lhames, loladiro Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10144 llvm-svn: 238983
* Move to llvm-objdump a large amount of code to that is only used there.Rafael Espindola2015-06-031-240/+0
| | | | llvm-svn: 238898
* Simplify another function that doesn't fail.Rafael Espindola2015-06-011-6/+3
| | | | llvm-svn: 238703
* Simplify interface of function that doesn't fail.Rafael Espindola2015-05-311-6/+3
| | | | llvm-svn: 238700
* Add RelocVisitor support for MachOKeno Fischer2015-05-301-0/+5
| | | | | | | | | | | | This commit adds partial support for MachO relocations to RelocVisitor. A simple test case is added to show that relocations are indeed being applied and that using llvm-dwarfdump on MachO files no longer errors. Correctness is not yet tested, due to an unrelated bug in DebugInfo, which will be fixed with appropriate testcase in a followup commit. Differential Revision: http://reviews.llvm.org/D8148 llvm-svn: 238663
* Stop inventing symbol sizes.Rafael Espindola2015-05-221-46/+6
| | | | | | | | | | | | | | | | | | | | | MachO and COFF quite reasonably only define the size for common symbols. We used to try to figure out the "size" by computing the gap from one symbol to the next. This would not be correct in general, since a part of a section can belong to no visible symbol (padding, private globals). It was also really expensive, since we would walk every symbol to find the size of one. If a caller really wants this, it can sort all the symbols once and get all the gaps ("size") in O(n log n) instead of O(n^2). On MachO this also has the advantage of centralizing all the checks for an invalid n_sect. llvm-svn: 238028
* Detect invalid section indexes when we first read them.Rafael Espindola2015-05-221-4/+4
| | | | | | We still detect the same errors, but now we do it earlier. llvm-svn: 238024
* Make it easier to use DwarfContext with MCJITKeno Fischer2015-05-211-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This supersedes http://reviews.llvm.org/D4010, hopefully properly dealing with the JIT case and also adds an actual test case. DwarfContext was basically already usable for the JIT (and back when we were overwriting ELF files it actually worked out of the box by accident), but in order to resolve relocations correctly it needs to know the load address of the section. Rather than trying to get this out of the ObjectFile or requiring the user to create a new ObjectFile just to get some debug info, this adds the capability to pass in that info directly. As part of this I separated out part of the LoadedObjectInfo struct from RuntimeDyld, since it is now required at a higher layer. Reviewers: lhames, echristo Reviewed By: echristo Subscribers: vtjnash, friss, rafael, llvm-commits Differential Revision: http://reviews.llvm.org/D6961 llvm-svn: 237961
* Remove more superfluous .str() and replace std::string concatenation with Twine.Yaron Keren2015-03-301-2/+2
| | | | | | Following r233392, http://llvm.org/viewvc/llvm-project?rev=233392&view=rev. llvm-svn: 233555
OpenPOWER on IntegriCloud