summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [PECOFF] Set ordinal to alias atomsRui Ueyama2014-09-191-3/+4
| | | | | | | | | | | | | | | | Atoms are ordered in the output file by ordinal. File has file ordinal, and atom has atom ordinal which is unique within the file. No two atoms should have the same combination of ordinals. However that contract was not satisifed for alias atoms. Alias atom is defined by /alternatename:sym1=sym2. In this case sym1 is defined as an alias for sym2. sym1 always got ordinal 0. As a result LLD failed with an assertion failure. This patch assigns ordinal to alias atoms. llvm-svn: 218158
* PECOFF: loosen assumptions about x86-only targetsSaleem Abdulrasool2014-09-191-12/+14
| | | | | | | | | | | | Rather than saving whether we are targeting 64-bit x86 (x86_64), simply convert the single use of that information to the actual relocation type. This will permit the selection of non-x86 relocation types (e.g. for WoA support). Inline the access of the machine type field as it is relatively cheap (a couple of pointer dereferences) rather than storing the relocation type as a member variable. llvm-svn: 218104
* ReaderWriter: print magic in hexSaleem Abdulrasool2014-09-191-1/+3
| | | | | | | | When we encounter an unknown machine type, we print out the machine type magic. However, we would print out the magic in decimal rather than hex. Perform this conversion to make it easier to identify what machine is unsupported. llvm-svn: 218103
* Adjust lld to handle LLVM r217812David Majnemer2014-09-151-1/+2
| | | | llvm-svn: 217815
* [PECOFF] Add support for bigobjDavid Majnemer2014-09-101-79/+73
| | | | | | | | | | | | | | lld shouldn't directly use the COFF header nor should it use raw coff_symbols. Instead, query the header properties from the COFFObjectFile and use COFFSymbolRef to abstractly reference COFF symbols. This is just enough to get lld compiling with the changes to llvm::object. Bigobj specific testing will come later. Differential Revision: http://reviews.llvm.org/D5280 llvm-svn: 217497
* [PECOFF] Explicitly pass machine typeRui Ueyama2014-08-221-3/+2
| | | | | | | x86 and x64 are created equal -- taking x86 as the default argument made it hard to find bugs. llvm-svn: 216295
* [PECOFF] Fix PE+ relocationsRui Ueyama2014-08-221-1/+14
| | | | | | | | | | | | | The implementation of AMD64 relocations was imcomplete and wrong. On AMD64, we of course have to use AMD64 relocations instead of i386 ones. This patch fixes the issue. LLD is now able to link hello64.obj (created from hello64.asm) against user32.lib and kernel32.lib to create a Win64 binary. llvm-svn: 216253
* Remove dead code.Rui Ueyama2014-08-211-1/+0
| | | | llvm-svn: 216152
* Update for llvm api change.Rafael Espindola2014-08-191-3/+4
| | | | llvm-svn: 216003
* [PECOFF] addDeadStripRoot is not thread-safe.Rui Ueyama2014-08-051-8/+14
| | | | llvm-svn: 214835
* [PECOFF] Fix /include option in .drectve section.Rui Ueyama2014-08-041-3/+20
| | | | | | | | | | | | | | | | | | | | | | | /INCLUDE arguments passed as command line options are handled in the same way as Unix -u. All option values are converted to an undefined symbol and added to a dummy input file, so that the specified symbols are resolved. One tricky thing on Windows is that the option is also allowed to appear in the object file's directive section. At the time when it's being read, all (regular) command line options have already been processed. We cannot add undefined atoms to the dummy file anymore. Previously, we added such /INCLUDE to a set that has already been processed. As a result the options were ignored. This patch fixes the issue. Now, /INCLUDE symbols in the directive section are handled as real undefined symbol in the COFF file. We create an undefined symbol for each /INCLUDE argument and add it to the file being parsed. llvm-svn: 214824
* [PECOFF] Remove unused paraemter.Rui Ueyama2014-08-041-3/+2
| | | | llvm-svn: 214791
* Update for llvm api change.Rafael Espindola2014-07-311-1/+1
| | | | llvm-svn: 214378
* Fix lld build for llvm API changes committed in r213557David Blaikie2014-07-211-1/+1
| | | | llvm-svn: 213560
* [PECOFF] Invoke cvtres.exe in the driver.Rui Ueyama2014-07-101-109/+0
| | | | | | | | | | | | | | | | | Previously we invoked cvtres.exe for each compiled Windows resource file. The generated files were then concatenated and embedded to the executable. That was not the correct way to merge compiled Windows resource files. If you just concatenate generated files, only the first file would be recognized and the rest would be ignored as trailing garbage. The right way to merge them is to call cvtres.exe with multiple input files. In this patch we do that in the Windows driver. llvm-svn: 212763
* [PECOFF] Fix .bss section alignmentRui Ueyama2014-07-081-4/+5
| | | | | | | | | | Previously the alignment of the .bss section was not properly set because of a bug in AtomizeDefinedSymbolsInSection. We set the alignment of the section at the end of the function, but we use an eraly return for the .bss section, so the code had been skipped. llvm-svn: 212571
* Update for llvm api change.Rafael Espindola2014-07-061-3/+4
| | | | llvm-svn: 212407
* Update for llvm api change.Rafael Espindola2014-06-231-1/+1
| | | | llvm-svn: 211548
* [PECOFF] Support COMDAT associative sections.Rui Ueyama2014-06-171-11/+41
| | | | | | | | | | | | | | | | | | | COFF supports a feature similar to ELF's section groups. This patch implements it. In ELF, section groups are identified by their names, and they are treated somewhat differently from regular symbols. In COFF, the feature is realized in a more straightforward way. A section can have an annotation saying "if Nth section is linked, link this section too." I added a new reference type, kindAssociate. If a target atom is coalesced away, the referring atom is removed by Resolver, so that they are treated as a group. Differential Revision: http://reviews.llvm.org/D4028 llvm-svn: 211106
* Update for llvm api change.Rafael Espindola2014-06-131-2/+3
| | | | llvm-svn: 210919
* include system_error directly.Rafael Espindola2014-06-121-1/+1
| | | | llvm-svn: 210801
* Run llvm/utils/sort_includes.py in a few files.Rafael Espindola2014-06-121-3/+0
| | | | | | This will reduce the noise in a followup patch. llvm-svn: 210800
* Don't import error_code into the lld namespace.Rafael Espindola2014-06-121-110/+119
| | | | llvm-svn: 210785
* Move Simple.h and Alias.h to include/Core.Rui Ueyama2014-06-111-1/+1
| | | | | | | | Because the files in Core actually depend on these files. Differential Revision: http://reviews.llvm.org/D4000 llvm-svn: 210710
* Use std::error_code instead of llvm::error_code.Rafael Espindola2014-06-111-2/+2
| | | | | | This is an update for a llvm api change. llvm-svn: 210689
* Revert "[PECOFF] Support COMDAT associative sections."Rui Ueyama2014-06-051-40/+11
| | | | | | This reverts accidental commit r210240. llvm-svn: 210243
* [PECOFF] Support COMDAT associative sections.Rui Ueyama2014-06-051-11/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | COFF supports a feature similar to ELF's section groups. This patch implements it. In ELF, section groups are identified by their names, and they are treated somewhat differently from regular symbols. In COFF, the feature is realized in a more straightforward way. A section can have an annotation saying "if Nth section is linked, link this section too." Implementing such feature is easy. We can add a reference from a target atom to an original atom, so that if the target is linked, the original atom is also linked. If not linked, both will be dead-stripped. So they are treated as a group. I added a new reference type, kindAssociate. It does nothing except preventing referenced atoms from being dead-stripped. No change to the Resolver is needed. Reviewers: Bigcheese, shankarke, atanasyan Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D3946 llvm-svn: 210240
* Improve error message.Rui Ueyama2014-06-031-3/+3
| | | | | | | Previously the parser always printed out an error message followed by "Invalid file type" even if the file type is correct. llvm-svn: 210093
* Run clang-format.Rui Ueyama2014-06-021-62/+61
| | | | llvm-svn: 210015
* s/vector/std::vector/Rui Ueyama2014-06-021-22/+21
| | | | llvm-svn: 210014
* Use error_code() instead of error_code::succes()Rafael Espindola2014-05-311-27/+27
| | | | | | | There is no std::error_code::success, so this removes much of the noise in transitioning to std::error_code. llvm-svn: 209948
* Use short identifier.Rui Ueyama2014-05-231-7/+7
| | | | llvm-svn: 209497
* [PECOFF] Make a separate pass for /alternatename symbols.Rui Ueyama2014-05-231-27/+44
| | | | | | | | | | | | | | | | | | | | | | | /alternatename is a command line option to define a weak alias. You can use it as /alternatename:foo=bar to define "foo" as a weak alias for "bar". Because it's a command line option, the weak alias mapping is in the LinkingContext object, and not in a object file being read. Previously, we looked up the mapping each time we read a new symbol from a file, to check if there is a weak alias defined for the symbol. That's not wrong, but had made function signature's a bit complicated -- we had to pass the mapping object to many functions. Now their parameter lists are much cleaner. This also has another (unrealized) benefit. parseFile() now read a file and then add alias symbols to the file. In the first pass a LinkingContext object is not used at all. That should make it easy to read files from archive files speculatively, as the first pass is free from side effect. llvm-svn: 209486
* [PECOFF] Check for a Characteristics field of a .debug section.Rui Ueyama2014-05-211-1/+3
| | | | llvm-svn: 209317
* [PECOFF] Discard .debug sections.Rui Ueyama2014-05-211-0/+7
| | | | llvm-svn: 209274
* [PECOFF] Make COFFObjectReader thread-safe.Rui Ueyama2014-05-211-0/+3
| | | | llvm-svn: 209271
* [PECOFF] Skip IMAGE_SYM_DEBUG sections correctly.Rui Ueyama2014-04-221-6/+8
| | | | | | | | | We don't use sections with IMAGE_SYM_DEBUG attribute so we basically want to the symbols for them when reading symbol table. When we skip them, we need to skip auxiliary symbols too. Otherwise weird error would happen because aux symbols would be interpreted as regular ones. llvm-svn: 206931
* [Modules] Fix potential ODR violations by sinking the DEBUG_TYPEChandler Carruth2014-04-221-2/+2
| | | | | | | | | | definition below all of the header #include lines, LLD edition. IF you want to know more details about this, you can see the recent commits to Debug.h in LLVM. This is just the LLD segment of a cleanup I'm doing globally for this macro. llvm-svn: 206851
* [PECOFF] Fix common symbol alignment.Rui Ueyama2014-04-091-0/+8
| | | | | | Differential Revision: http://reviews.llvm.org/D3322 llvm-svn: 205826
* [PECOFF] Support yet another new type of weak symbol.Rui Ueyama2014-03-181-1/+3
| | | | | | | | | | COMDAT_SELECT_LARGEST is a COMDAT type that make linker to choose the largest definition from among all of the definition of a symbol. If the size is the same, the choice is arbitrary. Differential Revision: http://llvm-reviews.chandlerc.com/D3011 llvm-svn: 204172
* Fix lld buildAlexey Samsonov2014-03-181-12/+8
| | | | llvm-svn: 204122
* [PECOFF] Data type of SectionNumber is now unsigned (r203986).Rui Ueyama2014-03-151-4/+2
| | | | | | So we don't need static_cast's to convert it from signed to unsigned. llvm-svn: 203992
* [PECOFF] Handle large objects having more than 32768 sections.Rui Ueyama2014-03-141-2/+4
| | | | | | | The COFF spec says that the SectionNumber field in the symbol table is 16 bit signed type, but MSVC treats the field as if it is unsigned. llvm-svn: 203901
* Replace OwningPtr with std::unique_ptr.Ahmed Charles2014-03-131-6/+5
| | | | | | | | This results in some simplifications to the code where an OwningPtr had to be used with the previous api and then ownership moved to a unique_ptr for the rest of lld. llvm-svn: 203809
* [PECOFF] Handle objects with unknown machine type header value.Rui Ueyama2014-03-131-0/+3
| | | | | | | | | An object whose machine type header value is unknown looks a bit odd but is valid. If an object contains only machine-type-independent data, you can leave the type field unspecified. Some files in oldname.lib are such object files. llvm-svn: 203752
* [PECOFF] Support a new type of weak symbol.Rui Ueyama2014-03-071-1/+3
| | | | | | | | | | | | | | | Summary: COMDAT_SELECT_SAME_SIZE is a COMDAT type that I presume exist only in COFF. The semantics of the type is that linker should merge such COMDAT sections if their sizes are the same. Otherwise it's an error. Reviewers: Bigcheese, shankarke, kledzik CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2996 llvm-svn: 203308
* Add "override" to member functions where appropriate.Rui Ueyama2014-03-051-13/+13
| | | | llvm-svn: 202998
* [PECOFF] Emit Load Configuration and SEH Table for x86.Rui Ueyama2014-02-261-4/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | If all input files are compatible with Structured Exception Handling, linker is supposed to create an exectuable with a table for SEH handlers. The table consists of exception handlers entry point addresses. The basic idea of SEH in x86 Microsoft ABI is to list all valid entry points of exception handlers in an read-only memory, so that an attacker cannot override the addresses in it. In x86 ABI, data for exception handling is mostly on stack, so it's volnerable to stack overflow attack. In order to protect against it, Windows runtime uses the table to check a return address, to ensure that the address is really an valid entry point for an exception handler. Compiler emits a list of exception handler functions to .sxdata section. It also emits a marker symbol "@feat.00" to indicate that the object is compatible with SEH. SEH is a relatively new feature for COFF, and mixing SEH-compatible and SEH-incompatible objects will result in an invalid executable, so is the marker. If all input files are compatible with SEH, LLD emits a SEH table. SEH table needs to be pointed by Load Configuration strucutre, so when emitting a SEH table LLD emits it too. The address of a Load Configuration will be stored to the file header. llvm-svn: 202248
* [COFF] Refactor .drectve section handling. No functionality change.Rui Ueyama2014-02-251-7/+18
| | | | llvm-svn: 202113
* [PECOFF] Fix uninitialized variableNico Rieck2014-02-231-1/+2
| | | | llvm-svn: 201970
OpenPOWER on IntegriCloud