summaryrefslogtreecommitdiff
path: root/lld/COFF/Driver.cpp
AgeCommit message (Collapse)Author
2025-10-23[DTLTO][Clang][LLD] Fix DTLTO for multi-call LLVM driver toolchain (#162456)Andrew Ng
Add DTLTO linker option `--thinlto-remote-compiler-prepend-arg` to enable support for the multi-call LLVM driver that requires an additional option to specify the subcommand, e.g. "llvm clang ...". Fixes https://github.com/llvm/llvm-project/issues/159125.
2025-10-02[DTLTO][LLD] Tidy up DTLTO related options (NFC) (#161675)Andrew Ng
Change LLD DTLTO option definitions to match actual option name.
2025-09-20[lld-link] Do not assert when reporting error about non-thin archive (#159828)Nico Weber
Follow-up to https://reviews.llvm.org/D57974, which added calls to Archive::Child::getFullName() to produce strings in errors. But getFullName() is only valid on thin archives, and should only be used to open the file the archive points to. For diagnostics, getName() is better: It works for both thin and non-thin files, and it doesn't make a very long string for thin files. And we already prepend the name of the parent archive file anyways.
2025-09-20[LLD][COFF] Add /nodbgdirmerge to control debug directory section (#159235)kkent030315
Resolves #141712. As described in the issue, this PR adds support for `/nodbgdirmerge` flag in LLD to align with MS link. When the flag is specified, the linker will emit the debug directory section in `.cvinfo` section, instead of merging it to the `.rdata`. The flag will be ignored on MinGW. --------- Co-authored-by: namazso <admin@namazso.eu>
2025-09-08[LLD][COFF] Display the size of all consumed inputs with /summary (take 2) ↵Alexandre Ganea
(#157284) When `/summary` is used, we now also display the cumulative size of all input OBJ files, including those pulled from archives. Lazy OBJ files that were not pulled in are not accounted for. Also added separators between digit groups, to make the output more bearable. Example output: ``` > lld-link ... /summary Summary -------------------------------------------------------------------------------- 4,958 Input OBJ files (expanded from all cmd-line inputs) 46,715,790,512 Size of all consumed OBJ files (non-lazy), in bytes 42 PDB type server dependencies 0 Precomp OBJ dependencies 293,910,064 Input type records 16,931,361,928 Size of all input type records, in bytes 11,201,549 Merged TPI records 2,765,494 Merged IPI records 38,649 Output PDB strings 21,512,230 Global symbol records 82,380,837 Module symbol records 715,313 Public symbol records ``` I've skipped over the exact amounts for "Size of all consumed inputs (non-lazy)" in the unit tests, since the sizes of OBJ files can fluctuate between compilers. _(this is a reopening of https://github.com/llvm/llvm-project/pull/157279 which wasa committed by mistake)_
2025-09-06Revert "[LLD][COFF] Display the size of all consumed inputs with `/summary`" ↵Alexandre Ganea
(#157282) Reverts llvm/llvm-project#157279
2025-09-06[LLD][COFF] Add more variety of CET and hotpatch flags (#150761)kkent030315
Those are all MS link.exe compatible flags. ### CET (Control-flow Enforcement Technology) family - Added LLD test that covers `/cetcompat[:no]` - Added `/cetcompatstrict[:no]` flag in LLD/COFF - Added `/cetipvalidationrelaxed[:no]` flag in LLD/COFF - Added `/cetdynamicapisinproc[:no]` flag in LLD/COFF ### Misc - Added `/hotpatchcompatible[:no]` flag in LLD/COFF - This flag requires at least 6 bytes of function padding (`/functionpadmin:#`) as per link.exe
2025-09-06[LLD][COFF] Display the size of all consumed inputs with `/summary` (#157279)Alexandre Ganea
When `/summary` is used, we now also display the cumulative size of all input OBJ files, including those pulled from archives. Lazy OBJ files that were not pulled in are not accounted for. Also added separators between digit groups, to make the output more bearable. Example output: ``` > lld-link ... /summary Summary -------------------------------------------------------------------------------- 4,958 Input OBJ files (expanded from all cmd-line inputs) 46,715,790,512 Size of all consumed OBJ files (non-lazy), in bytes 42 PDB type server dependencies 0 Precomp OBJ dependencies 293,910,064 Input type records 16,931,361,928 Size of all input type records, in bytes 11,201,549 Merged TPI records 2,765,494 Merged IPI records 38,649 Output PDB strings 21,512,230 Global symbol records 82,380,837 Module symbol records 715,313 Public symbol records ``` We skip over the exact amounts for "Size of all consumed inputs (non-lazy)" in the unit tests, since the sizes of OBJ files can fluctuate between compilers.
2025-09-04[LLD][COFF] Add support for custom section layout (#152779)kkent030315
MS link.exe provides the `/sectionlayout:@` option to specify the order of output sections at the granularity of individual sections. LLD/COFF currently does not have capability for user-controlled ordering of one or more output sections (as LLD/COFF does not support linker scripts), and this PR adds the option to align with MS link.exe. The option accepts only a file that specifies the order of sections, one per line. For example, `mylayout.txt` could emit the `.text` section after all other sections while preserving the original relative order of the remaining sections. ``` .data .rdata .pdata .rsrc .reloc .text ``` ```bash echo 'int main() { return 0; }' > main.c cl main.c /link /entry:main /sectionlayout:@mylayout.txt llvm-readobj --sections main.exe ```
2025-08-05[LLD][COFF] Don't resolve weak aliases when performing local import (#152000)Jacek Caban
Fixes crashes reported in #151255. The alias may have already been stored for later resolution, which can lead to treating a resolved alias as if it were still undefined. Instead, use the alias target directly for the import. Also extended the test to make reproducing the problem more likely, and added an assert that catches the issue.
2025-07-31[LLD][COFF] Add support for ARM64X same-address thunks (#151255)Jacek Caban
Fixes MSVC CRT thread-local constructors support on hybrid ARM64X targets. `-arm64xsameaddress` is an undocumented option that ensures the specified function has the same address in both native and EC views of hybrid images. To achieve this, the linker emits additional thunks and replaces the symbols of those functions with the thunk symbol (the same thunk is used in both views). The thunk code jumps to the native function (similar to range extension thunks), but additional ARM64X relocations are emitted to replace the target with the EC function in the EC view. MSVC appears to generate thunks even for non-hybrid ARM64EC images. As a side effect, the native symbol is pulled in. Since this is used in the CRT for thread-local constructors, it results in the image containing unnecessary native code. Because these thunks do not appear to be useful in that context, we limit this behavior to actual hybrid targets. This may change if compatibility requires it. The tricky part is that thunks should be skipped if the symbol is not live in either view, and symbol replacement must be reflected in weak aliases. This requires thunk generation to happen before resolving weak aliases but after the GC pass. To enable this, the `markLive` call was moved earlier, and the final weak alias resolution was postponed until afterward. This requires more code to be aware of weak aliases, which previously could assume they were already resolved.
2025-07-31[LLD][COFF] Introduce Symbol::getDefined helper. (NFC) (#151253)Jacek Caban
2025-07-28[LLD][COFF] Move resolving alternate names to SymbolTable (NFC) (#149495)Jacek Caban
2025-07-22[LLD][COFF] Make /wholearchive thin-archive member identifiers consistent ↵bd1976bris
(#145487) A thin archive is an archive/library format where the archive itself contains only references to member object files on disk, rather than embedding the file contents. For the non-/wholearchive case, we use the path to the archive member as the identifier for thin-archive members (see comments in `enqueueArchiveMember`). This patch modifies the /wholearchive path to behave the same way. Apart from consistency, my motivation for fixing this is DTLTO (#126654), where having the member identifier be the path on disk allows distribution of bitcode members during ThinLTO.
2025-07-21[LLD][COFF] Follow up comments on pr146610 (#147152)Alexandre Ganea
This is a follow-up PR for post-commit comments in https://github.com/llvm/llvm-project/pull/146610 - Changed "exporteddllmain" references to "importeddllmain". - Add support for x86 target and test coverage. - Changed a comment to better express why we're skipping importing `DllMain`.
2025-07-20[DTLTO][LLD][COFF] Add support for Integrated Distributed ThinLTO (#148594)bd1976bris
This patch introduces support for Integrated Distributed ThinLTO (DTLTO) in COFF LLD. DTLTO enables the distribution of ThinLTO backend compilations via external distribution systems, such as Incredibuild, during the traditional link step: https://llvm.org/docs/DTLTO.html. Note: Bitcode members of non-thin archives are not currently supported. This will be addressed in a future change. This patch is sufficient to allow for self-hosting an LLVM build with DTLTO if thin archives are used. Testing: - LLD `lit` test coverage has been added, using a mock distributor to avoid requiring Clang. - Cross-project `lit` tests cover integration with Clang. For the design discussion of the DTLTO feature, see: https://github.com/llvm/llvm-project/pull/126654
2025-07-02[LLD][COFF] Disallow importing DllMain from import libraries (#146610)Alexandre Ganea
This is a workaround for https://github.com/llvm/llvm-project/issues/82050 by skipping the `DllMain` symbol if seen in aimport library. If this situation occurs, after this commit a warning will also be displayed. The warning can be silenced with `/ignore:exporteddllmain`
2025-06-24Use the Windows SDK arguments over the environment (#144805)Fabrice de Gans
If any of the Windows SDK (and MSVC)-related argument is passed in the command line, they should take priority over the environment variables like `INCLUDE` or `LIB` set by vcvarsall from the Visual Studio Developer Environment on Windows. These changes ensure that all of the arguments related to VC Tools and the Windows SDK cause the driver to ignore the environment.
2025-05-25[lld] Remove unused includes (NFC) (#141421)Kazu Hirata
2025-05-15[LLD][COFF] Allow -arm64xsameaddress in ARM64EC directives (#139631)Jacek Caban
Make it a no-op for now, which is sufficient for non-hybrid images. Fixes #131712.
2025-05-15[LLD][COFF] Add support for including native ARM64 objects in ARM64EC images ↵Jacek Caban
(#137653) MSVC linker accepts native ARM64 object files as input with `-machine:arm64ec`, similar to `-machine:arm64x`. Its usefulness is very limited; for example, both exports and imports are not reflected in the PE structures and can't work. However, their symbol tables are otherwise functional. Since we already have handling of multiple symbol tables implemented for ARM64X, the required changes are mostly about adjusting relevant checks to account for them on the ARM64EC target. Delay-load helper handling is a bit of a shortcut. The patch never pulls it for native object files and just ensures that the code is fine with that. In general, I think it would be nice to adjust the driver to pull it only when it's actually referenced, which would allow applying the same logic to the native symbol table on ARM64EC without worrying about pulling too much.
2025-05-02[LLD][COFF] add __{data,bss}_{start,end}__ symbols for Cygwin support (#136180)jeremyd2019
Cygwin requires these symbols for its fork emulation to know what data to copy into the child. GNU ld defines these symbols for MinGW targets also, so do the same here. Cygwin also has the `.data_cygwin_nocopy` section, which is merged into `.data` outside the `__data_start__` to `__data_end__` range. This excludes it from fork's copying. AFAIK it's only used by the Cygwin DLL itself (which requires a custom linker script to link, that's not supported by LLD), but the section is included in GNU ld's default linker script so handle it here too. Signed-off-by: Jeremy Drake <github@jdrake.com>
2025-04-11[LLD][COFF] Remove no longer needed symtabEC from COFFLinkerContext (NFC) ↵Jacek Caban
(#135094) With #135093, we may just use `symtab` instead.
2025-04-11[LLD][COFF] Swap the meaning of symtab and hybridSymtab in hybrid images ↵Jacek Caban
(#135093) Originally, the intent behind symtab was to represent the symbol table seen in the PE header (without applying ARM64X relocations). However, in most cases outside of `writeHeader()`, the code references either both symbol tables or only the EC one, for example, `mainSymtab` in `linkerMain()` maps to `hybridSymtab` on ARM64X. MSVC's link.exe allows pure ARM64EC images to include native ARM64 files. This patch prepares LLD to support the same, which will require `hybridSymtab` to be available even for ARM64EC. At that point, `writeHeader()` will need to use the EC symbol table, and the original reasoning for keeping it in `hybridSymtab` no longer applies. Given this, it seems cleaner to treat the EC symbol table as the “main” one, assigning it to `symtab`, and use `hybridSymtab` for the native symbol table instead. Since `writeHeader()` will need to be conditional anyway, this change simplifies the rest of the code by allowing other parts to consistently treat `ctx.symtab` as the main symbol table. As a further simplification, this also allows us to eliminate `symtabEC` and use `symtab` directly; I’ll submit that as a separate PR. The map file now uses the EC symbol table for printed entry points and exports, matching MSVC behavior.
2025-04-07[LLD][COFF] Don't dllimport from static libraries (#134443)Alexandre Ganea
This reverts commit 6a1bdd9 and re-instate behavior that matches what MSVC link.exe does, that is, error out when trying to dllimport a symbol from a static library. A hint is now displayed in stdout, mentioning that we should rather dllimport the symbol from a import library. Fixes https://github.com/llvm/llvm-project/issues/131807
2025-03-29[lld] Use *Set::insert_range (NFC) (#133565)Kazu Hirata
2025-03-12[LLD][COFF] Update nodefaultlibs after updating search paths (#128813)A2uria
Fix #107346
2025-03-03[LLD][COFF] Support -aligncomm directives on ARM64X (#129513)Jacek Caban
2025-03-03[LLD][COFF] Add support for -includeglob on ARM64X (#129515)Jacek Caban
Include symbols from both symbol tables.
2025-03-02[LLD][COFF] Mark personality functions as live in both symbol tables on ↵Jacek Caban
ARM64X (#129295)
2025-03-02[LLD][COFF] Add support for autoimports on ARM64X (#129282)Jacek Caban
2025-02-21[LLD][COFF] Support alternate names in both symbol tables on ARM64X (#127619)Jacek Caban
The `.drectve` directive applies only to the namespace in which it is defined, while the command-line argument applies only to the EC namespace.
2025-02-10[LLD][MinGW] Add support for wrapped symbols on ARM64X (#126296)Jacek Caban
Apply `-wrap` arguments to both symbol tables.
2025-02-10[LLD][COFF] Add support for -includeoptional on ARM64X (#126300)Jacek Caban
Include symbols from both symbol tables.
2025-02-06[LLD][COFF] Add support for MinGW auto-export on ARM64X (#125862)Jacek Caban
Export all symbols from both EC and native symbol tables. If an explicit export is present in either symbol table, auto-export is disabled for both.
2025-02-05[LLD][COFF] Use EC symbol table for output DEF file on ARM64X (#125531)Jacek Caban
For consistency with input def handling.
2025-01-29[LLD][COFF] Write both native and EC export symbols to the import library on ↵Jacek Caban
ARM64X (#124833)
2025-01-28[LLD][COFF] Move delayLoadHelper and tailMergeUnwindInfoChunk to SymbolTable ↵Jacek Caban
(NFC) (#124729) In preparation for ARM64X delay-load import support (#124600).
2025-01-22[LLD][COFF] Add support for the -defArm64Native argument (#123850)Jacek Caban
MSVC ignores the `/defArm64Native` argument on non-ARM64X targets. It is also ignored if the `/def` option is not specified.
2025-01-22[LLD][COFF] Use EC symbol table for exports defined in module definition ↵Jacek Caban
files (#123849)
2025-01-21[LLD][COFF] Separate EC and native exports for ARM64X (#123652)Jacek Caban
Store exports in SymbolTable instead of Configuration.
2025-01-20[LLD][COFF] Add support for custom DOS stub (#122561)kkent030315
This change implements support for the /stub flag to align with MS link.exe. This option is useful when a program needs to optimize the DOS program that executes when the PE runs on DOS, avoiding the traditional hardcoded DOS program in LLD.
2025-01-17[LLD][COFF] Process bitcode files separately for each symbol table on ARM64X ↵Jacek Caban
(#123194)
2025-01-16[LLD][COFF] Move getChunk to LinkerDriver (NFC) (#123103)Jacek Caban
The `getChunk` function returns all chunks, not just those specific to a symbol table. Move it out of the `SymbolTable` class to clarify its scope.
2025-01-16[LLD][COFF] Add support for hybrid ARM64X entry points (#123096)Jacek Caban
Store the entry symbol in SymbolTable instead of Configuration, as it differs between symbol tables.
2025-01-15[LLD][COFF] Infer subsystem from EC symbol table for ARM64X (#122838)Jacek Caban
2025-01-15[LLD][COFF] Pull _load_config_used symbol from both symbol tables on ARM64X ↵Jacek Caban
(#122837)
2025-01-15[LLD][COFF] Move symbol mangling and lookup helpers to SymbolTable class ↵Jacek Caban
(NFC) (#122836) This refactor prepares for further ARM64X hybrid support, where these helpers will need to work with either the native or EC symbol table based on context.
2025-01-13[LLD][COFF] Use appropriate symbol table for -include argument on ARM64X ↵Jacek Caban
(#122554) Move `LinkerDriver::addUndefined` to` SymbolTable` to allow its use with both symbol tables on ARM64X and rename it to `addGCRoot` to clarify its distinct role compared to the existing `SymbolTable::addUndefined`. Command-line `-include` arguments now apply to the EC symbol table, with `mainSymtab` introduced in `linkerMain`. There will be more similar cases. For `.drectve` sections, the corresponding symbol table is used based on the context.
2025-01-05[LLD] Do not combine cg_profile from obj and ordering file (#121325)Haohai Wen
cg_profile in object is from CGProfilePass and it is often inaccurate. While call-graph-ordering-file is provided by user. It is weird to aggregate them together especially when call-graph-ordering-file is accurate enough.