aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-07-18llvm: add llvm-dlltool support to the archiverMartell Malone1-1/+4
A PE COFF spec compliant import library generator. Intended to be used with mingw-w64. Supports: PE COFF spec (section 8, Import Library Format) PE COFF spec (Aux Format 3: Weak Externals) Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D29892 This reapplies rL308329, which was reverted in rL308374 llvm-svn: 308379
2017-07-18Revert r308329: llvm: add llvm-dlltool support to the archiverRui Ueyama1-4/+1
This reverts commit r308329 because it broke buildbots. llvm-svn: 308374
2017-07-18llvm: add llvm-dlltool support to the archiverMartell Malone1-1/+4
A PE COFF spec compliant import library generator. Intended to be used with mingw-w64. Supports: PE COFF spec (section 8, Import Library Format) PE COFF spec (Aux Format 3: Weak Externals) Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D29892 llvm-svn: 308329
2017-06-30[llvm-readobj] Improve printouts for COFF ARM64 binariesMartin Storsjo1-1/+1
Differential Revision: https://reviews.llvm.org/D34835 llvm-svn: 306795
2017-06-27[COFF, ARM64] Add support for Windows ARM64 COFF formatMandeep Singh Grang1-0/+23
Summary: This is the llvm part of the initial implementation to support Windows ARM64 COFF format. I will gradually add more functionality in subsequent patches. Reviewers: ruiu, rnk, t.p.northover, compnerd Reviewed By: ruiu, compnerd Subscribers: aemerson, mgorny, javed.absar, llvm-commits, kristof.beyls Differential Revision: https://reviews.llvm.org/D34705 llvm-svn: 306490
2017-06-22[llvm-readobj] Dump the COFF image load configReid Kleckner1-0/+20
This includes the safe SEH tables and the control flow guard function table. LLD will emit the guard table soon, and I need a tool that dumps them for testing. llvm-svn: 305979
2017-06-07Move Object format code to lib/BinaryFormat.Zachary Turner1-1/+1
This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
2017-05-27Recommit "[DWARF] - Make collectAddressRanges() return section index in ↵George Rimar1-0/+4
addition to Low/High PC" With fix of uninitialized variable. Original commit message: This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 llvm-svn: 304078
2017-05-26Revert r304002 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar1-4/+0
in addition to Low/High PC" Revert it again. Now another bot unhappy: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/8750 llvm-svn: 304011
2017-05-26[DWARF] - Make collectAddressRanges() return section index in addition to ↵George Rimar1-0/+4
Low/High PC This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 llvm-svn: 304002
2017-05-26Revert "[DWARF] - Make collectAddressRanges() return section index in ↵George Rimar1-4/+0
addition to Low/High PC" Broked BB again: TEST 'LLVM :: DebugInfo/X86/dbg-value-regmask-clobber.ll' FAILED ... LLVM ERROR: Section was outside of section table. llvm-svn: 303984
2017-05-26Recommit r303978 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar1-0/+4
in addition to Low/High PC" With fix of test compilation. Initial commit message: This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 llvm-svn: 303983
2017-05-26Revert r303978 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar1-4/+0
in addition to Low/High PC" It failed BB. llvm-svn: 303981
2017-05-26[DWARF] - Make collectAddressRanges() return section index in addition to ↵George Rimar1-0/+4
Low/High PC This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 llvm-svn: 303978
2017-05-14[COFF] Gracefully handle empty .drectve sectionsShoaib Meenai1-1/+1
Running `llvm-readobj -coff-directives msvcrt.lib` resulted in this error: Invalid data was encountered while parsing the file This happened because some of the object files in the archive have empty `.drectve` sections. These empty sections result in a `parse_failed` error being returned from `COFFObjectFile::getSectionContents()`, which in turn caused `llvm-readobj` to stop. With this change, `getSectionContents` now returns success, and like before the resulting array is empty. Patch by Dave Lee. Differential Revision: https://reviews.llvm.org/D32652 llvm-svn: 303014
2017-05-09Fix the Endianness bug by adding the little endian UTF marker.Eric Beckmann1-2/+0
Summary: Quick fix Reviewers: zturner, uweigand Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33014 llvm-svn: 302573
2017-05-08Hopefully one last commit to fix this patch, addresses string referenceEric Beckmann1-7/+3
issues. llvm-svn: 302401
2017-05-08Update llvm-readobj -coff-resources to display tree structure.Eric Beckmann1-2/+47
Summary: Continue making updates to llvm-readobj to display resource sections. This is necessary for testing the up and coming cvtres tool. Reviewers: zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32609 llvm-svn: 302399
2017-05-08Revert "Hopefully one last commit to fix this patch, addresses string reference"Eric Beckmann1-43/+2
Summary: This reverts commit 56beec1b1cfc6d263e5eddb7efff06117c0724d2. Revert "Quick fix to D32609, it seems .o files are not transferred in all cases." This reverts commit 7652eecd29cfdeeab7f76f687586607a99ff4e36. Revert "Update llvm-readobj -coff-resources to display tree structure." This reverts commit 422b62c4d302cfc92401418c2acd165056081ed7. Reviewers: zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32958 llvm-svn: 302397
2017-05-08Hopefully one last commit to fix this patch, addresses string referenceEric Beckmann1-7/+3
issues. llvm-svn: 302395
2017-05-07Update llvm-readobj -coff-resources to display tree structure.Eric Beckmann1-2/+47
Summary: Continue making updates to llvm-readobj to display resource sections. This is necessary for testing the up and coming cvtres tool. Reviewers: zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32609 llvm-svn: 302386
2017-04-19[Object] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-10/+22
other minor fixes (NFC). llvm-svn: 300779
2016-11-22Object: Make SymbolicFile::symbol_{begin,end}() virtual and remove ↵Peter Collingbourne1-2/+2
unnecessary wrappers. llvm-svn: 287611
2016-11-11[lli] Simplify the code a bit. No functional change intended.Davide Italiano1-3/+1
llvm-svn: 286555
2016-11-02[lli/COFF] Set the correct alignment for common symbolsDavide Italiano1-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
2016-08-30[COFFObjectFile] Ignore broken symbol tableDavid Majnemer1-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
2016-08-11Re-commit r278066: Do not ignore SizeOfOptionalHeader in COFF header even if ↵Rui Ueyama1-1/+3
PE header is not present. llvm-svn: 278429
2016-08-09CodeView: extract the OMF Directory HeaderSaleem Abdulrasool1-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
2016-08-08Revert "Do not ignore SizeOfOptionalHeader in COFF header even if PE header ↵Rui Ueyama1-2/+1
is not present." This reverts commit r278066 to unbreak buildbots. llvm-svn: 278070
2016-08-08Do not ignore SizeOfOptionalHeader in COFF header even if PE header is not ↵Rui Ueyama1-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
2016-07-31[COFF] Expose iterators for ImportAddressTableRVADavid Majnemer1-2/+17
Patch by Bandzi Michal! llvm-svn: 277298
2016-07-31[COFF] Remove a duplicate import_directory_table_entry definitionDavid Majnemer1-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
2016-06-26[Object, COFF] An import data directory might not consist soley of importsDavid Majnemer1-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
2016-06-24Thread Expected<...> up from libObject’s getSymbolAddress() for symbols to ↵Kevin Enderby1-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
2016-06-03[Symbolize] Check if the PE file has a PDB and emit an error if we can't load itReid Kleckner1-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
2016-06-02[COFF] Expose the PE debug data directory and dump itReid Kleckner1-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
2016-05-28[Object] Return an error code instead of assertingDavid Majnemer1-4/+4
This makes it easier to report errors up the stack. llvm-svn: 271140
2016-05-24Recommit r270547 ([llvm-dwarfdump] - Teach dwarfdump to decompress debug ↵George Rimar1-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
2016-05-24Revert r270543 ("Recommit r270540")George Rimar1-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
2016-05-24Recommit r270540George Rimar1-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
2016-05-24Revert r270540 "[llvm-dwarfdump] - Teach dwarfdump to decompress debug ↵George Rimar1-4/+0
sections in zlib style." it broked bot: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/5036 llvm-svn: 270541
2016-05-24[llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style.George Rimar1-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
2016-05-02Thread Expected<...> up from libObject’s getType() for symbols to allow ↵Kevin Enderby1-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
2016-04-20Thread Expected<...> up from libObject’s getName() for symbols to allow ↵Kevin Enderby1-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
2016-04-18[NFC] Header cleanupMehdi Amini1-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
2016-03-23Fix a crash in running llvm-objdump -t with an invalid Mach-O file alreadyKevin Enderby1-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
2016-03-17[COFF] Refactor section alignment calculationDavid Majnemer1-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
2016-01-25[Object][COFF] Revert r258665 - It doesn't do what I had intended.Lang Hames1-1/+1
I'm discussing the right approach for tracking visibility for COFF symbols on the llvm-dev list. llvm-svn: 258666
2016-01-24[Object][COFF] Set the generic SF_Exported flag on COFF exported symbols.Lang Hames1-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
2016-01-12COFF: Teach llvm-objdump how to dump DLL forwarder symbols.Rui Ueyama1-0/+24
llvm-svn: 257539