summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/COFFObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [COFF] Add a ResourceSectionRef method for getting resource contentsMartin Storsjo2019-08-301-0/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows llvm-readobj to print the contents of each resource when printing resources from an object file or executable, like it already does for plain .res files. This requires providing the whole COFFObjectFile to ResourceSectionRef. This supports both object files and executables. For executables, the DataRVA field is used as is to look up the right section. For object files, ideally we would need to complete linking of them and fix up all relocations to know what the DataRVA field would end up being. In practice, the only thing that makes sense for an RVA field is an ADDR32NB relocation. Thus, find a relocation pointing at this field, verify that it has the expected type, locate the symbol it points at, look up the section the symbol points at, and read from the right offset in that section. This works both for GNU windres object files (which use one single .rsrc section, with all relocations against the base of the .rsrc section, with the original value of the DataRVA field being the offset of the data from the beginning of the .rsrc section) and cvtres object files (with two separate .rsrc$01 and .rsrc$02 sections, and one symbol per data entry, with the original pre-relocated DataRVA field being set to zero). Differential Revision: https://reviews.llvm.org/D66820 llvm-svn: 370433
* [COFF] Add a ResourceSectionRef method for getting the data entry, print it ↵Martin Storsjo2019-08-291-0/+18
| | | | | | | | in llvm-readobj Differential Revision: https://reviews.llvm.org/D66819 llvm-svn: 370311
* [COFF] Add a bounds checking helper for iterating a coff_resource_dir_tableMartin Storsjo2019-08-291-0/+22
| | | | | | | | | | Instead of blindly incrementing pointers in llvm-readobj, use this helper, which does bounds checking against the available section data. Differential Revision: https://reviews.llvm.org/D66818 llvm-svn: 370310
* [COFF] Fix error handling in ResourceSectionRefMartin Storsjo2019-08-291-3/+6
| | | | | | | | | | | Previously, the expression (Reader.readFoo()) was expanded twice, triggering asserts as one of the Error types ends up not checked (and as it was expanded twice, the method would end up called twice if it failed first). Differential Revision: https://reviews.llvm.org/D66817 llvm-svn: 370309
* [Object/COFF.h] - Stop returning std::error_code in a few methods. NFCI.George Rimar2019-08-191-23/+0
| | | | | | | | | | There are 4 methods that return std::error_code now, though they do not have to because they are always succeed. I refactored them. This allows to simplify the code in tools a bit. llvm-svn: 369263
* Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar2019-08-141-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Expected<>" Changes: no changes. A fix for the clang code will be landed right on top. Original commit message: SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368826
* Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar2019-08-141-5/+4
| | | | | | | | Expected<>" It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455 llvm-svn: 368813
* [llvm/Object] - Convert SectionRef::getName() to return Expected<>George Rimar2019-08-141-4/+5
| | | | | | | | | | | | | | | | | | | | | | | SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368812
* [Object] Change ObjectFile::getSectionContents to return ↵Fangrui Song2019-05-141-11/+10
| | | | | | | | | | | | | | | | | | | Expected<ArrayRef<uint8_t>> Change std::error_code getSectionContents(DataRefImpl, StringRef &) const; to Expected<ArrayRef<uint8_t>> getSectionContents(DataRefImpl) const; Many object formats use ArrayRef<uint8_t> as the underlying type, which is generally better than StringRef to represent binary data, so change the type to decrease the number of type conversions. Reviewed By: ruiu, sbc100 Differential Revision: https://reviews.llvm.org/D61781 llvm-svn: 360648
* [Object] Change getSectionName() to return Expected<StringRef>Fangrui Song2019-05-021-10/+10
| | | | | | | | | | Summary: It currently receives an output parameter and returns std::error_code. Expected<StringRef> fits for this purpose perfectly. Differential Revision: https://reviews.llvm.org/D61421 llvm-svn: 359774
* [COFF] Fix delay import directory iteratorJoseph Tremoulet2019-04-041-1/+1
| | | | | | | | | | | | | | | | | | Summary: Take the Index into account in `getDelayImportTable`, otherwise we always return the entry for the first delay DLL reference. Reviewers: ruiu Reviewed By: ruiu Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60081 llvm-svn: 357697
* [COFF] Add new relocation types.Martin Storsjo2019-01-271-0/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D57291 llvm-svn: 352324
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [llvm-readobj] [COFF] Print the symbol index for relocationsMartin Storsjo2019-01-031-0/+10
| | | | | | | | | | There can be multiple local symbols with the same name (for e.g. comdat sections), and thus the symbol name itself isn't enough to disambiguate symbols. Differential Revision: https://reviews.llvm.org/D56140 llvm-svn: 350288
* [llvm-objcopy] Initial COFF supportMartin Storsjo2018-12-191-0/+12
| | | | | | | | | This is an initial implementation of no-op passthrough copying of COFF with objcopy. Differential Revision: https://reviews.llvm.org/D54939 llvm-svn: 349605
* [COFF] Map truncated .eh_frame section nameMartin Storsjo2018-12-081-0/+6
| | | | | | | | | | | | | | | PE/COFF sections can have section names truncated to 8 chars, in order to have the name available at runtime. (The string table, where long untruncated names are stored, isn't loaded at runtime.) This allows various llvm tools to dump the .eh_frame section from such executables. Patch by Peiyuan Song! Differential Revision: https://reviews.llvm.org/D55407 llvm-svn: 348708
* Handle zero-length debug directory entries.Nico Weber2018-09-051-4/+6
| | | | | | Part of https://reviews.llvm.org/D51652 (tests will be in the lld repo) llvm-svn: 341485
* [COFF] Expose an easier helper function for getting names for relocation typesMartin Storsjo2018-08-271-16/+18
| | | | | | | | | The existing method is protected, and requires using DataRefImpl and SmallVector. Differential Revision: https://reviews.llvm.org/D50995 llvm-svn: 340725
* Remove trailing spaceFangrui Song2018-07-301-1/+1
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
* [COFF] Adjust how we flag weak externalsMartin Storsjo2018-07-201-4/+4
| | | | | | | | | | This fixes PR36096. Originally based on a patch by Martell Malone. Differential Revision: https://reviews.llvm.org/D44357 llvm-svn: 337613
* [llvm-readobj] Add -hex-dump (-x) optionPaul Semel2018-07-111-0/+15
| | | | | | Differential Revision: https://reviews.llvm.org/D48281 llvm-svn: 336782
* [llvm-objdump] Add --file-headers (-f) optionPaul Semel2018-07-041-0/+6
| | | | llvm-svn: 336284
* COFF: Make SectionChunk::Relocs field an ArrayRef. NFCI.Peter Collingbourne2018-04-171-6/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D45714 llvm-svn: 330172
* [NFC] fix trivial typos in documents and commentsHiroshi Inoue2018-04-121-1/+1
| | | | | | "is is" -> "is", "if if" -> "if", "or or" -> "or" llvm-svn: 329878
* Fix many -Wsign-compare and -Wtautological-constant-compare warnings.Zachary Turner2017-12-141-1/+1
| | | | | | | | | | | | Most of the -Wsign-compare warnings are due to the fact that enums are signed by default in the MS ABI, while the tautological comparison warnings trigger on x86 builds where sizeof(size_t) is 4 bytes, so N > numeric_limits<unsigned>::max() is always false. Differential Revision: https://reviews.llvm.org/D41256 llvm-svn: 320750
* Convert the last uses of ErrorOr in COFF.h.Rafael Espindola2017-10-111-7/+6
| | | | llvm-svn: 315480
* Convert a couple of ErrorOr to Expected. NFC.Rafael Espindola2017-10-111-8/+10
| | | | llvm-svn: 315475
* Convert two uses of ErrorOr to Expected.Rafael Espindola2017-10-101-2/+2
| | | | llvm-svn: 315354
* [Object] Verify object sizes before handing out StringRefs pointing outBenjamin Kramer2017-08-311-12/+3
| | | | | | | | | of bounds. This can only happen on corrupt input. Found by OSS-FUZZ! https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3228 llvm-svn: 312235
* llvm: add llvm-dlltool support to the archiverMartell Malone2017-07-181-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
* Revert r308329: llvm: add llvm-dlltool support to the archiverRui Ueyama2017-07-181-4/+1
| | | | | | This reverts commit r308329 because it broke buildbots. llvm-svn: 308374
* llvm: add llvm-dlltool support to the archiverMartell Malone2017-07-181-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
* [llvm-readobj] Improve printouts for COFF ARM64 binariesMartin Storsjo2017-06-301-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D34835 llvm-svn: 306795
* [COFF, ARM64] Add support for Windows ARM64 COFF formatMandeep Singh Grang2017-06-271-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
* [llvm-readobj] Dump the COFF image load configReid Kleckner2017-06-221-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
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-071-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
* Recommit "[DWARF] - Make collectAddressRanges() return section index in ↵George Rimar2017-05-271-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
* Revert r304002 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar2017-05-261-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
* [DWARF] - Make collectAddressRanges() return section index in addition to ↵George Rimar2017-05-261-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
* Revert "[DWARF] - Make collectAddressRanges() return section index in ↵George Rimar2017-05-261-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
* Recommit r303978 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar2017-05-261-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
* Revert r303978 "[DWARF] - Make collectAddressRanges() return section index ↵George Rimar2017-05-261-4/+0
| | | | | | | | in addition to Low/High PC" It failed BB. llvm-svn: 303981
* [DWARF] - Make collectAddressRanges() return section index in addition to ↵George Rimar2017-05-261-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
* [COFF] Gracefully handle empty .drectve sectionsShoaib Meenai2017-05-141-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
* Fix the Endianness bug by adding the little endian UTF marker.Eric Beckmann2017-05-091-2/+0
| | | | | | | | | | | | Summary: Quick fix Reviewers: zturner, uweigand Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33014 llvm-svn: 302573
* Hopefully one last commit to fix this patch, addresses string referenceEric Beckmann2017-05-081-7/+3
| | | | | | issues. llvm-svn: 302401
* Update llvm-readobj -coff-resources to display tree structure.Eric Beckmann2017-05-081-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
* Revert "Hopefully one last commit to fix this patch, addresses string reference"Eric Beckmann2017-05-081-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
* Hopefully one last commit to fix this patch, addresses string referenceEric Beckmann2017-05-081-7/+3
| | | | | | issues. llvm-svn: 302395
* Update llvm-readobj -coff-resources to display tree structure.Eric Beckmann2017-05-071-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
OpenPOWER on IntegriCloud