summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/COFFObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Move three methods only used by MCJIT to MCJIT.Rafael Espindola2014-12-101-28/+0
| | | | | | | | These methods are only used by MCJIT and are very specific to it. In fact, they are also fairly specific to the fact that we have a dynamic linker of relocatable objects. llvm-svn: 223964
* Object/COFF: Fix off-by-one error for object having lots of relocationsRui Ueyama2014-11-261-1/+2
| | | | | | | | | llvm-objdump printed out an error message for this off-by-one error, but because it always exits with 0 whether or not it found an error, the test (llvm-objdump/coff-many-relocs.test) succeeded. I made llvm-objdump exit with EXIT_FAILURE when an error is found. llvm-svn: 222852
* COFF: Add back an assertion that is superseded by r222124David Majnemer2014-11-251-1/+1
| | | | llvm-svn: 222735
* llvm-readobj: fix off-by-one error in COFFDumperRui Ueyama2014-11-191-1/+1
| | | | | | | | It printed out base relocation table header as table entry. This patch also makes llvm-readobj to not skip ABSOLUTE entries becuase it was confusing. llvm-svn: 222299
* llvm-readobj: teach it how to dump COFF base relocation tableRui Ueyama2014-11-191-1/+69
| | | | llvm-svn: 222289
* Object, COFF: Tighten the object file parserDavid Majnemer2014-11-171-27/+47
| | | | | | | | | | | | We were a little lax in a few areas: - We pretended that import libraries were like any old COFF file, they are not. In fact, they aren't really COFF files at all, we should probably grow some specialized functionality to handle them smarter. - Our symbol iterators were more than happy to attempt to go past the end of the symbol table if you had a symbol with a bad list of auxiliary symbols. llvm-svn: 222124
* obj2yaml, yaml2obj: Add support for COFF executablesDavid Majnemer2014-11-141-5/+9
| | | | | | | | | | | | | | | | In support of serializing executables, obj2yaml now records the virtual address and size of sections. It also serializes whatever we strictly need from the PE header, it expects that it can reconstitute everything else via inference. yaml2obj can reconstitute a fully linked executable. In order to get executables correctly serialized/deserialized, other bugs were fixed as a circumstance. We now properly respect file and section alignments. We also avoid writing out string tables unless they are strictly necessary. llvm-svn: 221975
* Un-break the big-endian buildbotsRui Ueyama2014-11-131-2/+2
| | | | llvm-svn: 221919
* Object, COFF: Refactor code to get relocation iteratorsDavid Majnemer2014-11-131-26/+24
| | | | | | No functional change intended. llvm-svn: 221880
* Object, COFF: Increase code reuseDavid Majnemer2014-11-131-24/+32
| | | | | | | | | | Split getObject's smarts into checkOffset, use this to replace the handwritten check in getSectionContents. Similarly, replace checks in section_rel_begin/section_rel_end with getNumberOfRelocations. No functionality change intended. llvm-svn: 221873
* Object, COFF: getRelocationSymbol shouldn't assertDavid Majnemer2014-11-131-1/+1
| | | | | | | | lib/Object is supposed to be robust to malformed object files. Don't assert if we don't have a symbol table. I'll try to come up with a test case later. llvm-svn: 221870
* Object, COFF: Cleanup some code in getSectionNameDavid Majnemer2014-11-131-2/+2
| | | | | | | Use StringRef::startswith to tidy up some code, no functionality change intended. llvm-svn: 221869
* Object, COFF: Fix some theoretical bugsDavid Majnemer2014-11-131-3/+14
| | | | | | | | getObject didn't consider the case where a pointer came before the start of the object file. No test is included, trying to come up with something reasonable. llvm-svn: 221868
* llvm-readobj: Print out address table when dumping COFF delay-import tableRui Ueyama2014-11-131-0/+14
| | | | llvm-svn: 221855
* Object, COFF: Don't consider AuxFunctionDefinition for getSymbolSizeDavid Majnemer2014-11-061-10/+0
| | | | | | | mingw lies about the size of a function's AuxFunctionDefinition. Ignore the field and rely on our heuristic to determine the symbol's size. llvm-svn: 221485
* Object, COFF: Infer symbol sizes from adjacent symbolsDavid Majnemer2014-11-061-7/+39
| | | | | | | | | Use the position of the subsequent symbol in the object file to infer the size of it's predecessor. I hope to eventually remove whatever COFF specific details from this little algorithm so that we can unify this logic with what Mach-O does. llvm-svn: 221444
* llvm-readobj: Add support for dumping the DOS header in PE filesDavid Majnemer2014-11-051-13/+13
| | | | llvm-svn: 221333
* Object, COFF: Cleanup symbol type code, improve binutils compatibilityDavid Majnemer2014-10-311-44/+75
| | | | | | | Do a better job classifying symbols. This increases the consistency between the COFF handling code and the ELF side of things. llvm-svn: 220952
* Object, COFF: Move the VirtualSize/SizeOfRawData logic to getSectionSizeDavid Majnemer2014-10-091-18/+23
| | | | | | | | While getSectionContents was updated to do the right thing, getSectionSize wasn't. Move the logic to getSectionSize and leverage it from getSectionContents. llvm-svn: 219391
* Object, COFF: Cap the section contents to min(VirtualSize, SizeOfRawData)David Majnemer2014-10-091-5/+19
| | | | | | | | | | | | | | | | It is not useful to return the data beyond VirtualSize it's less than SizeOfRawData. An implementation detail of COFF requires the section size to be rounded up to a multiple of FileAlignment; this means that SizeOfRawData is not representative of how large the section is. Instead, we should cap it to VirtualSize when this occurs as it represents the true size of the section. Note that this is only relevant in executable files because this rounding doesn't occur in object files (and VirtualSize is always zero). llvm-svn: 219388
* Object: Add range iterators for COFF import/export tableRui Ueyama2014-10-091-0/+26
| | | | llvm-svn: 219383
* Correctly compute the size of common symbols in COFF.Rafael Espindola2014-10-081-4/+9
| | | | llvm-svn: 219324
* Remove bogus std::error_code returns form SectionRef.Rafael Espindola2014-10-081-46/+23
| | | | | | | | | | | | | | There are two methods in SectionRef that can fail: * getName: The index into the string table can be invalid. * getContents: The section might point to invalid contents. Every other method will always succeed and returning and std::error_code just complicates the code. For example, a section can have an invalid alignment, but if we are able to get to the section structure at all and create a SectionRef, we will always be able to read that invalid alignment. llvm-svn: 219314
* Don't check for null after calling COFFObjectFile::toSec.Rafael Espindola2014-10-071-2/+0
| | | | | | | | | | | It can only return null if passed a corrupted reference with a null Ref.p. Checking for null is then an issue for asserts to check for internal consistency, not control flow to check for invalid input. I didn't add an assert(sec != nullptr) because toSec itself has a far more complete assert. llvm-svn: 219235
* Optimize COFFObjectFile::sectionContainsSymbol a bit.Rafael Espindola2014-10-071-7/+2
| | | | | | | | | There is no need to compute the coff_section of the symbol just to compare the pointer. Inspired by the ELF implementation. llvm-svn: 219233
* llvm-readobj: print out the fields of the COFF delay-import tableRui Ueyama2014-10-031-0/+6
| | | | llvm-svn: 218996
* llvm-readobj: print COFF delay-load import tableRui Ueyama2014-10-031-13/+90
| | | | | | | | | This patch adds another iterator to access the delay-load import table and use it from llvm-readobj. http://reviews.llvm.org/D5594 llvm-svn: 218933
* llvm-readobj: print COFF imported symbolsRui Ueyama2014-10-021-0/+90
| | | | | | | | This patch defines a new iterator for the imported symbols. Make a change to COFFDumper to use that iterator to print out imported symbols and its ordinals. llvm-svn: 218915
* This patch adds a new flag "-coff-imports" to llvm-readobj.Rui Ueyama2014-10-021-5/+18
| | | | | | | | | | | | | | When the flag is given, the command prints out the COFF import table. Currently only the import table directory will be printed. I'm going to make another patch to print out the imported symbols. The implementation of import directory entry iterator in COFFObjectFile.cpp was buggy. This patch fixes that too. http://reviews.llvm.org/D5569 llvm-svn: 218891
* Object: BSS/virtual sections don't have contentsDavid Majnemer2014-09-261-0/+4
| | | | | | | | | | | | Users of getSectionContents shouldn't try to pass in BSS or virtual sections. In all instances, this is a bug in the code calling this routine. N.B. Some COFF implementations (like CL) will mark their BSS sections as taking space on disk. This would confuse COFFObjectFile into thinking the section is larger than the file. llvm-svn: 218549
* Support: Delete {aligned_,}{u,}{little,big}8_tRui Ueyama2014-09-111-1/+0
| | | | | | | The byte has no endianness, so these types don't make sense. uint8_t should be used instead. llvm-svn: 217631
* Attempt to pacify buildbots.David Majnemer2014-09-101-11/+0
| | | | llvm-svn: 217499
* Object: Add support for bigobjDavid Majnemer2014-09-101-113/+160
| | | | | | | | | | | | | | | | | | | | | | This adds support for reading the "bigobj" variant of COFF produced by cl's /bigobj and mingw's -mbig-obj. The most significant difference that bigobj brings is more than 2**16 sections to COFF. bigobj brings a few interesting differences with it: - It doesn't have a Characteristics field in the file header. - It doesn't have a SizeOfOptionalHeader field in the file header (it's only used in executable files). - Auxiliary symbol records have the same width as a symbol table entry. Since symbol table entries are bigger, so are auxiliary symbol records. Write support will come soon. Differential Revision: http://reviews.llvm.org/D5259 llvm-svn: 217496
* Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper2014-08-271-4/+3
| | | | | | just letting them be implicitly created. llvm-svn: 216525
* Don't own the buffer in object::Binary.Rafael Espindola2014-08-191-20/+16
| | | | | | | | | | | | | | | | | | | | | | | | | Owning the buffer is somewhat inflexible. Some Binaries have sub Binaries (like Archive) and we had to create dummy buffers just to handle that. It is also a bad fit for IRObjectFile where the Module wants to own the buffer too. Keeping this ownership would make supporting IR inside native objects particularly painful. This patch focuses in lib/Object. If something elsewhere used to own an Binary, now it also owns a MemoryBuffer. This patch introduces a few new types. * MemoryBufferRef. This is just a pair of StringRefs for the data and name. This is to MemoryBuffer as StringRef is to std::string. * OwningBinary. A combination of Binary and a MemoryBuffer. This is needed for convenience functions that take a filename and return both the buffer and the Binary using that buffer. The C api now uses OwningBinary to avoid any change in semantics. I will start a new thread to see if we want to change it and how. llvm-svn: 216002
* llvm-objdump: don't print relocations in non-relocatable files.Rafael Espindola2014-08-171-0/+4
| | | | | | This matches the behavior of GNU objdump. llvm-svn: 215844
* Delete dead code. NFC.Rafael Espindola2014-08-081-20/+0
| | | | llvm-svn: 215224
* getLoadName is only implemented for ELF, make it ELF only.Rafael Espindola2014-08-081-5/+0
| | | | llvm-svn: 215219
* Use std::unique_ptr to make the ownership explicit.Rafael Espindola2014-07-311-2/+2
| | | | llvm-svn: 214377
* Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola2014-06-241-4/+7
| | | | | | | Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. llvm-svn: 211595
* Make ObjectFile and BitcodeReader always own the MemoryBuffer.Rafael Espindola2014-06-231-22/+21
| | | | | | | | | | This allows us to just use a std::unique_ptr to store the pointer to the buffer. The flip side is that they have to support releasing the buffer back to the caller. Overall this looks like a more efficient and less brittle api. llvm-svn: 211542
* Remove 'using std::errro_code' from lib.Rafael Espindola2014-06-131-119/+135
| | | | llvm-svn: 210871
* Don't use 'using std::error_code' in include/llvm.Rafael Espindola2014-06-121-0/+1
| | | | | | This should make sure that most new uses use the std prefix. llvm-svn: 210835
* [C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper2014-04-151-14/+15
| | | | | | instead of comparing to nullptr. llvm-svn: 206252
* Object: add type names for ARM/COFF relocationsSaleem Abdulrasool2014-04-091-0/+21
| | | | | | | Add type name mappings for the ARM COFF relocations. This allows for objdump to provide a more useful description of relocations in disassembly inline form. llvm-svn: 205834
* Remove section_rel_empty. Just compare begin() and end() instead.Rafael Espindola2014-04-031-5/+0
| | | | llvm-svn: 205577
* Implement get getSymbolFileOffset with getSymbolAddress.Rafael Espindola2014-04-031-16/+0
| | | | | | | | | | | | This has the following advantages: * Less code. * The old ELF implementation was wrong for non-relocatable objects. * The old ELF implementation (and I think MachO) was wrong for thumb. No current testcase since this is only used from MCJIT and it only uses relocatable objects and I don't think it supports thumb yet. llvm-svn: 205508
* Remove getSymbolValue.Rafael Espindola2014-04-031-5/+0
| | | | | | All existing users explicitly ask for an address or a file offset. llvm-svn: 205503
* Revert "Fix a nomenclature error in llvm-nm."Rafael Espindola2014-04-031-9/+2
| | | | | | | | | | | | | | | | This reverts commit r205479. It turns out that nm does use addresses, it is just that every reasonable relocatable ELF object has sections with address 0. I have no idea if those exist in reality, but it at least it shows that llvm-nm should use the name address. The added test was includes an unusual .o file with non 0 section addresses. I created it by hacking ELFObjectWriter.cpp. Really sorry for the churn. llvm-svn: 205493
* Fix a nomenclature error in llvm-nm.Rafael Espindola2014-04-021-2/+9
| | | | | | | | | | | What llvm-nm prints depends on the file format. On ELF for example, if the file is relocatable, it prints offsets. If it is not, it prints addresses. Since it doesn't really need to care what it is that it is printing, use the generic term value. Fix or implement getSymbolValue to keep llvm-nm working. llvm-svn: 205479
OpenPOWER on IntegriCloud