433 Commits

Author SHA1 Message Date
Jacek Caban
61f80db9a4
[LLD][COFF] Remove no longer needed symtabEC from COFFLinkerContext (NFC) (#135094)
With #135093, we may just use `symtab` instead.
2025-04-11 18:50:16 +02:00
Jacek Caban
1c05c6183d
[LLD][COFF] Swap the meaning of symtab and hybridSymtab in hybrid images (#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-11 15:53:25 +02:00
Kazu Hirata
690b8b4e94
[lld] Avoid repeated map lookups (NFC) (#132327) 2025-03-21 17:24:43 +08:00
Jacek Caban
7c26407a20
[LLD][COFF] Clarify EC vs. native symbols in diagnostics on ARM64X (#130857)
On ARM64X, symbol names alone are ambiguous as they may refer to either
a native or an EC symbol. Append '(EC symbol)' or '(native symbol)' in
diagnostic messages to distinguish them.
2025-03-15 21:15:08 +01:00
Jacek Caban
868c409d38 Reapply "[LLD][COFF] Support CF guards on ARM64X (#128440)"
Both native and EC views share table chunks. Ensure relevant symbols are
set in both symbol tables.
2025-03-07 21:04:30 +01:00
Zequan Wu
0efaad00a9 Revert "[LLD][COFF] Support CF guards on ARM64X (#128440)"
This reverts commit 14bab65cbfb2bf9a410c3ce206a6b7a273441f26.
It causes lld-link to crash, posted repro at https://github.com/llvm/llvm-project/pull/128440#issuecomment-2702493683.
2025-03-06 10:13:30 -08:00
Jacek Caban
c6598f6ddf
[LLD][COFF] Add support for autoimports on ARM64X (#129282) 2025-03-02 13:10:50 +01:00
Jacek Caban
14bab65cbf
[LLD][COFF] Support CF guards on ARM64X (#128440)
Both native and EC views share table chunks. Ensure relevant symbols are
set in both symbol tables.
2025-02-27 21:55:16 +01:00
Jacek Caban
94f34c00f2
[LLD][COFF] Use primary symbol table machine in Writer::writeHeader (NFC) (#128442)
Instead of duplicating the logic from `LinkerDriver::setMachine`.
2025-02-27 21:53:10 +01:00
Jacek Caban
a92bfaa7d9
[LLD][COFF] Support MinGW constructor and destructor lists on ARM64X (#127205)
Split the chunks for EC and native views, inserting headers and tails for both.
2025-02-17 21:34:12 +01:00
Jacek Caban
15944056aa
[LLD][COFF] Split native and EC .CRT chunks on ARM64X (#127203) 2025-02-17 20:03:32 +01:00
Jacek Caban
8252e0ef82
[LLD][COFF] Emit ARM64X relocations for CHPE ExtraRFETable entries (#126713)
In the native view, ExtraEFRTable references the x86 exception table.
The EC view references the ARM exception table, as it did before this
change.
2025-02-13 19:22:57 +01:00
Jacek Caban
c52fbabc93
[LLD][COFF] Set __buildid symbol in both symbol tables on ARM64X (#126777) 2025-02-13 19:10:46 +01:00
Jacek Caban
8cb3d7b418
[LLD][COFF] Emit locally imported EC symbols for ARM64X (#125527) 2025-02-05 10:30:13 +01:00
Jacek Caban
97aa56ada5
[LLD][COFF] Move delayLoadHelper and tailMergeUnwindInfoChunk to SymbolTable (NFC) (#124729)
In preparation for ARM64X delay-load import support (#124600).
2025-01-28 12:07:35 +01:00
Jacek Caban
671ec34fb2
[LLD][COFF] Add support for hybrid exports on ARM64X (#123724) 2025-01-21 22:55:58 +01:00
Jacek Caban
659e66e2b3
[LLD][COFF] Implement ARM64X relocations for the exception table (#123723) 2025-01-21 22:24:00 +01:00
Jacek Caban
455b3d6df2
[LLD][COFF] Separate EC and native exports for ARM64X (#123652)
Store exports in SymbolTable instead of Configuration.
2025-01-21 10:41:15 +01:00
Jacek Caban
2cfddda1f5
[LLD][COFF] Simplify creation of .edata chunks (NFC) (#123651)
Since commit dadc6f2488684, only the constructor of the `EdataContents`
class is used. Replace it with a function and skip the call when using a
custom `.edata` section.
2025-01-20 23:02:26 +01:00
kkent030315
fb974e8909
[LLD][COFF] Add support for custom DOS stub (#122561)
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-20 23:38:59 +02:00
Jacek Caban
a16adafd47
[LLD][COFF] Add support for alternate entry point in CHPE metadata on ARM64X (#123346)
Includes handling for ARM64X relocations relative to a symbol.
2025-01-20 11:38:54 +01:00
Jacek Caban
1bd5f34d76
[LLD][COFF] Move getChunk to LinkerDriver (NFC) (#123103)
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 12:55:12 +01:00
Jacek Caban
d004947ac5
[LLD][COFF] Add support for hybrid ARM64X entry points (#123096)
Store the entry symbol in SymbolTable instead of Configuration, as it
differs between symbol tables.
2025-01-16 12:53:48 +01:00
Jacek Caban
3b0dafff87
[LLD][COFF] Use EC load config for ARM64X relocations of load config directory (#121337)
This change ensures the load config in the hybrid image view is handled
correctly. It introduces a new Arm64XRelocVal class to abstract
relocation values, allowing them to be relative to a symbol. This class
will also be useful for managing ARM64X relocation offsets in the
future.
2025-01-10 21:50:07 +01:00
Jacek Caban
c57810a00a
[LLD][COFF] Sort base relocations (#121699)
This change ensures that base relocations are sorted in the output,
aligning with MSVC linker behavior. While input files typically provide
sorted relocations, this update guarantees correct sorting even if the
input relocations are unordered.
2025-01-09 15:40:49 +01:00
Nico Weber
4b22ef7d6b [lld/COFF] Fix comment typo to cycle bots 2025-01-02 08:24:50 -05:00
Jacek Caban
db7123fbbc
[LLD][COFF] Use EC symbol table for CHPE metadata (#120328)
Copy CHPE metadata pointer from EC load config to native configuration.
2024-12-29 14:04:00 +01:00
Jacek Caban
7144325109
[LLD][COFF] Prepare both load configs on ARM64X (#120326) 2024-12-29 12:55:10 +01:00
Jacek Caban
ff29f38c02
[LLD][COFF] Store and validate load config in SymbolTable (#120324)
Improve diagnostics for invalid load configurations.
2024-12-29 11:43:45 +01:00
Fangrui Song
1865f0e203 [lld-link] Replace warn(...) with Warn(ctx) 2024-12-12 22:27:45 -08:00
Fangrui Song
c7caab2238 [lld-link] Simplify some << toString 2024-12-05 20:56:19 -08:00
Fangrui Song
8b844de3c9 [lld-link] Replace fatal(...) with Fatal 2024-12-05 20:18:01 -08:00
Fangrui Song
36c294013c [lld-link] Remove unneeded Twine when using COFFSyncStream 2024-12-05 19:49:53 -08:00
Fangrui Song
8d225f10ef [lld-link] Replace error(...) with Err 2024-12-05 19:44:26 -08:00
Mateusz Mikuła
8a6f1abe16
[LLD] [COFF] Print a warning when using /dependentloadflag without load config (#117400)
As per request in https://github.com/llvm/llvm-project/pull/113814.
2024-12-05 22:28:38 +02:00
Jacek Caban
71bbafba31
[LLD][COFF] Add basic ARM64X dynamic relocations support (#118035)
This modifies the machine field in the hybrid view to be AMD64, aligning
it with expectations from ARM64EC modules. While this provides initial
support, additional relocations will be necessary for full
functionality. Many of these cases depend on implementing separate
namespace support first.

Move clearing of the .reloc section from addBaserels to assignAddresses
to ensure it is always cleared, regardless of the relocatable
configuration. This change also clarifies the reasoning for adding the
dynamic relocations chunk in that location.
2024-12-05 13:07:41 +01:00
Fangrui Song
4639a9a063 [lld-link] Replace log(...) with Log 2024-12-04 09:04:40 -08:00
Jacek Caban
7235ac9051
[LLD][COFF] Check load config size before setting its DependentLoadFlags (#118535)
Merge prepareLoadConfig and checkLoadConfigGuardData to share helper
macros.
2024-12-04 15:36:41 +01:00
Fangrui Song
1534f45694 [lld-link] Replace warn(...) with Warn(ctx) 2024-12-03 22:19:30 -08:00
Fangrui Song
8c7c8eaa19 [lld-link] Replace global lld::errs() with ctx.e.errs() 2024-11-16 18:45:47 -08:00
Fangrui Song
1bfe55aff5 [lld-link] Replace errorHandler() with ctx.e
errorHandler() uses the global state, which should be avoided in
lld/COFF code.
2024-11-16 18:31:58 -08:00
Jacek Caban
5fbe9b958d
[LLD][COFF] Set __guard_flags to CF_INSTRUMENTED if any object is instrumented (#115374) 2024-11-08 14:01:25 +01:00
Jacek Caban
18fa9fa043
[LLD][COFF] Add support for ARM64EC delay-load imports (#110042)
Fill the regular delay-load IAT with x86_64 delay-load thunks. Similarly
to regular imports, create an auxiliary IAT and its copy for ARM64EC
calls. These are filled with the same `__impchk_` thunks used for
regular imports, which perform an indirect call with
`__icall_helper_arm64ec` on the regular delay-load IAT. These auxiliary
IATs are exposed via CHPE metadata starting from version 2.

The MSVC linker creates one more copy of the auxiliary IAT. `__imp_func`
symbols refer to that hidden IAT, while the `#func` thunk performs a
call with the public auxiliary IAT. If the public auxiliary IAT is fine
for `#func`, it should be fine for calls using the `__imp_func` symbol
as well. Therefore, I made `__imp_func` refer to that IAT too.
2024-09-30 20:26:55 +02:00
Jacek Caban
f661e695a6
[LLD][COFF] Add support for ARM64EC import call thunks with extended range (#109703)
The MSVC linker generates range extensions for these thunks when needed.
This commit inlines the range extension into the thunk, making it both
slightly more optimal and easier to implement in LLD.
2024-09-26 10:44:40 +02:00
Jacek Caban
fc661df41a
[LLD][COFF][NFC] Use dyn_cast on section chunks (#109701)
Instead of dyn_cast_or_null, chunk pointers are never null.
2024-09-24 12:04:04 +02:00
Jacek Caban
a17a2451db
[LLD][COFF] Add Support for auxiliary IAT copy (#108610)
In addition to the auxiliary IAT, ARM64EC modules also contain a copy of
it. At runtime, the auxiliary IAT is filled with the addresses of actual
ARM64EC functions when possible. If patching is detected, the OS may use
the IAT copy to revert the auxiliary IAT, ensuring that the call checker
is used for calls to imported functions.
2024-09-17 14:40:24 +02:00
Jacek Caban
ea5d37f4c1
[LLD][COFF] Add Support for ARM64EC Import Thunks (#108460)
ARM64EC import thunks function similarly to regular ARM64 thunks but use
a mangled name and perform the call through the auxiliary IAT.
2024-09-13 17:05:02 +02:00
Jacek Caban
6be9be5e0b
[LLD][COFF][NFC] Store live flag in ImportThunkChunk. (#108459)
Instead of ImportFile. This is a preparation for ARM64EC support, which
has both x86 and ARM64EC thunks and each of them needs a separate flag.
2024-09-13 15:42:05 +02:00
Jacek Caban
82a36468c7
[LLD][COFF] Add support for ARM64EC auxiliary IAT (#108304)
In addition to the regular IAT, ARM64EC also includes an auxiliary IAT.
At runtime, the regular IAT is populated with the addresses of imported
functions, which may be x86_64 functions or the export thunks of ARM64EC
functions. The auxiliary IAT contains versions of functions that are
guaranteed to be directly callable by ARM64 code.

The linker fills the auxiliary IAT with the addresses of `__impchk_`
thunks. These thunks perform a call on the IAT address using
`__icall_helper_arm64ec` with the target address from the IAT. If the
imported function is an ARM64EC function, the OS may replace the address
in the auxiliary IAT with the address of the ARM64EC version of the
function (not its export thunk), avoiding the runtime call checker for
better performance.
2024-09-12 22:20:50 +02:00
Jacek Caban
99a2354993
[LLD][COFF] Add support for ARM64EC import call thunks. (#107931)
These thunks can be accessed using `__impchk_*` symbols, though they
are typically not called directly. Instead, they are used to populate the
auxiliary IAT. When the imported function is x86_64 (or an ARM64EC
function with a patched export thunk), the thunk is used to call it.
Otherwise, the OS may replace the thunk at runtime with a direct
pointer to the ARM64EC function to avoid the overhead.
2024-09-11 14:46:40 +02:00