summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/COFFObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [Object] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko2017-04-191-10/+22
| | | | | | other minor fixes (NFC). llvm-svn: 300779
* Object: Make SymbolicFile::symbol_{begin,end}() virtual and remove ↵Peter Collingbourne2016-11-221-2/+2
| | | | | | unnecessary wrappers. llvm-svn: 287611
* [lli] Simplify the code a bit. No functional change intended.Davide Italiano2016-11-111-3/+1
| | | | llvm-svn: 286555
* [lli/COFF] Set the correct alignment for common symbolsDavide Italiano2016-11-021-0/+9
| | | | | | | | | | Otherwise we set it always to zero, which is not correct, and we assert inside alignTo (Assertion failed: Align != 0u && "Align can't be 0."). Differential Revision: https://reviews.llvm.org/D26173 llvm-svn: 285841
* [COFFObjectFile] Ignore broken symbol tableDavid Majnemer2016-08-301-2/+6
| | | | | | | | | | | | | | | | When binaries are compressed by UPX, information about symbol table offset and symbol count remain unchanged (but became invalid due to compression). This causes failure in the constructor and the rest of the binary cannot be processed. Instead, reset symbol related information (symbol/string table pointers, sizes) - this should disable the related iterators and functions while the rest of the binary can still be processed. Patch by Bandzi Michal! llvm-svn: 280147
* Re-commit r278066: Do not ignore SizeOfOptionalHeader in COFF header even if ↵Rui Ueyama2016-08-111-1/+3
| | | | | | PE header is not present. llvm-svn: 278429
* CodeView: extract the OMF Directory HeaderSaleem Abdulrasool2016-08-091-8/+10
| | | | | | | | | | | | The DebugDirectory contains a pointer to the CodeView info structure which is a derivative of the OMF debug directory. The structure has evolved a bit over time, and PDB 2.0 used a slightly different definition from PDB 7.0. Both of these are specific to CodeView and not COFF. Reflect this by moving the structure definitions into the DebugInfo/CodeView headers. Define a generic DebugInfo union type that can be used to pass around a reference to the DebugInfo irrespective of the versioning. NFC. llvm-svn: 278075
* Revert "Do not ignore SizeOfOptionalHeader in COFF header even if PE header ↵Rui Ueyama2016-08-081-2/+1
| | | | | | | | is not present." This reverts commit r278066 to unbreak buildbots. llvm-svn: 278070
* Do not ignore SizeOfOptionalHeader in COFF header even if PE header is not ↵Rui Ueyama2016-08-081-1/+2
| | | | | | | | | | | | | | | | | | | present. Attribute SizeOfOptionalHeader is ignored if no PE header is present in the file. This attribute should be ignored according to standard, however there are uses of this field even though it should not be used. This change does not conform to PE/COFF standard, but there are several COFF files without PE header, where you had to add up SizeOfOptionalHeader in order to get proper section headers. Other tools and their own parsers do take this into account. Patch by Marek Milkovič! https://reviews.llvm.org/D22750 llvm-svn: 278066
* [COFF] Expose iterators for ImportAddressTableRVADavid Majnemer2016-07-311-2/+17
| | | | | | Patch by Bandzi Michal! llvm-svn: 277298
* [COFF] Remove a duplicate import_directory_table_entry definitionDavid Majnemer2016-07-311-4/+4
| | | | | | | | We had import_directory_table_entry and coff_import_directory_table_entry, remove one. Also, factor out the logic which determins if a descriptor is a terminator. llvm-svn: 277296
* [Object, COFF] An import data directory might not consist soley of importsDavid Majnemer2016-06-261-17/+29
| | | | | | | | | | | | | The last import is the penultimate entry, the last entry is nulled out. Data beyond the null entry should not be considered to hold import entries. This fixes PR28302. N.B. I am working on a reduced testcase, the one in PR28302 is too large. llvm-svn: 273790
* Thread Expected<...> up from libObject’s getSymbolAddress() for symbols to ↵Kevin Enderby2016-06-241-2/+2
| | | | | | | | | | | | | | | | | | | | | allow a good error message to be produced. This is nearly the last libObject interface that used ErrorOr and the last one that appears in llvm/include/llvm/Object/MachO.h . For Mach-O objects this is just a clean up because it’s version of getSymbolAddress() can’t return an error. I will leave it to the experts on COFF and ELF to actually add meaning full error messages in their tests if they wish. And also leave it to these experts to change the last two ErrorOr interfaces in llvm/include/llvm/Object/ObjectFile.h for createCOFFObjectFile() and createELFObjectFile() if they wish. Since there are no test cases for COFF and ELF error cases with respect to getSymbolAddress() in the test suite this is no functional change (NFC). llvm-svn: 273701
* [Symbolize] Check if the PE file has a PDB and emit an error if we can't load itReid Kleckner2016-06-031-0/+11
| | | | | | | | | | | | | | | | | | | | | Summary: Previously we would try to load PDBs for every PE executable we tried to symbolize. If that failed, we would fall back to DWARF. If there wasn't any DWARF, we'd print mostly useless symbol information using the export table. With this change, we only try to load PDBs for executables that claim to have them. If that fails, we can now print an error rather than falling back silently. This should make it a lot easier to diagnose and fix common symbolization issues, such as not having DIA or not having a PDB. Reviewers: zturner, eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D20982 llvm-svn: 271725
* [COFF] Expose the PE debug data directory and dump itReid Kleckner2016-06-021-2/+70
| | | | | | | | | | | | This directory is used to find if there is a PDB associated with an executable. I plan to use this functionality to teach llvm-symbolizer whether it should use DIA or DWARF to symbolize a given DLL. Reviewers: majnemer Differential Revision: http://reviews.llvm.org/D20885 llvm-svn: 271539
* [Object] Return an error code instead of assertingDavid Majnemer2016-05-281-4/+4
| | | | | | This makes it easier to report errors up the stack. llvm-svn: 271140
* Recommit r270547 ([llvm-dwarfdump] - Teach dwarfdump to decompress debug ↵George Rimar2016-05-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | sections in zlib style.) Fix was: 1) Had to regenerate dwarfdump-test-zlib.elf-x86-64, dwarfdump-test-zlib-gnu.elf-x86-64 (because llvm-symbolizer-zlib.test uses that inputs for its purposes and failed). 2) Updated llvm-symbolizer-zlib.test (updated used call function address to match new files + added one more check for newly created dwarfdump-test-zlib-gnu.elf-x86-64 binary input). 3) Updated comment in dwarfdump-test-zlib.cc. Original commit message: [llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style. Before this llvm-dwarfdump only recognized zlib-gnu compression style of headers, this patch adds support for zlib style. It looks reasonable to support both styles for dumping, even if we are not going to suport generating of deprecated gnu one. Differential revision: http://reviews.llvm.org/D20470 llvm-svn: 270557
* Revert r270543 ("Recommit r270540")George Rimar2016-05-241-4/+0
| | | | | | | | Failed build bot in another test. I am sorry for noise. http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/23679/testReport/junit/LLVM/DebugInfo/llvm_symbolizer_zlib_test/ llvm-svn: 270547
* Recommit r270540George Rimar2016-05-241-0/+4
| | | | | | | | | | | | | | | | fix: forgot to commit the updated dwarfdump-test-zlib.elf-x86-64 Original commit message: [llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style. Before this llvm-dwarfdump only recognized zlib-gnu compression style of headers, this patch adds support for zlib style. It looks reasonable to support both styles for dumping, even if we are not going to suport generating of deprecated gnu one. Differential revision: http://reviews.llvm.org/D20470 llvm-svn: 270543
* Revert r270540 "[llvm-dwarfdump] - Teach dwarfdump to decompress debug ↵George Rimar2016-05-241-4/+0
| | | | | | | | | sections in zlib style." it broked bot: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/5036 llvm-svn: 270541
* [llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style.George Rimar2016-05-241-0/+4
| | | | | | | | | | | Before this llvm-dwarfdump only recognized zlib-gnu compression style of headers, this patch adds support for zlib style. It looks reasonable to support both styles for dumping, even if we are not going to suport generating of deprecated gnu one. Differential revision: http://reviews.llvm.org/D20470 llvm-svn: 270540
* Thread Expected<...> up from libObject’s getType() for symbols to allow ↵Kevin Enderby2016-05-021-3/+3
| | | | | | | | | | | | | | | | | | | | | | llvm-objdump to produce a good error message. Produce another specific error message for a malformed Mach-O file when a symbol’s section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating that a symbol at a specific index has a bad section index and that bad section index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: "// TODO: Actually report errors helpfully" and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. llvm-svn: 268298
* Thread Expected<...> up from libObject’s getName() for symbols to allow ↵Kevin Enderby2016-04-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | llvm-objdump to produce a good error message. Produce another specific error message for a malformed Mach-O file when a symbol’s string index is past the end of the string table. The existing test case in test/Object/macho-invalid.test for macho-invalid-symbol-name-past-eof now reports the error with the message indicating that a symbol at a specific index has a bad sting index and that bad string index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. There is some code for this that could be factored into a routine but I would like to leave that for the code owners post-commit to do as they want for handling an llvm::Error. An example of how this could be done is shown in the diff in lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h which had a Check() routine already for std::error_code so I added one like it for llvm::Error . Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there fixes needed to lld that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 266919
* [NFC] Header cleanupMehdi Amini2016-04-181-1/+0
| | | | | | | | | | | | | | Removed some unused headers, replaced some headers with forward class declarations. Found using simple scripts like this one: clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap' Patch by Eugene Kosov <claprix@yandex.ru> Differential Revision: http://reviews.llvm.org/D19219 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266595
* Fix a crash in running llvm-objdump -t with an invalid Mach-O file alreadyKevin Enderby2016-03-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in the test suite. While this is not really an interesting tool and option to run on a Mach-O file to show the symbol table in a generic libObject format it shouldn’t crash. The reason for the crash was in MachOObjectFile::getSymbolType() when it was calling MachOObjectFile::getSymbolSection() without checking its return value for the error case. What makes this fix require a fair bit of diffs is that the method getSymbolType() is in the class ObjectFile defined without an ErrorOr<> so I needed to add that all the sub classes.  And all of the uses needed to be updated and the return value needed to be checked for the error case. The MachOObjectFile version of getSymbolType() “can” get an error in trying to come up with the libObject’s internal SymbolRef::Type when the Mach-O symbol symbol type is an N_SECT type because the code is trying to select from the SymbolRef::ST_Data or SymbolRef::ST_Function values for the SymbolRef::Type. And it needs the Mach-O section to use isData() and isBSS to determine if it will return SymbolRef::ST_Data. One other possible fix I considered is to simply return SymbolRef::ST_Other when MachOObjectFile::getSymbolSection() returned an error. But since in the past when I did such changes that “ate an error in the libObject code” I was asked instead to push the error out of the libObject code I chose not to implement the fix this way. As currently written both the COFF and ELF versions of getSymbolType() can’t get an error. But if isReservedSectionNumber() wanted to check for the two known negative values rather than allowing all negative values or the code wanted to add the same check as in getSymbolAddress() to use getSection() and check for the error then these versions of getSymbolType() could return errors. At the end of the day the error printed now is the generic “Invalid data was encountered while parsing the file” for object_error::parse_failed. In the future when we thread Lang’s new TypedError for recoverable error handling though libObject this will improve. And where the added // Diagnostic(… comment is, it would be changed to produce and error message like “bad section index (42) for symbol at index 8” for this case. llvm-svn: 264187
* [COFF] Refactor section alignment calculationDavid Majnemer2016-03-171-1/+1
| | | | | | | Section alignment isn't completely trivial, let it live in one place so that we may reuse it in LLVM. llvm-svn: 263722
* [Object][COFF] Revert r258665 - It doesn't do what I had intended.Lang Hames2016-01-251-1/+1
| | | | | | | I'm discussing the right approach for tracking visibility for COFF symbols on the llvm-dev list. llvm-svn: 258666
* [Object][COFF] Set the generic SF_Exported flag on COFF exported symbols.Lang Hames2016-01-241-1/+1
| | | | | | | | | | | | | | The ORC ObjectLinkingLayer uses this flag during symbol lookup. Failure to set it causes all symbols to behave as if they were non-exported, which has caused failures in the kaleidoscope tutorials on Windows. Raising the flag should un-break the tutorials. No test case yet - none of the existing command line tools for printing symbol tables (llvm-nm, llvm-objdump) show the status of this flag, and I don't want to change the format from these tools without consulting their owners. I'll send an email to the dev-list to figure out the right way forward. llvm-svn: 258665
* COFF: Teach llvm-objdump how to dump DLL forwarder symbols.Rui Ueyama2016-01-121-0/+24
| | | | llvm-svn: 257539
* Address review comments, remove error case and return 0 instead as required ↵Reid Kleckner2015-10-091-7/+8
| | | | | | by tests llvm-svn: 249785
* [llvm-symbolizer] Make --relative-address work with DWARF contextsReid Kleckner2015-10-091-10/+11
| | | | | | | | | | | | | | | | Summary: Previously the relative address flag only affected PDB debug info. Now both DIContext implementations always expect to be passed virtual addresses. llvm-symbolizer is now responsible for adding ImageBase to module offsets when --relative-offset is passed. Reviewers: zturner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12883 llvm-svn: 249784
* Convert getSymbolSection to return an ErrorOr.Rafael Espindola2015-08-071-14/+10
| | | | | | | This function can actually fail since the symbol contains an index to the section and that can be invalid. llvm-svn: 244375
* COFF: Assign the correct symbol type to internal functions.Peter Collingbourne2015-08-061-2/+2
| | | | | | | | | | | The COFFSymbolRef::isFunctionDefinition() function tests for several conditions that are not related to whether a symbol is a function, but rather whether the symbol meets the requirements for a function definition auxiliary record, which excludes certain symbols such as internal functions and undefined references. The test we need to determine the symbol type is much simpler: we only need to compare the complex type against IMAGE_SYM_DTYPE_FUNCTION. llvm-svn: 244195
* [COFF] Consider the ImageBase when reporting section addressesDavid Majnemer2015-07-311-2/+10
| | | | | | This lets us reenable the lld test disabled in r243758. llvm-svn: 243761
* [COFF] Return symbol VAs instead of RVAs for PE filesReid Kleckner2015-07-311-0/+8
| | | | | | | | This makes llvm-nm consistent with binutils nm on executables and DLLs. For a vanilla hello world executable, the address of main should include the default image base of 0x400000. llvm-svn: 243755
* Summary:Martell Malone2015-07-281-0/+4
| | | | | | | | | | | | | | | | Object: add IMAGE_FILE_MACHINE_ARM64 The official specifications state that the value of IMAGE_FILE_MACHINE_ARM64 is 0xAA64 (as per the Microsoft Portable Executable and Common Object Format Specification v8.3). Reviewers: rnk Subscribers: llvm-commits, compnerd, ruiu Differential Revision: http://reviews.llvm.org/D11511 llvm-svn: 243434
* Delete UnknownAddress. It is a perfectly valid symbol value.Rafael Espindola2015-07-071-7/+2
| | | | | | | | | | | 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
* Remove getRelocationAddress.Rafael Espindola2015-07-061-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Check that COFF .obj files have sections with zero virtual address spaces.Rafael Espindola2015-07-061-0/+2
| | | | | | | | | | | | | When talking about the virtual address of sections the coff spec says: ... for simplicity, compilers should set this to zero. Otherwise, it is an arbitrary value that is subtracted from offsets during relocation. We don't currently subtract it, so check that it is zero. If some producer does create such files, we can change getRelocationOffset instead. llvm-svn: 241447
* Object/COFF: Do not rely on VirtualSize being 0 in object files.Rui Ueyama2015-07-041-8/+4
| | | | llvm-svn: 241387
* Return ErrorOr from getSymbolAddress.Rafael Espindola2015-07-031-5/+4
| | | | | | | It can fail trying to get the section on ELF and COFF. This makes sure the error is handled. llvm-svn: 241366
* Return ErrorOr from SymbolRef::getName.Rafael Espindola2015-07-021-3/+6
| | | | | | | | | | | | 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-2/+1
| | | | | | | 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-8/+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
* Don't return error_code from a function that doesn't fail.Rafael Espindola2015-06-301-4/+2
| | | | llvm-svn: 241033
* Object/COFF: Define coff_symbol_generic.Rui Ueyama2015-06-301-6/+10
| | | | | | | | | | | | | | If you only need Name and Value fields in the COFF symbol, you don't need to distinguish 32 bit and 64 bit COFF symbols. These fields start at the same offsets and have the same size. This data strucutre is one pointer smaller than COFFSymbolRef thus slightly efficient. I'll use this class in LLD as we create millions of LLD symbol objects that currently contain COFFSymbolRef. Shaving off 8 byte (or 4 byte on 32 bit) from that class actually matters becasue of the number of objects we create in LLD. llvm-svn: 241024
* Don't return error_code from function that never fails.Rafael Espindola2015-06-291-8/+2
| | | | llvm-svn: 241021
* Simplify getSymbolType.Rafael Espindola2015-06-261-28/+19
| | | | | | | | 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
* libObject/COFF: Add a function to get pointers to relocation entries.Rui Ueyama2015-06-251-0/+10
| | | | llvm-svn: 240610
OpenPOWER on IntegriCloud