summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/WindowsResource.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [LLD] [COFF] Implement MinGW default manifest handlingMartin Storsjo2019-09-041-5/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In mingw environments, resources are normally compiled to resource object files directly, instead of letting the linker convert them to COFF format. Since some time, GCC supports the notion of a default manifest object. When invoking the linker, GCC looks for the default manifest object file, and if found in the expected path, it is added to linker commands. The default manifest is one that indicates support for the latest known versions of windows, to implicitly unlock the modern behaviours of certain APIs. Not all mingw/gcc distributions include this file, but e.g. in msys2, the default manifest object is distributed in a separate package (which can be but might not always be installed). This means that even if user projects only use one single resource object file, the linker can end up with two resource object files, and thus needs to support merging them. The default manifest has a language id of zero, and GNU ld has got logic for dropping a manifest with a zero language id, if there's another manifest present with a nonzero language id. If there are multiple manifests with a nonzero language id, the merging process errors out. Differential Revision: https://reviews.llvm.org/D66825 llvm-svn: 370974
* [LLD] [COFF] Support merging resource object filesMartin Storsjo2019-08-301-0/+124
| | | | | | | | | | | | | | | | | | | | | | | | Extend WindowsResourceParser to support using a ResourceSectionRef for loading resources from an object file. Only allow merging resource object files in mingw mode; keep the existing error on multiple resource objects in link mode. If there only is one resource object file and no .res resources, don't parse and recreate the .rsrc section, but just link it in without inspecting it. This allows users to produce any .rsrc section (outside of what the parser supports), just like before. (I don't have a specific need for this, but it reduces the risk of this new feature.) Separate out the .rsrc section chunks in InputFiles.cpp, and only include them in the list of section chunks to link if we've determined that there only was one single resource object. (We need to keep other chunks from those object files, as they can legitimately contain other sections as well, in addition to .rsrc section chunks.) Differential Revision: https://reviews.llvm.org/D66824 llvm-svn: 370436
* [WindowsResource] Remove use of global variables in WindowsResourceParserMartin Storsjo2019-08-301-58/+45
| | | | | | | | | | | | | | | | Instead of updating a global variable counter for the next index of strings and data blobs, pass along a reference to actual data/string vectors and let the TreeNode insertion methods add their data/strings to the vectors when a new entry is needed. Additionally, if the resource tree had duplicates, that were ignored with -force:multipleres in lld, we no longer store all versions of the duplicated resource data, now we only keep the one that actually ends up referenced. Differential Revision: https://reviews.llvm.org/D66823 llvm-svn: 370435
* [WindowsResource] Avoid duplicating the input filenames for each resource. NFC.Martin Storsjo2019-08-301-4/+5
| | | | | | Differential Revision: https://reviews.llvm.org/D66821 llvm-svn: 370434
* Be explicit about Windows coff name trailing character policySerge Guelton2019-08-211-6/+14
| | | | | | | | | | It's okay to *not* copy the trailing zero of a windows section/symbol name. This is compatible with strncpy behavior but gcc doesn't know that and throws an invalid warning. Encode this behavior in a proper function. Differential Revision: https://reviews.llvm.org/D66420 llvm-svn: 369501
* lld-link: Reject more than one resource .obj fileNico Weber2019-06-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Users are exepcted to pass all .res files to the linker, which then merges all the resource in all .res files into a tree structure and then converts the final tree structure to a .obj file with .rsrc$01 and .rsrc$02 sections and then links that. If the user instead passes several .obj files containing such resources, the correct thing to do would be to have custom code to merge the trees in the resource sections instead of doing normal section merging -- but link.exe rejects if multiple resource obj files are passed in with LNK4078, so let lld-link do that too instead of silently writing broken .rsrc sections in that case. The only real way to run into this is if users manually convert .res files to .obj files by running cvtres and then handing the resulting .obj files to lld-link instead, which in practice likely never happens. (lld-link is slightly stricter than link.exe now: If link.exe is passed one .obj file created by cvtres, and a .res file, for some reason it just emits a warning instead of an error and outputs strange looking data. lld-link now errors out on mixed input like this.) One way users could accidentally run into this is the following scenario: If a .res file is passed to lib.exe, then lib.exe calls cvtres.exe on the .res file before putting it in the output .lib. (llvm-lib currently doesn't do this.) link.exe's /wholearchive seems to only add obj files referenced from the static library index, but lld-link current really adds all files in the archive. So if lld-link /wholearchive is used with .lib files produced by lib.exe and .res files were among the files handed to lib.exe, we previously silently produced invalid output, but now we error out. link.exe's /wholearchive semantics on the other hand mean that it wouldn't load the resource object files from the .lib file at all. Since this scenario is probably still an unlikely corner case, the difference in behavior here seems fine -- and lld-link might have to change to use link.exe's /wholearchive semantics in the future anyways. Vaguely related to PR42180. Differential Revision: https://reviews.llvm.org/D63109 llvm-svn: 363078
* Let writeWindowsResourceCOFF() take a TimeStamp parameterNico Weber2019-06-111-15/+11
| | | | | | | | | | | | | | | | | | | For lld, pass in Config->Timestamp (which is set based on lld's /timestamp: and /Brepro flags). Since the writeWindowsResourceCOFF() data is only used in-memory by LLD and the obj's timestamp isn't used for anything in the output, this doesn't change behavior. For llvm-cvtres, add an optional /timestamp: parameter, and use the current behavior of calling time() if the parameter is not passed in. This doesn't really change observable behavior (unless someone passes /timestamp: to llvm-cvtres, which wasn't possible before), but it removes the last unqualified call to time() from llvm/lib, which seems like a good thing. Differential Revision: https://reviews.llvm.org/D63116 llvm-svn: 363050
* lld-link: Add /force:multipleres extension to make dupe resource diag non-fatalNico Weber2019-05-021-7/+9
| | | | | | | As a side benefit, lld-link now reports more than one duplicate resource entry before exiting with an error even if the new flag is not passed. llvm-svn: 359829
* lld-link: Make "duplicate resource" error message a bit more conciseNico Weber2019-05-021-4/+6
| | | | | | | | | | | | | | | | Reduces the error message from: lld-link: error: failed to parse .res file: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res To: lld-link: error: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res Make sure every error message emitted by cvtres contains the name of at least one ".res" file, so that removing the "failed to parse .res file" string doesn't lose information. Differential Revision: https://reviews.llvm.org/D61388 llvm-svn: 359749
* llvm-cvtres: Attempt to make llvm-cvtres/duplicate.test work on big-endian ↵Nico Weber2019-04-291-12/+14
| | | | | | systems llvm-svn: 359414
* llvm-cvtres: Make new dupe resource error a bit friendlierNico Weber2019-04-241-7/+34
| | | | | | | | | | | | For well-known type IDs, include the name of the type. To not duplicate the ID->name map, make llvm-readobj call this new function as well. It has slightly different output, so this also requires updating a few tests. Differential Revision: https://reviews.llvm.org/D61086 llvm-svn: 359153
* Let llvm-cvtres (and lld-link) report duplicate resourcesNico Weber2019-04-241-23/+63
| | | | | | | | | | | | | | | | | If two .res files contain the same resource, cvtres.exe (and hence link.exe) reject the input with this message: CVTRES : fatal error CVT1100: duplicate resource. type:STRING, name:101, language:0x0409 LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt llvm-cvtres (and lld-link) used to silently pick one of the duplicate resources instead. This patch makes them report an error as well. We slightly improve on cvtres by printing the name of two .res files containing duplicate entries as well. Differential Revision: https://reviews.llvm.org/D61049 llvm-svn: 359083
* llvm-cvtres: Split addChild(ID) into two functionsNico Weber2019-04-231-13/+23
| | | | | | | | | | | Before, there was an IsData parameter. Now, there are two different functions for data nodes and ID nodes. No behavior change, needed for a follow-up change to make two data nodes (but not two ID nodes) with the same ID an error. For consistency, rename another addChild() overload to addNameChild(). llvm-svn: 359024
* 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
* Use llvm::copy. NFCFangrui Song2018-11-171-4/+3
| | | | llvm-svn: 347126
* [Support] Add WritableMemoryBuffer::getNewMemBufferPavel Labath2018-01-091-3/+3
| | | | | | | | | | | | | | | | | | Summary: The idea is that it would replace (non-Writable)MemoryBuffer::getNewMemBuffer, which is quite useless unless you const_cast its contents to write to it (which all (both) callers of this function were doing). This patch also fixes one of the usages in COFFWriter. After fixing the other usage in clang, I plan to delete the old function. Reviewers: dblaikie, Bigcheese Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41540 llvm-svn: 322094
* Fix buffer overrun in WindowsResourceCOFFWriter::writeSymbolTable()Bob Haarman2017-12-181-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: We were using sprintf(..., "$R06X", <some uint32_t>) to create strings that are expected to be exactly length 8, but this results in longer strings if the uint32_t is greater than 0xffffff. This change modifies the behavior as follows: - Uses the loop counter instead of the data offset. This gives us sequential symbol names, avoiding collisions as much as possible. - Masks the value to 0xffffff to avoid generating names longer than 8 bytes. - Uses formatv instead of sprintf. Fixes PR35581. Reviewers: ruiu, zturner Reviewed By: ruiu Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D41270 llvm-svn: 321030
* Remove redundant includes from lib/Object.Michael Zolotukhin2017-12-131-1/+0
| | | | llvm-svn: 320625
* [llvm-cvtres] Add support for ARM64Martin Storsjo2017-11-101-14/+5
| | | | | | | | | | | Also change some default cases into llvm_unreachable in WindowsResourceCOFFWriter, to make it easier to find if they are triggerd from within e.g. lld, which supported ARM64 earlier than llvm-cvtres did. Differential Revision: https://reviews.llvm.org/D39892 llvm-svn: 317942
* Fix warnings discovered by rL317076. [-Wunused-private-field]NAKAMURA Takumi2017-11-011-1/+1
| | | | llvm-svn: 317091
* Fix bug 34051 by handling empty .res files gracefully.Eric Beckmann2017-08-241-12/+27
| | | | | | | | | | | | Summary: Previously, llvm-cvtres crashes on .res files which are empty except for the null header. This allows the library to simply pass over them. Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D37044 llvm-svn: 311625
* Revert "Revert "Revert "Revert "Switch external cvtres.exe for llvm's own ↵Eric Beckmann2017-07-081-16/+9
| | | | | | | | | | | | | | | | | | | | resource library."""" This reverts commit 147f45ff24456aea59575fa4ac16c8fa554df46a. Revert "Revert "Revert "Revert "Replace trivial use of external rc.exe by writing our own .res file."""" This reverts commit 61a90a67ed54a1f0dfeab457b65abffa129569e4. The patches were intially reverted because they were causing a failure on CrWinClangLLD. Unfortunately, this was done haphazardly and didn't compile, so the revert was reverted again quickly to fix this. One that was done, the revert of the revert was itself reverted. This allowed me to finally fix the actual bug in r307452. This patch re-enables the code path that had originally been causing the bug, now that it (should) be fixed. llvm-svn: 307460
* Add name offset flags, for parity with cvtres.exe.Eric Beckmann2017-07-071-2/+2
| | | | | | | | | | | | | | | | | | | Summary: The original cvtres.exe sets the high bit when an identifier offset points to a string. Even though this is not mentioned in the spec, and in fact does not seem to cause errors with most cases, for some reason this causes a failure in Chromium where the new resource file is not verified as a new version. This patch sets this high bit flag, and also adds a test case to check that the output of our library is always identical to original cvtres. Reviewers: zturner, ruiu Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D35099 llvm-svn: 307452
* Revert "Revert "Revert "Switch external cvtres.exe for llvm's own resource ↵Eric Beckmann2017-07-051-1/+0
| | | | | | | | | | | | | | library.""" This reverts commit ae21ee0b6cacbc1efaf4d42502e71da2f0eb45c3. The initial revert was done in order to prevent ongoing errors on chromium bots such as CrWinClangLLD. However, this was done haphazardly and I didn't realize there were test and compilation failures, so this revert was reverted. Now that those have been fixed, we can revert the revert of the revert. llvm-svn: 307227
* Revert "Revert "Revert "Replace trivial use of external rc.exe by writing ↵Eric Beckmann2017-07-051-8/+16
| | | | | | | | | | | | | | our own .res file.""" This reverts commit 5fecbbbe5049665d86834cf69d8f75db4f392308. The initial revert was done in order to prevent ongoing errors on chromium bots such as CrWinClangLLD. However, this was done haphazardly and I didn't realize there were test and compilation failures, so this revert was reverted. Now that those have been fixed, we can revert the revert of the revert. llvm-svn: 307226
* Revert "Revert "Replace trivial use of external rc.exe by writing our own ↵Eric Beckmann2017-07-051-16/+8
| | | | | | | | .res file."" This reverts commit 8c8dce3b8f15d6ebaefc35ce88f15a85c8cdbd6e. llvm-svn: 307191
* Revert "Revert "Switch external cvtres.exe for llvm's own resource library.""Eric Beckmann2017-07-051-1/+2
| | | | | | | | This reverts commit 165e578e47f1cd38191120aad23a9020fb5476dd. Forgot to run tests on this. llvm-svn: 307190
* Revert "Switch external cvtres.exe for llvm's own resource library."Eric Beckmann2017-07-051-2/+1
| | | | | | | | | This reverts commit 600d52c278e123dd08bee24c1f00932b55add8de. This patch still seems to break CrWinClangLLD, reverting until I can find root problem. llvm-svn: 307189
* Revert "Replace trivial use of external rc.exe by writing our own .res file."Eric Beckmann2017-07-051-8/+16
| | | | | | | | | This patch still seems to break CrWinClangLLD, reverting this once more until I can discover root problem. This reverts commit 3dbbc8ce43be50ffde2b1c655c6d3a25796fe78b. llvm-svn: 307188
* Revert "Revert "Replace trivial use of external rc.exe by writing our own ↵Eric Beckmann2017-07-011-17/+8
| | | | | | | | | | | | | | | | | | .res file."" Summary: This reverts commit 51931072a7c9a52540baf76fc30ef391d2529a2f. This revert was originally done because the integrations of the new WindowsResource library into LLD was causing error in chromium, due to bugs in how resource sections were handled. These bugs were fixed, meaning that the features may be reintegrated. Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D34922 llvm-svn: 306941
* Fix bug in symbol generation for resource COFFEric Beckmann2017-06-301-1/+1
| | | | | | | | | | | | Symbols in the resource COFF file should be for .rsrc$02, where the actual resource data is, not .rsrc$01, which contains the directory tree. Differential Revision: https://reviews.llvm.org/D34832 Patch by Joe Ranieri. llvm-svn: 306853
* Revert "Replace trivial use of external rc.exe by writing our own .res file."Eric Beckmann2017-06-291-8/+17
| | | | | | | | | | | | | | | This reverts commit d4c7e9fc63c10dbab0c30186ef8575474a704496. This is done in order to address the failure of CrWinClangLLD etc. bots. These throw an error of "side-by-side configuration is incorrect" during compilation, which sounds suspiciously related to these manifest changes. Revert "Switch external cvtres.exe for llvm's own resource library." This reverts commit 71fe8ef283a9dab9a3f21432c98466cbc23990d1. llvm-svn: 306618
* Replace trivial use of external rc.exe by writing our own .res file.Eric Beckmann2017-06-261-16/+8
| | | | | | | | | This patch removes the dependency on the external rc.exe tool by writing a simple .res file using our own library. In this patch I also added an explicit definition for the .res file magic. Furthermore, I added a unittest for embeded manifests and fixed a bug exposed by the test. llvm-svn: 306311
* Have writeCOFFWriter return Expected<unique_ptr>.Eric Beckmann2017-06-191-16/+14
| | | | | | | | | | | | Summary: Have writeCOFFWriter return Expected<unique_ptr> instead of requiring being passed an uninitialized unique_ptr. Reviewers: zturner, ruiu Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D34307 llvm-svn: 305730
* Clean up some things in the WindowsResource changes.Eric Beckmann2017-06-161-102/+93
| | | | llvm-svn: 305596
* [Object] Remove redundant std::move.Benjamin Kramer2017-06-161-1/+1
| | | | | | Found by -Wpessimizing-move. llvm-svn: 305595
* Switch external cvtres.exe for llvm's own resource library.Eric Beckmann2017-06-161-29/+24
| | | | | | | | | | | | | | | | | | | | | | | | In this patch, I flip the switch in DriverUtils from using the external cvtres.exe tool to using the Windows Resource library in llvm. I also fixed a bug where .rsrc sections were marked as discardable memory and therefore were placed in the wrong order in the final PE. Furthermore, I modified WindowsResource to write the coff directly to a memory buffer instead of to file, also had it use the machine types already declared in COFF.h instead creating my own enum. Finally, I flipped the switch to allow all unit tests that had previously run only on windows due to a winres dependency to run cross-platform. Reviewers: zturner, ruiu Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D34265 llvm-svn: 305592
* Use reference to iterate through string table instead of copying.Eric Beckmann2017-06-131-1/+1
| | | | | | | | | | Summary: just a quick patch Subscribers: ruiu, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D34171 llvm-svn: 305324
* Fix a bug introduced in r305092 on big-endian systems.Eric Beckmann2017-06-131-3/+1
| | | | | | | | | | | | | | Summary: We were writing the length of the string based on system-endianness, and not universally little-endian. This fixes that. Reviewers: zturner Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D34159 llvm-svn: 305322
* Fix alignment complaint.Eric Beckmann2017-06-131-3/+2
| | | | | | | | | | Summary: Apparently we need to write using a void* pointer on some architectures, or else alignment error is caused. Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D34166 llvm-svn: 305320
* Improve error messages in order to help with fixing a big-endian bug.Eric Beckmann2017-06-131-3/+3
| | | | | | | | | | | | Summary: Added output to stderr so that we can actually see what is happening when the test fails on big endian. Reviewers: zturner Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D34155 llvm-svn: 305314
* Revert "Revert "Fix alignment bug in COFF emission.""Eric Beckmann2017-06-131-46/+67
| | | | | | | | | | This revert was done so that my other patch to add test framework could land separately. Now the revert can be reverted and this patch can reland. This reverts commit 18b3c75b2b0d32601fb60a06b9672c33d6f0dff9. llvm-svn: 305259
* Update the test framework for llvm-cvtres to be more comprehensive.Eric Beckmann2017-06-131-15/+21
| | | | | | | | | | Summary: Added test cases for multiple machine types, file merging, multiple languages, and more resource types. Also fixed new bugs these tests exposed. Subscribers: javed.absar, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D34047 llvm-svn: 305258
* Revert "Fix alignment bug in COFF emission."Eric Beckmann2017-06-131-88/+61
| | | | | | | | | I accidentally combined this patch with one for adding more tests, they should be separated. This reverts commit 3da218a523be78df32e637d3446ecf97c9ea0465. llvm-svn: 305257
* Fix alignment bug in COFF emission.Eric Beckmann2017-06-131-61/+88
| | | | | | | | | | | | Summary: Fix alignment issue in D34020, by aligning all sections to 8 bytes. Reviewers: zturner Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D34072 llvm-svn: 305256
* Fix a ubsan failure introduced by r305092Vedant Kumar2017-06-101-2/+2
| | | | | | | | | | | | lib/Object/WindowsResource.cpp:578:3: runtime error: store to misaligned address 0x7fa09aedebbe for type 'unsigned int', which requires 4 byte alignment 0x7fa09aedebbe: note: pointer points here 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ llvm-svn: 305149
* Implement COFF emission for parsed Windows Resource ( .res) files.Eric Beckmann2017-06-091-9/+507
| | | | | | | | | | | | Summary: Add the WindowsResourceCOFFWriter class for producing the final COFF after all parsing is done. Reviewers: hiraditya!, zturner, ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34020 llvm-svn: 305092
* 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
* Fix bug on Big-Endian system, due to reference to vector out of scope.Eric Beckmann2017-05-301-1/+1
| | | | llvm-svn: 304255
* This patch should fix various clang warnings and a use of to_stringEric Beckmann2017-05-301-1/+2
| | | | | | which isn't support before c++11. llvm-svn: 304252
OpenPOWER on IntegriCloud