summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/COFFObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Make computeSymbolSizes never fail.Rafael Espindola2015-06-241-0/+12
| | | | | | | | | | | 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-10/+14
| | | | | | | | | 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
* Simplify the logic, NFC.Rafael Espindola2015-06-241-12/+8
| | | | llvm-svn: 240554
* Change how symbol sizes are handled in lib/Object.Rafael Espindola2015-06-241-7/+4
| | | | | | | | | | | | | | 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
* Make getRelocationSection MachO only.Rafael Espindola2015-06-191-13/+0
| | | | | | | | | | | | | | There are 3 types of relocations on MachO * Scattered * Section based * Symbol based On ELF and COFF relocations are symbol based. We were in the strange situation that we abstracted over two of them. This makes section based relocations MachO only. llvm-svn: 240149
* Remove object_error::success and use std::error_code() insteadRui Ueyama2015-06-091-60/+60
| | | | | | | | | | | | 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
* Move to llvm-objdump a large amount of code to that is only used there.Rafael Espindola2015-06-031-16/+0
| | | | llvm-svn: 238898
* Simplify another function that doesn't fail.Rafael Espindola2015-06-011-7/+3
| | | | llvm-svn: 238703
* Stop inventing symbol sizes.Rafael Espindola2015-05-221-52/+3
| | | | | | | | | | | | | | | | | | | | | 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
* Make it easier to use DwarfContext with MCJITKeno Fischer2015-05-211-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Change range-based for-loops to be -Wrange-loop-analysis clean.Richard Trieu2015-04-151-1/+1
| | | | | | No functionality change. llvm-svn: 234963
* ExecutionEngine: Preliminary support for dynamically loadable coff objectsDavid Majnemer2015-03-071-3/+10
| | | | | | | | | | Provide basic support for dynamically loadable coff objects. Only handles a subset of x64 currently. Patch by Andy Ayers! Differential Revision: http://reviews.llvm.org/D7793 llvm-svn: 231574
* 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
OpenPOWER on IntegriCloud