summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Symbols.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [LLD] [COFF] Always demangle the __imp_ prefix to __declspec(dllimport)Martin Storsjo2019-10-041-3/+5
| | | | | | Differential Revision: https://reviews.llvm.org/D68017 llvm-svn: 373781
* [LLD] [COFF] Use the unified llvm demangle frontend function. NFC.Martin Storsjo2019-09-271-15/+15
| | | | | | | | Add test cases for some cases where we don't want demangling to happen. Differential Revision: https://reviews.llvm.org/D67301 llvm-svn: 373075
* reland "[lld-link] implement -start-lib and -end-lib"Bob Haarman2019-09-031-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is a re-land of r370487 with a fix for the use-after-free bug that rev contained. This implements -start-lib and -end-lib flags for lld-link, analogous to the similarly named options in ld.lld. Object files after -start-lib are included in the link only when needed to resolve undefined symbols. The -end-lib flag goes back to the normal behavior of always including object files in the link. This mimics the semantics of static libraries, but without needing to actually create the archive file. Reviewers: ruiu, smeenai, MaskRay Reviewed By: ruiu, MaskRay Subscribers: akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66848 llvm-svn: 370816
* [LLD] [COFF] Demangle itanium symbols in mingw modeMartin Storsjo2019-09-021-1/+12
| | | | | | Differential Revision: https://reviews.llvm.org/D67051 llvm-svn: 370654
* Revert "[lld-link] implement -start-lib and -end-lib"Vlad Tsyrklevich2019-08-301-4/+2
| | | | | | | This reverts commit r370487 as it is causing ASan/MSan failures on sanitizer-x86_64-linux-fast llvm-svn: 370550
* [lld-link] implement -start-lib and -end-libBob Haarman2019-08-301-2/+4
| | | | | | | | | | | | | | | | | | | | | | | Summary: This implements -start-lib and -end-lib flags for lld-link, analogous to the similarly named options in ld.lld. Object files after -start-lib are included in the link only when needed to resolve undefined symbols. The -end-lib flag goes back to the normal behavior of always including object files in the link. This mimics the semantics of static libraries, but without needing to actually create the archive file. Reviewers: ruiu, smeenai, MaskRay Reviewed By: ruiu, MaskRay Subscribers: akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66848 llvm-svn: 370487
* [COFF] Add libcall symbols to the link when LTO is being usedAmy Huang2019-08-221-0/+9
| | | | llvm-svn: 369694
* ld.lld: Demangle symbols from archives in diagnosticsNico Weber2019-07-231-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | This ports r366573 from COFF to ELF. There are now to toString(Archive::Symbol), one doing MSVC demangling in COFF and one doing Itanium demangling in ELF, so rename these two to toCOFFString() and to toELFString() to not get a duplicate symbol. Nothing ever passes a raw Archive::Symbol to CHECK(), so these not being part of the normal toString() machinery seems ok. There are two code paths in the ELF linker that emits this type of diagnostic: 1. The "normal" one in InputFiles.cpp. This is covered by the tweaked test. 2. An additional one that's only used for libcalls if there's at least one bitcode in the link, and if the libcall symbol is lazy, and lazily loaded from an archive (i.e. not from a lazy .o file). (This code path was added in r339301.) Since all libcall names so far are C symbols and never mangled, the change there is not observable and hence not covered by tests. Differential Revision: https://reviews.llvm.org/D65095 llvm-svn: 366836
* lld-link: Demangle symbols from archives in diagnosticsNico Weber2019-07-191-4/+7
| | | | | | | | | Also add test coverage for thin archives (which are the only way I could come up with to test at least some of the diagnostic changes). Differential Revision: https://reviews.llvm.org/D64927 llvm-svn: 366573
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-111-50/+50
| | | | | | | | | | | This patch does the same thing as r365595 to other subdirectories, which completes the naming style change for the entire lld directory. With this, the naming style conversion is complete for lld. Differential Revision: https://reviews.llvm.org/D64473 llvm-svn: 365730
* [COFF] Pack Name in Symbol as is done in ELFReid Kleckner2019-04-191-5/+13
| | | | | | | | | | | | | | | | | | | | | | Summary: This assumes all symbols are <4GB long, so we can store them as a 32-bit integer. This reorders the fields so the length appears first, packing with the other bitfield data in the base Symbol object. This saved 70MB / 3.60% of heap allocations when linking browser_tests.exe with no PDB. It's not much as a percentage, but worth doing. I didn't do performance measurements, I don't think it will be measurable in time. Reviewers: ruiu, inglorion, amccarth, aganea Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60297 llvm-svn: 358794
* lld-link: Only print demangled symbol names by defaultNico Weber2019-03-111-2/+5
| | | | | | | | | | | | | | | | | | This makes lld-link's output a bit more concise. Since most developers can't read mangled names, this should make the output a bit easier to understand as well. It also makes lld-link's output consistent with ld.lld's output. (link.exe prints both demangled and mangled names; lld-link used to match link.exe output but now no longer does.) For people working on toolchains, add a `/demangle:no` flag that makes lld-link print the mangled name instead of the demangled name. (If desired, people could pipe that through `demumble -b` to get the old behavior of both demangled and mangled output.) Differential Revision: https://reviews.llvm.org/D58132 llvm-svn: 355878
* 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
* [COFF] When doing automatic dll imports, replace whole .refptr.<var> chunks ↵Martin Storsjo2018-08-311-1/+1
| | | | | | | | | | | | | | | | | | | | with __imp_<var> After fixing up the runtime pseudo relocation, the .refptr.<var> will be a plain pointer with the same value as the IAT entry itself. To save a little binary size and reduce the number of runtime pseudo relocations, redirect references to the IAT entry (via the __imp_<var> symbol) itself and discard the .refptr.<var> chunk (as long as the same section chunk doesn't contain anything else than the single pointer). As there are now cases for both setting the Live variable to true and false externally, remove the accessors and setters and just make the variable public instead. Differential Revision: https://reviews.llvm.org/D51456 llvm-svn: 341175
* [COFF] Support MinGW automatic dllimport of dataMartin Storsjo2018-08-271-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Normally, in order to reference exported data symbols from a different DLL, the declarations need to have the dllimport attribute, in order to use the __imp_<var> symbol (which contains an address to the actual variable) instead of the variable itself directly. This isn't an issue in the same way for functions, since any reference to the function without the dllimport attribute will end up as a reference to a thunk which loads the actual target function from the import address table (IAT). GNU ld, in MinGW environments, supports automatically importing data symbols from DLLs, even if the references didn't have the appropriate dllimport attribute. Since the PE/COFF format doesn't support the kind of relocations that this would require, the MinGW's CRT startup code has an custom framework of their own for manually fixing the missing relocations once module is loaded and the target addresses in the IAT are known. For this to work, the linker (originall in GNU ld) creates a list of remaining references needing fixup, which the runtime processes on startup before handing over control to user code. While this feature is rather controversial, it's one of the main features allowing unix style libraries to be used on windows without any extra porting effort. Some sort of automatic fixing of data imports is also necessary for the itanium C++ ABI on windows (as clang implements it right now) for importing vtable pointers in certain cases, see D43184 for some discussion on that. The runtime pseudo relocation handler supports 8/16/32/64 bit addresses, either PC relative references (like IMAGE_REL_*_REL32*) or absolute references (IMAGE_REL_AMD64_ADDR32, IMAGE_REL_AMD64_ADDR32, IMAGE_REL_I386_DIR32). On linking, the relocation is handled as a relocation against the corresponding IAT slot. For the absolute references, a normal base relocation is created, to update the embedded address in case the image is loaded at a different address. The list of runtime pseudo relocations contains the RVA of the imported symbol (the IAT slot), the RVA of the location the relocation should be applied to, and a size of the memory location. When the relocations are fixed at runtime, the difference between the actual IAT slot value and the IAT slot address is added to the reference, doing the right thing for both absolute and relative references. With this patch alone, things work fine for i386 binaries, and mostly for x86_64 binaries, with feature parity with GNU ld. Despite this, there are a few gotchas: - References to data from within code works fine on both x86 architectures, since their relocations consist of plain 32 or 64 bit absolute/relative references. On ARM and AArch64, references to data doesn't consist of a plain 32 or 64 bit embedded address or offset in the code. On ARMNT, it's usually a MOVW+MOVT instruction pair represented by a IMAGE_REL_ARM_MOV32T relocation, each instruction containing 16 bit of the target address), on AArch64, it's usually an ADRP+ADD/LDR/STR instruction pair with an even more complex encoding, storing a PC relative address (with a range of +/- 4 GB). This could theoretically be remedied by extending the runtime pseudo relocation handler with new relocation types, to support these instruction encodings. This isn't an issue for GCC/GNU ld since they don't support windows on ARMNT/AArch64. - For x86_64, if references in code are encoded as 32 bit PC relative offsets, the runtime relocation will fail if the target turns out to be out of range for a 32 bit offset. - Fixing up the relocations at runtime requires making sections writable if necessary, with the VirtualProtect function. In Windows Store/UWP apps, this function is forbidden. These limitations are addressed by a few later patches in lld and llvm. Differential Revision: https://reviews.llvm.org/D50917 llvm-svn: 340726
* COFF: Don't create unnecessary thunks.Peter Collingbourne2018-05-101-1/+1
| | | | | | | | | A thunk is only needed if a relocation points to the undecorated import name. Differential Revision: https://reviews.llvm.org/D46673 llvm-svn: 332019
* Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.Rui Ueyama2018-02-281-2/+2
| | | | | | | | | This should resolve the issue that lld build fails in some hosts that uses case-insensitive file system. Differential Revision: https://reviews.llvm.org/D43788 llvm-svn: 326339
* Remove an unused accessor and simplify the logic a bit. NFC.Rui Ueyama2018-02-171-1/+1
| | | | llvm-svn: 325445
* Move Memory.{h,cpp} to Common.Rui Ueyama2017-11-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40571 llvm-svn: 319221
* Factor out common code to Common/Strings.cpp.Rui Ueyama2017-11-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40530 llvm-svn: 319138
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-5/+5
| | | | | | | | | | | | | Now that we have only SymbolBody as the symbol class. So, "SymbolBody" is a bit strange name now. This is a mechanical change generated by perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF) nd clang-format-diff. Differential Revision: https://reviews.llvm.org/D39459 llvm-svn: 317370
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-1/+1
| | | | | | | | | | | | | | | | | | | Summary: The COFF linker and the ELF linker have long had similar but separate Error.h and Error.cpp files to implement error handling. This change introduces new error handling code in Common/ErrorHandler.h, changes the COFF and ELF linkers to use it, and removes the old, separate implementations. Reviewers: ruiu Reviewed By: ruiu Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D39259 llvm-svn: 316624
* [PDB] Write public symbol records and the publics hash tableReid Kleckner2017-07-271-0/+11
| | | | | | | | | | | | | | Summary: MSVC link.exe records all external symbol names in the publics stream. It provides similar functionality to an ELF .symtab. Reviewers: zturner, ruiu Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D35871 llvm-svn: 309303
* Rename ObjectFile ObjFile for COFF as well.Rui Ueyama2017-07-261-3/+2
| | | | llvm-svn: 309228
* [COFF] Add initial support for some ARM64 relocations and import thunksMartin Storsjo2017-07-111-0/+2
| | | | | | | | | | This is enough to link a working hello world executable, with a call to an imported function, a string constant passed to the imported function, and loads from a global variable. Differential Revision: https://reviews.llvm.org/D34964 llvm-svn: 307629
* [COFF] Fix SECTION and SECREL relocation handling for absolute symbolsReid Kleckner2017-06-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: For SECTION relocations against absolute symbols, MSVC emits the largest output section index plus one. I've implemented that by threading a global variable through DefinedAbsolute that is filled in by the Writer. A more library-oriented approach would be to thread the Writer through Chunk::writeTo and SectionChunk::applyRel*, but Rui seems to prefer doing it this way. MSVC rejects SECREL relocations against absolute symbols, but only when the relocation is in a real output section. When the relocation is in a CodeView debug info section destined for the PDB, it seems that this relocation error is suppressed, and absolute symbols become zeros in the object file. This is easily implemented by checking the input section from which we're applying relocations. This should fix errors about __safe_se_handler_table and __guard_fids_table when linking the CRT and generating a PDB. Reviewers: ruiu Subscribers: aprantl, llvm-commits Differential Revision: https://reviews.llvm.org/D34541 llvm-svn: 306071
* Garbage collect dllimported symbols.Rui Ueyama2017-05-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is a different implementation than r303225 (which was reverted in r303270, re-submitted in r303304 and then re-reverted in r303527). In the previous patch, I tried to add Live bit to each dllimported symbol. It turned out that it didn't work with "oldnames.lib" which contains a lot of weak aliases to dllimported symbols. The way we handle weak aliases is to check if undefined symbols can be resolved using weak aliases, and if so, memcpy the Defined symbols to weak Undefined symbols, so that any references to weak aliases automatically see defined symbols instead of undefined ones. This memcpy happens before MarkLive kicks in. That means we may have multiple copies of dllimported symbols. So turning on one instance's Live bit is not enough. This patch moves the Live bit to dllimport file. Since multiple copies of dllsymbols still point to the same file, we can use it as the central repository to keep track of liveness. Differential Revision: https://reviews.llvm.org/D33520 llvm-svn: 303814
* Rewrite badly-formatted switch. NFC.Rui Ueyama2017-05-241-8/+11
| | | | llvm-svn: 303777
* Revert r303304: Re-submit r303225: Garbage collect dllimported symbols.Rui Ueyama2017-05-221-2/+1
| | | | | | | | This reverts commit r303304 because it looks like the change introduced a crash bug. At least after that change, LLD with thinlto crashes when linking Chromium. llvm-svn: 303527
* Re-submit r303225: Garbage collect dllimported symbols.Rui Ueyama2017-05-171-1/+2
| | | | | | | | | | This reverts re-submits r303225 which was reverted in r303270 because it broke the sanitizer-windows bot. The reason of the failure is that we were writing dead symbols to the symbol table. I fixed the issue. llvm-svn: 303304
* Revert r303225 "Garbage collect dllimported symbols."Hans Wennborg2017-05-171-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | and follow-up r303226 "Fix Windows buildbots." This broke the sanitizer-windows buildbot. > Previously, the garbage collector (enabled by default or by explicitly > passing /opt:ref) did not kill dllimported symbols. As a result, > dllimported symbols could be added to resulting executables' dllimport > list even if no one was actually using them. > > This patch implements dllexported symbol garbage collection. Just like > COMDAT sections, dllimported symbols now have Live bits to manage their > liveness, and MarkLive marks reachable dllimported symbols. > > Fixes https://bugs.llvm.org/show_bug.cgi?id=32950 > > Reviewers: pcc > > Subscribers: llvm-commits > > Differential Revision: https://reviews.llvm.org/D33264 llvm-svn: 303270
* Garbage collect dllimported symbols.Rui Ueyama2017-05-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | Summary: Previously, the garbage collector (enabled by default or by explicitly passing /opt:ref) did not kill dllimported symbols. As a result, dllimported symbols could be added to resulting executables' dllimport list even if no one was actually using them. This patch implements dllexported symbol garbage collection. Just like COMDAT sections, dllimported symbols now have Live bits to manage their liveness, and MarkLive marks reachable dllimported symbols. Fixes https://bugs.llvm.org/show_bug.cgi?id=32950 Reviewers: pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33264 llvm-svn: 303225
* refactor COFF linker to use new LTO APIBob Haarman2017-02-021-5/+4
| | | | | | | | | | | | | | Summary: The COFF linker previously implemented link-time optimization using an API which has now been marked as legacy. This change refactors the COFF linker to use the new LTO API, which is also used by the ELF linker. Reviewers: pcc, ruiu Reviewed By: pcc Subscribers: mgorny, mehdi_amini Differential Revision: https://reviews.llvm.org/D29059 llvm-svn: 293967
* Unbreak Darwin buildbots.Rui Ueyama2017-01-061-7/+7
| | | | llvm-svn: 291224
* Merge elf::toString and coff::toString.Rui Ueyama2017-01-061-4/+3
| | | | | | The two overloaded functions hid each other. This patch merges them. llvm-svn: 291222
* Remove lld/Support/Memory.h.Rui Ueyama2016-12-181-1/+1
| | | | | | | | | | | | I thought for a while about how to remove it, but it looks like we can just copy the file for now. Of course I'm not happy about that, but it's just less than 50 lines of code, and we already have duplicate code in Error.h and some other places. I want to solve them all at once later. Differential Revision: https://reviews.llvm.org/D27819 llvm-svn: 290062
* COFF: Fix memory leaks reported by lsan.Peter Collingbourne2016-12-121-3/+3
| | | | llvm-svn: 289451
* COFF: New symbol table design.Peter Collingbourne2016-12-091-141/+1
| | | | | | | | | This ports the ELF linker's symbol table design, introduced in r268178, to the COFF linker. Differential Revision: http://reviews.llvm.org/D21166 llvm-svn: 289280
* COFF: Use make() to create a new file object in createFile.Rui Ueyama2016-12-081-6/+7
| | | | llvm-svn: 289097
* Revert r289084: Start using make() in COFF.Rui Ueyama2016-12-081-7/+6
| | | | | | This reverts commit r289084 to appease buildbots. llvm-svn: 289086
* Start using make() in COFF.Rui Ueyama2016-12-081-6/+7
| | | | | | We don't want ELF and COFF to diverge too much. llvm-svn: 289085
* COFF: Define overloaded toString functions.Rui Ueyama2016-12-071-14/+21
| | | | | | | | | | | | | Previously, we had different way to stringize SymbolBody and InputFile to construct error messages. This patch defines overloaded function toString() so that we don't need to memorize all these different function names. With that change, it is now easy to include demangled names in error messages. Now, if there is a symbol name conflict, we'll print out both mangled and demangled names. llvm-svn: 288992
* COFF: Update error messages so that they start with lowercase letters.Rui Ueyama2016-07-151-1/+1
| | | | llvm-svn: 275513
* Remove unnecessary explicit call of Twine ctor.Rui Ueyama2016-07-151-1/+1
| | | | llvm-svn: 275512
* COFF: Rename noreturn error -> fatal.Rui Ueyama2016-07-141-1/+1
| | | | | | This new name is also consistent with ELF. llvm-svn: 275500
* [COFF] Remove an unused function, getFileOffDavid Majnemer2016-03-151-26/+0
| | | | | | | The function was not used and was not functional: all paths would lead to report_fatal_error or endless stack recursion. llvm-svn: 263542
* COFF: Allow forward reference for weak externalsRui Ueyama2015-08-171-1/+1
| | | | | | | | | | | Previously, weak external symbols could reference only symbols that appeared before them. Although that covers almost all use cases of weak externals, there are object files out there which contains weak externals that have forward references. This patch supports such weak externals. llvm-svn: 245258
* Port the error functions from ELF to COFF.Rafael Espindola2015-08-061-12/+7
| | | | | | | | | | | | | | | This has a few advantages * Less C++ code (about 300 lines less). * Less machine code (about 14 KB of text on a linux x86_64 build). * It is more debugger friendly. Just set a breakpoint on the exit function and you get the complete lld stack trace of when the error was found. * It is a more robust API. The errors are handled early and we don't get a std::error_code hot potato being passed around. * In most cases the error function in a better position to print diagnostics (it has more context). llvm-svn: 244215
* COFF: ARM: Fix DLL import table.Rui Ueyama2015-07-291-8/+4
| | | | | | | The previous test was testing -flavor link. This patch correctly tests link2 and fixes a bug that we didn't emit import thunks. llvm-svn: 243559
* COFF: Use short identifiers. NFC.Rui Ueyama2015-07-251-2/+2
| | | | llvm-svn: 243229
OpenPOWER on IntegriCloud