summaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFObjectFile.cpp
AgeCommit message (Collapse)Author
2015-06-24Simplify the logic, NFC.Rafael Espindola
llvm-svn: 240554
2015-06-24Change how symbol sizes are handled in lib/Object.Rafael Espindola
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
2015-06-19Make getRelocationSection MachO only.Rafael Espindola
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
2015-06-09Remove object_error::success and use std::error_code() insteadRui Ueyama
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
2015-06-03Move to llvm-objdump a large amount of code to that is only used there.Rafael Espindola
llvm-svn: 238898
2015-06-01Simplify another function that doesn't fail.Rafael Espindola
llvm-svn: 238703
2015-05-22Stop inventing symbol sizes.Rafael Espindola
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
2015-05-21Make it easier to use DwarfContext with MCJITKeno Fischer
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
2015-04-15Change range-based for-loops to be -Wrange-loop-analysis clean.Richard Trieu
No functionality change. llvm-svn: 234963
2015-03-07ExecutionEngine: Preliminary support for dynamically loadable coff objectsDavid Majnemer
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
2014-12-10Move three methods only used by MCJIT to MCJIT.Rafael Espindola
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
2014-11-26Object/COFF: Fix off-by-one error for object having lots of relocationsRui Ueyama
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
2014-11-25COFF: Add back an assertion that is superseded by r222124David Majnemer
llvm-svn: 222735
2014-11-19llvm-readobj: fix off-by-one error in COFFDumperRui Ueyama
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
2014-11-19llvm-readobj: teach it how to dump COFF base relocation tableRui Ueyama
llvm-svn: 222289
2014-11-17Object, COFF: Tighten the object file parserDavid Majnemer
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
2014-11-14obj2yaml, yaml2obj: Add support for COFF executablesDavid Majnemer
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
2014-11-13Un-break the big-endian buildbotsRui Ueyama
llvm-svn: 221919
2014-11-13Object, COFF: Refactor code to get relocation iteratorsDavid Majnemer
No functional change intended. llvm-svn: 221880
2014-11-13Object, COFF: Increase code reuseDavid Majnemer
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
2014-11-13Object, COFF: getRelocationSymbol shouldn't assertDavid Majnemer
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
2014-11-13Object, COFF: Cleanup some code in getSectionNameDavid Majnemer
Use StringRef::startswith to tidy up some code, no functionality change intended. llvm-svn: 221869
2014-11-13Object, COFF: Fix some theoretical bugsDavid Majnemer
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
2014-11-13llvm-readobj: Print out address table when dumping COFF delay-import tableRui Ueyama
llvm-svn: 221855
2014-11-06Object, COFF: Don't consider AuxFunctionDefinition for getSymbolSizeDavid Majnemer
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
2014-11-06Object, COFF: Infer symbol sizes from adjacent symbolsDavid Majnemer
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
2014-11-05llvm-readobj: Add support for dumping the DOS header in PE filesDavid Majnemer
llvm-svn: 221333
2014-10-31Object, COFF: Cleanup symbol type code, improve binutils compatibilityDavid Majnemer
Do a better job classifying symbols. This increases the consistency between the COFF handling code and the ELF side of things. llvm-svn: 220952
2014-10-09Object, COFF: Move the VirtualSize/SizeOfRawData logic to getSectionSizeDavid Majnemer
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
2014-10-09Object, COFF: Cap the section contents to min(VirtualSize, SizeOfRawData)David Majnemer
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
2014-10-09Object: Add range iterators for COFF import/export tableRui Ueyama
llvm-svn: 219383
2014-10-08Correctly compute the size of common symbols in COFF.Rafael Espindola
llvm-svn: 219324
2014-10-08Remove bogus std::error_code returns form SectionRef.Rafael Espindola
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
2014-10-07Don't check for null after calling COFFObjectFile::toSec.Rafael Espindola
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
2014-10-07Optimize COFFObjectFile::sectionContainsSymbol a bit.Rafael Espindola
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
2014-10-03llvm-readobj: print out the fields of the COFF delay-import tableRui Ueyama
llvm-svn: 218996
2014-10-03llvm-readobj: print COFF delay-load import tableRui Ueyama
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
2014-10-02llvm-readobj: print COFF imported symbolsRui Ueyama
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
2014-10-02This patch adds a new flag "-coff-imports" to llvm-readobj.Rui Ueyama
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
2014-09-26Object: BSS/virtual sections don't have contentsDavid Majnemer
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
2014-09-11Support: Delete {aligned_,}{u,}{little,big}8_tRui Ueyama
The byte has no endianness, so these types don't make sense. uint8_t should be used instead. llvm-svn: 217631
2014-09-10Attempt to pacify buildbots.David Majnemer
llvm-svn: 217499
2014-09-10Object: Add support for bigobjDavid Majnemer
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
2014-08-27Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper
just letting them be implicitly created. llvm-svn: 216525
2014-08-19Don't own the buffer in object::Binary.Rafael Espindola
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
2014-08-17llvm-objdump: don't print relocations in non-relocatable files.Rafael Espindola
This matches the behavior of GNU objdump. llvm-svn: 215844
2014-08-08Delete dead code. NFC.Rafael Espindola
llvm-svn: 215224
2014-08-08getLoadName is only implemented for ELF, make it ELF only.Rafael Espindola
llvm-svn: 215219
2014-07-31Use std::unique_ptr to make the ownership explicit.Rafael Espindola
llvm-svn: 214377
2014-06-24Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola
Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. llvm-svn: 211595