1244 Commits

Author SHA1 Message Date
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
A2uria
90a08fb4b7
[LLD][COFF] Update nodefaultlibs after updating search paths (#128813)
Fix #107346
2025-03-12 08:47:01 +02: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
Jacek Caban
c53e527bf8
[LLD][COFF] Implement ECExportThunkChunk::classof (NFC) (#130106)
Allows using `dyn_cast_or_null` in `maybeAddAddressTakenFunction` in #128440.
2025-03-07 18:34:56 +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
f2473bc31e
[LLD][COFF] Support -aligncomm directives on ARM64X (#129513) 2025-03-03 22:48:20 +01:00
Jacek Caban
2d0eb5df4f
[LLD][COFF] Add support for -includeglob on ARM64X (#129515)
Include symbols from both symbol tables.
2025-03-03 22:39:42 +01:00
Jacek Caban
d403f33886
[LLD][COFF] Mark personality functions as live in both symbol tables on ARM64X (#129295) 2025-03-02 13:37:51 +01:00
Jacek Caban
c6598f6ddf
[LLD][COFF] Add support for autoimports on ARM64X (#129282) 2025-03-02 13:10:50 +01:00
Jacek Caban
f858ac7acc
[LLD][COFF] Correct relocation size comments in autoimport tests (NFC) (#129403) 2025-03-02 13:10:01 +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
b09dfbd699
[LLD][COFF] Add support for x86_64 archives on ARM64X (#128241)
If the ECSYMBOLS section is missing in the archive, the archive could be
either a native-only ARM64 or x86_64 archive. Check the machine type of
the object containing a symbol to determine which symbol table to use.
2025-02-22 11:20:58 +01:00
Jacek Caban
8616c87335
[LLD][COFF] Support alternate names in both symbol tables on ARM64X (#127619)
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-21 12:52:28 +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
94d956367e
[LLD][MinGW] Add support for wrapped symbols on ARM64X (#126296)
Apply `-wrap` arguments to both symbol tables.
2025-02-10 22:52:11 +01:00
Jacek Caban
fdded8537d [LLD][COFF] Fix a typo in REQUIRES directive (NFC)
Fixes #126300.
2025-02-10 22:09:33 +01:00
Jacek Caban
6536579d80
[LLD][COFF] Add support for -includeoptional on ARM64X (#126300)
Include symbols from both symbol tables.
2025-02-10 22:01:53 +01:00
Peter Rong
839002dd2d
[lld] Remove usage of %T in lld/test (#126133)
`%T` is not unique and deprecated
[[1](https://llvm.org/docs/CommandGuide/lit.html#substitutions)].

This patch replaces all `%T` in `lld/test` with `%t.dir` (`mkdir` if
necessary)

---------

Signed-off-by: Peter Rong <PeterRong@meta.com>
2025-02-10 10:35:44 -08:00
Jacek Caban
abd31b48e3
[LLD][MinGW] Exclude load config symbols from auto-export (#126134) 2025-02-07 15:52:39 +01:00
Jacek Caban
c8b2ba722f
[LLD][COFF] Add test for hybrid patchable thunks on ARM64X (NFC) (#126135) 2025-02-07 15:51:38 +01:00
Jacek Caban
f729477657
[LLD][COFF] Add support for MinGW auto-export on ARM64X (#125862)
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-06 22:25:53 +01:00
Jacek Caban
e596387ebe
[LLD][COFF] Use EC symbol table for output DEF file on ARM64X (#125531)
For consistency with input def handling.
2025-02-05 12:16:02 +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
e902cf2df1
[LLD][COFF] Write both native and EC export symbols to the import library on ARM64X (#124833) 2025-01-29 09:57:11 +01:00
Jacek Caban
3a51466caf
[LLD][COFF] Add support for delay-load imports on ARM64X (#124600)
For each imported module, emit null-terminated native import entries,
followed by null-terminated EC entries. If a view lacks imports for a
given module, only terminators are emitted. Use ARM64X relocations to
skip native entries in the EC view.

Move `delayLoadHelper` and `tailMergeUnwindInfoChunk` to `SymbolTable`
since they are different for each symbol table.
2025-01-28 13:06:01 +01:00
Jacek Caban
80ab237c11 [LLD][COFF] Add REQUIRE x86 to arm64x-import.test (NFC)
This ensures the disassembler can handle ARM64X binaries correctly. Fixes #124189.
2025-01-26 22:36:01 +01:00
Jacek Caban
fb01a28903
[LLD][COFF] Implement support for hybrid IAT on ARM64X (#124189)
In hybrid images, the PE header references a single IAT for both native
and EC views, merging entries where possible. When merging isn't
feasible, different imports are grouped together, and ARM64X relocations
are emitted as needed.
2025-01-26 22:11:40 +01:00
Jacek Caban
77c325b646
[LLD][COFF] Keep hasData true in NullChunk constructor (#124368)
`NullChunk` instances do write data, even if it's always zero. Setting
`hasData` to false causes `Writer::assignAddresses` to ignore them
when calculating `rawSize`. This typically isn't an issue, as null chunks
are usually positioned within a section, and later chunks adjust the
size accordingly.

However, on ARM64EC, the auxiliary IAT is placed at the end of the
`.rdata` section and terminates with a null chunk. As a result, `rawSize`
is never updated to account for it, and space for the null chunk is not
allocated. Consequently, when `NullChunk::writeTo` is called, it receives
an invalid pointer - either pointing to the next section or beyond the
allocated buffer.
2025-01-25 22:20:34 +01:00
Nico Weber
d9b8120259
[lld/COFF] Fix -start-lib / -end-lib more after reviews.llvm.org/D116434 (#124294)
This is a follow-up to #120452 in a way.

Since lld/COFF does not yet insert all defined in an obj file before all
undefineds (ELF and MachO do this, see #67445 and things linked from
there), it's possible that:

1. We add an obj file a.obj
2. a.obj contains an undefined that's in b.obj, causing b.obj to be
added
3. b.obj contains an undefined that's in a part of a.obj that's not yet
in the symbol table, causing a recursive load of a.obj, which adds the
symbols in there twice, leading to duplicate symbol errors.

For normal archives, `ArchiveFile::addMember()` has a `seen` check to
prevent this. For start-lib lazy objects, we can just check if the
archive is still lazy at the recursive call.

This bug is similar to issue #59162.

(Eventually, we'll probably want to do what the MachO and ELF ports do.)

Includes a test that caused duplicate symbol diagnostics before this
code change.
2025-01-24 13:14:21 -05:00
Martin Storsjö
8eb99bbe6e
Reland [LLD] [COFF] Fix linking MSVC generated implib header objects (#123916)
ecb5ea6a266d5cc4e05252f6db4c73613b73cc3b tried to fix cases when LLD
links what seems to be import library header objects from MSVC. However,
the fix seems incorrect; the review at https://reviews.llvm.org/D133627
concluded that if this (treating this kind of symbol as a common symbol)
is what link.exe does, it's fine.

However, this is most probably not what link.exe does. The symbol
mentioned in the commit message of
ecb5ea6a266d5cc4e05252f6db4c73613b73cc3b would be a common symbol with a
size of around 3 GB; this is not what might have been intended.

That commit tried to avoid running into the error ".idata$4 should not
refer to special section 0"; that issue is fixed for a similar style of
section symbols in 4a4a8a1476b1386b523dc5b292ba9a5a6748a9cf.

Therefore, revert ecb5ea6a266d5cc4e05252f6db4c73613b73cc3b and extend
the fix from 4a4a8a1476b1386b523dc5b292ba9a5a6748a9cf to also work for
the section symbols in MSVC generated import libraries.

The main detail about them, is that for symbols of type
IMAGE_SYM_CLASS_SECTION, the Value field is not an offset, but it is an
optional set of flags, corresponding to the Characteristics of the
section header (although it may be empty).

This is a reland of a previous version of this commit, earlier merged in
9457418e66766d8fafc81f85eb8045986220ca3e / #122811. The previous version
failed tests when run with address sanitizer. The issue was that the
synthesized coff_symbol_generic object actually will be used to access a
full coff_symbol16 or coff_symbol32 struct, see
DefinedCOFF::getCOFFSymbol. Therefore, we need to make a copy of the
full size of either of them.
2025-01-23 09:15:47 +02:00
Jacek Caban
4e9d5a3a30
[LLD][COFF] Add support for the -defArm64Native argument (#123850)
MSVC ignores the `/defArm64Native` argument on non-ARM64X targets.
It is also ignored if the `/def` option is not specified.
2025-01-22 23:32:18 +01:00
Jacek Caban
a2c683b665
[LLD][COFF] Use EC symbol table for exports defined in module definition files (#123849) 2025-01-22 23:30:23 +01:00
Thurston Dang
c53faf63ff
Revert "[LLD] [COFF] Fix linking MSVC generated implib header objects" (#123877)
Reverts llvm/llvm-project#122811 due to buildbot breakage e.g.,
https://lab.llvm.org/buildbot/#/builders/52/builds/5421/steps/11/logs/stdio

ASan output from local re-run:
```
==2780289==ERROR: AddressSanitizer: use-after-poison on address 0x7e0b87e28d28 at pc 0x55a979a99e7e bp 0x7ffe4b18f0b0 sp 0x7ffe4b18f0a8
READ of size 1 at 0x7e0b87e28d28 thread T0
    #0 0x55a979a99e7d in getStorageClass /usr/local/google/home/thurston/buildbot_repro/llvm-project/llvm/include/llvm/Object/COFF.h:344
    #1 0x55a979a99e7d in isSectionDefinition /usr/local/google/home/thurston/buildbot_repro/llvm-project/llvm/include/llvm/Object/COFF.h:429:9
    #2 0x55a979a99e7d in getSymbols /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/COFF/LLDMapFile.cpp:54:42
    #3 0x55a979a99e7d in lld::coff::writeLLDMapFile(lld::coff::COFFLinkerContext const&) /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/COFF/LLDMapFile.cpp:103:40
    #4 0x55a979a16879 in (anonymous namespace)::Writer::run() /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/COFF/Writer.cpp:810:3
    #5 0x55a979a00aac in lld::coff::writeResult(lld::coff::COFFLinkerContext&) /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/COFF/Writer.cpp:354:15
    #6 0x55a97985f7ed in lld::coff::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/COFF/Driver.cpp:2826:3
    #7 0x55a97984cdd3 in lld::coff::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/COFF/Driver.cpp:97:15
    #8 0x55a9797f9793 in lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/Common/DriverDispatcher.cpp:163:12
    #9 0x55a9797fa3b6 in operator() /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/Common/DriverDispatcher.cpp:188:15
    #10 0x55a9797fa3b6 in void llvm::function_ref<void ()>::callback_fn<lld::lldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>)::$_0>(long) /usr/local/google/home/thurston/buildbot_repro/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
    #11 0x55a97966cb93 in operator() /usr/local/google/home/thurston/buildbot_repro/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
    #12 0x55a97966cb93 in llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /usr/local/google/home/thurston/buildbot_repro/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:426:3
    #13 0x55a9797f9dc3 in lld::lldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>) /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/Common/DriverDispatcher.cpp:187:14
    #14 0x55a979627512 in lld_main(int, char**, llvm::ToolContext const&) /usr/local/google/home/thurston/buildbot_repro/llvm-project/lld/tools/lld/lld.cpp:103:14
    #15 0x55a979628731 in main /usr/local/google/home/thurston/buildbot_repro/llvm_build_asan/tools/lld/tools/lld/lld-driver.cpp:17:10
    #16 0x7ffb8b202c89 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #17 0x7ffb8b202d44 in __libc_start_main csu/../csu/libc-start.c:360:3
    #18 0x55a97953ef60 in _start (/usr/local/google/home/thurston/buildbot_repro/llvm_build_asan/bin/lld+0x8fd1f60)
```
2025-01-21 20:40:07 -08:00
Jacek Caban
671ec34fb2
[LLD][COFF] Add support for hybrid exports on ARM64X (#123724) 2025-01-21 22:55:58 +01:00
Martin Storsjö
9457418e66
[LLD] [COFF] Fix linking MSVC generated implib header objects (#122811)
ecb5ea6a266d5cc4e05252f6db4c73613b73cc3b tried to fix cases when LLD
links what seems to be import library header objects from MSVC. However,
the fix seems incorrect; the review at https://reviews.llvm.org/D133627
concluded that if this (treating this kind of symbol as a common symbol)
is what link.exe does, it's fine.

However, this is most probably not what link.exe does. The symbol
mentioned in the commit message of
ecb5ea6a266d5cc4e05252f6db4c73613b73cc3b would be a common symbol with a
size of around 3 GB; this is not what might have been intended.

That commit tried to avoid running into the error ".idata$4 should not
refer to special section 0"; that issue is fixed for a similar style of
section symbols in 4a4a8a1476b1386b523dc5b292ba9a5a6748a9cf.

Therefore, revert ecb5ea6a266d5cc4e05252f6db4c73613b73cc3b and extend
the fix from 4a4a8a1476b1386b523dc5b292ba9a5a6748a9cf to also work for
the section symbols in MSVC generated import libraries.

The main detail about them, is that for symbols of type
IMAGE_SYM_CLASS_SECTION, the Value field is not an offset, but it is an
optional set of flags, corresponding to the Characteristics of the
section header (although it may be empty).
2025-01-21 23:55:41 +02: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
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
b068f2fd0f
[LLD][COFF] Process bitcode files separately for each symbol table on ARM64X (#123194) 2025-01-17 11:36: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
Martin Storsjö
4a4a8a1476
[LLD] [COFF] Fix linking import libraries with -wholearchive: (#122806)
When LLD links against an import library (for the regular, short import
libraries), it doesn't actually link in the header/trailer object files
at all, but synthesizes new corresponding data structures into the right
sections.

If the whole of such an import library is forced to be linked, e.g. with
the -wholearchive: option, we actually end up linking in those
header/trailer objects. The header objects contain a construct which LLD
fails to handle; previously we'd error out with the error ".idata$4
should not refer to special section 0".

Within the import library header object, in the import directory we have
relocations towards the IAT (.idata$4 and .idata$5), but the header
object itself doesn't contain any data for those sections.

In the case of GNU generated import libraries, the header objects
contain zero length sections .idata$4 and .idata$5, with relocations
against them. However in the case of LLVM generated import libraries,
the sections .idata$4 and .idata$5 are not included in the list of
sections. The symbol table does contain section symbols for these
sections, but without any actual associated section. This can probably
be seen as a declaration of an empty section.

If the header/trailer objects of a short import library are linked
forcibly and we also reference other functions in the library, we end up
with two import directory entries for this DLL, one that gets
synthesized by LLD, and one from the actual header object file. This is
inelegant, but should be acceptable.

While it would seem unusual to link import libraries with the
-wholearchive: option, this can happen in certain scenarios.

Rust builds libraries that contain relevant import libraries bundled
along with compiled Rust code as regular object files, all within one
single archive. Such an archive can then end up linked with the
-wholarchive: option, if build systems decide to use such an option for
including static libraries.

This should fix https://github.com/msys2/MINGW-packages/issues/21017.

This works for the header/trailer object files in import libraries
generated by LLVM; import libraries generated by MSVC are vaguely
different. ecb5ea6a266d5cc4e05252f6db4c73613b73cc3b did an attempt at
fixing the issue for MSVC generated libraries, but it's not entirely
correct, and isn't enough for making things work for that case.
2025-01-16 00:09:09 +02:00
Jacek Caban
0360f8170a
[LLD][COFF] Infer subsystem from EC symbol table for ARM64X (#122838) 2025-01-15 17:50:19 +01:00
Jacek Caban
80084e9cb6
[LLD][COFF] Pull _load_config_used symbol from both symbol tables on ARM64X (#122837) 2025-01-15 17:43:33 +01:00
Jacek Caban
616007d88f
[LLD][COFF] Skip sections marked as IMAGE_SCN_LNK_INFO in the output image (#122752)
Fixes #106275.
2025-01-14 17:28:59 +01:00
Jacek Caban
251ef3f503
[LLD][COFF] Use appropriate symbol table for -include argument on ARM64X (#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-13 23:16:57 +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