Commit Graph

17232 Commits

Author SHA1 Message Date
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
Sam Elliott
65ced158e9 [RISCV] Remove R_RISCV_RVC_LUI Relocation (#118714)
This was removed from the ABI in riscv-non-isa/riscv-elf-psabi-doc#398.
It is not emitted by LLVM, and seems to have been an internal
implementation detail in binutils.

This is a follow-up to 26ec5da744 which removed previous binutils
internal relocations when they were removed from the ABI.

The LLD implementation was not tested when it was added in
https://reviews.llvm.org/D39322
2024-12-05 10:10:27 +00:00
Feng Zou
636beb6a28 [X86][LLD] Handle R_X86_64_CODE_6_GOTTPOFF relocation type (#117675)
For

    add %reg1, name@GOTTPOFF(%rip), %reg2
    add name@GOTTPOFF(%rip), %reg1, %reg2
    {nf} add %reg1, name@GOTTPOFF(%rip), %reg2
    {nf} add name@GOTTPOFF(%rip), %reg1, %reg2
    {nf} add name@GOTTPOFF(%rip), %reg

add

    R_X86_64_CODE_6_GOTTPOFF = 50

in #117277.

Linker can treat R_X86_64_CODE_6_GOTTPOFF as R_X86_64_GOTTPOFF or
convert the instructions above to

    add $name@tpoff, %reg1, %reg2
    add $name@tpoff, %reg1, %reg2
    {nf} add $name@tpoff, %reg1, %reg2
    {nf} add $name@tpoff, %reg1, %reg2
    {nf} add $name@tpoff, %reg

if the first byte of the instruction at the relocation offset - 6 is
0x62 (namely, encoded w/EVEX prefix) when possible.

Binutils patch: bminor/binutils-gdb@5bc71c2
Binutils mailthread:
https://sourceware.org/pipermail/binutils/2024-February/132351.html
ABI discussion:
https://groups.google.com/g/x86-64-abi/c/FhEZjCtDLFw/m/VHDjN4orAgAJ
Blog: https://kanrobert.github.io/rfc/All-about-APX-relocation
2024-12-05 16:26:26 +08:00
pcc
970d6d2096 ELF: Have __rela_iplt_{start,end} surround .rela.iplt with --pack-dyn-relocs=android.
In #86751 we moved the IRELATIVE relocations to .rela.plt when
--pack-dyn-relocs=android was enabled but we neglected to also move
the __rela_iplt_{start,end} symbols. As a result, static binaries
linked with this flag were unable to find their IRELATIVE relocations.
Fix it by having the symbols surround the correct section.

Reviewers: MaskRay, smithp35

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/118585
2024-12-04 17:35:05 -08: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
59bc03cf8e [lld-link] Simplify warnUnusable. NFC 2024-12-03 22:33:36 -08:00
Fangrui Song
1534f45694 [lld-link] Replace warn(...) with Warn(ctx) 2024-12-03 22:19:30 -08:00
Anutosh Bhat
52aff97f40 [lld][wasm] Clear lazyBitcodeFiles while resetting context (#118440)
Hi @sbc100 

I was looking into a use case involving the link function (which got my
attention to reset).

I see that `lazyBitcodeFiles` variable was introduced here
https://github.com/llvm/llvm-project/pull/114327 but I don't see it
being reset while destroying the context eventually. Hopefully this
should be the correct way to address it.
2024-12-03 22:18:43 -08:00
Fangrui Song
bc66e9aaa6 [lld-link] Replace message(...) with Msg(ctx)
to avoid the global ctx.
2024-12-03 21:29:02 -08:00
Fangrui Song
982575fd06 [lld-link] Add context-aware diagnostic functions (#118430)
Similar to #112319 for ELF. While there is some initial boilerplate, it
can simplify some call sites that use Twine, especially when a printed
element uses `ctx` or toString.
2024-12-03 20:51:50 -08:00
Ulrich Weigand
d1f4f63680 [SystemZ] Use nop mnemonics for disassembly
To match the behavior of GNU binutils, output the nop family
of mnemonic aliases when disassembling.
2024-12-03 18:51:20 +01:00
Fangrui Song
04996a28b7 [ELF] Rename target-specific RelExpr enumerators
RelExpr enumerators are named `R_*`, which can be confused with ELF
relocation type names. Rename the target-specific ones to `RE_*` to
avoid confusion.

For consistency, the target-independent ones can be renamed as well, but
that's not urgent. The relocation processing mechanism with RelExpr has
non-trivial overhead compared with mold's approach, and we might make
more code into Arch/*.cpp files and decrease the enumerators.

Pull Request: https://github.com/llvm/llvm-project/pull/118424
2024-12-03 09:17:17 -08:00
David Spickett
6292327556 [lld] Convert CODE_OWNERS.txt to Maintainers.md (#118084)
To align with https://llvm.org/docs/DeveloperPolicy.html#maintainers

I've moved the file and changed it to markdown to match `llvm/`'s file.
2024-12-03 11:44:54 +00:00
Dan Gohman
c3536b263f [WebAssembly] Define call-indirect-overlong and bulk-memory-opt features (#117087)
This defines some new target features. These are subsets of existing
features that reflect implementation concerns:

- "call-indirect-overlong" - implied by "reference-types"; just the
overlong encoding for the `call_indirect` immediate, and not the actual
reference types.

- "bulk-memory-opt" - implied by "bulk-memory": just `memory.copy` and
`memory.fill`, and not the other instructions in the bulk-memory
proposal.

This is split out from https://github.com/llvm/llvm-project/pull/112035.

---------

Co-authored-by: Heejin Ahn <aheejin@gmail.com>
2024-12-02 17:08:07 -08:00
Alexander Richardson
a6fa51f5ce [lld] Move handling of message separator to reportDiagnostic()
This ensures that it is also updated when calling log() and not just for
errors and warnings. This was noticed in the downstream CHERI fork where
a test using CHECK-NEXT was seeing empty lines after single-line log()
messages.

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/117587
2024-12-02 10:36:32 -08:00
Fangrui Song
d9d656edd4 [ELF] resolve LazySymbol: remove a branch in the fast path 2024-12-01 23:07:38 -08:00
Fangrui Song
a09df64f40 [ELF] postParse: remove some branches in the fast path 2024-12-01 14:18:10 -08:00
Fangrui Song
603d41ab7b [ELF] decompress: remove mutex
decompress() is in the parallel code path splitIntoPieces
and we should avoid mutex.
2024-12-01 14:02:44 -08:00
Fangrui Song
9becc4a3c9 [ELF] ObjFile::parse: check EM_AARCH64 for SHT_AARCH64_MEMTAG_GLOBAL_STATIC
and reorder sh_type checks to make SHT_PROGBITS/SHT_GROUP fast.
2024-12-01 12:03:35 -08:00
Fangrui Song
ee19eb3037 [ELF] Change some upper-case utohexstr to lower-case to improve consistency
The convention is to use lower-case addresses.
2024-11-29 18:37:47 -08:00
Fangrui Song
10b98473e8 [ELF] Simplify --print-icf-sections 2024-11-29 18:26:29 -08:00
Fangrui Song
1f13713dbb [ELF] Change getSrcMsg to use ELFSyncStream. NFC 2024-11-29 17:18:22 -08:00
Fangrui Song
666de79595 [ELF] Move some ObjFile members to ELFFileBase to simplify getSrcMsg 2024-11-29 15:48:46 -08:00
Fangrui Song
05ff6e7948 [ELF] Use lower case offset in getObjMsg
to improve consistency with other diagnostics. While here, migrate to
use ELFSyncStream to drop toStr/getCtx uses and avoid string overhead.
2024-11-29 13:00:36 -08:00
Carlo Cabrera
d668304998 [lld][MachO] Support -allowable_client (#117155)
Closes #117113.

Follow-up to #114638.
2024-11-27 11:23:49 -05:00
Feng Zou
fad5ed6e90 [X86][LLD] Handle R_X86_64_CODE_4_GOTPC32_TLSDESC relocation type (#116909)
For

  lea name@tlsdesc(%rip), %reg

add

  R_X86_64_CODE_4_GOTPC32_TLSDESC = 45

in #116908.

Linker can treat R_X86_64_CODE_4_GOTPC32_TLSDESC as
R_X86_64_GOTPC32_TLSDESC or convert the instruction above to

  mov $name@tpoff, %reg

if the first byte of the instruction at the relocation offset - 4 is
0xd5 (namely, encoded w/REX2 prefix) when possible.

Binutils patch: a533c8df59
Binutils mailthread: https://sourceware.org/pipermail/binutils/2023-December/131463.html
ABI discussion: https://groups.google.com/g/x86-64-abi/c/ACwD-UQXVDs/m/vrgTenKyFwAJ
Blog: https://kanrobert.github.io/rfc/All-about-APX-relocation
2024-11-27 09:31:12 +08:00
Feng Zou
73d1abb018 [X86][LLD] Handle R_X86_64_CODE_4_GOTTPOFF relocation type (#116634)
For

  mov name@GOTTPOFF(%rip), %reg
  add name@GOTTPOFF(%rip), %reg

add

  `R_X86_64_CODE_4_GOTTPOFF` = 44

in #116633.

Linker can treat `R_X86_64_CODE_4_GOTTPOFF` as `R_X86_64_GOTTPOFF` or
convert the instructions above to

  mov $name, %reg
  add $name, %reg

if the first byte of the instruction at the relocation `offset - 4` is
`0xd5` (namely, encoded w/REX2 prefix) when possible.

Binutils patch: a533c8df59
Binutils mailthread: https://sourceware.org/pipermail/binutils/2023-December/131463.html
ABI discussion: https://groups.google.com/g/x86-64-abi/c/ACwD-UQXVDs/m/vrgTenKyFwAJ
Blog: https://kanrobert.github.io/rfc/All-about-APX-relocation
2024-11-27 09:25:31 +08:00
Oliver Stannard
6512e488f6 [LLD][ARM] Allow R_ARM_SBREL32 relocations in debug info (#116956)
The R_ARM_SBREL32 relocation is used in debug info for ARM RWPI
(read-write position independent) code. Compiler-generated DWARF info
will use an expression to add the relocated value to the actual value of
the static base (held in r9) at run-time, so it should be relocated as
if the static base is at address 0.
2024-11-25 08:51:27 +00:00
Fangrui Song
6aeffa18e9 [ELF] --reproduce: strip directories for --dependency-file=
CMake may generate build.ninja with DEP_FILE specifying a non-existent
directory in the reproduce tarball.
2024-11-24 17:23:52 -08:00
Fangrui Song
1cd627562b [ELF] Remove unneeded Twine in ELFSyncStream 2024-11-24 12:13:02 -08:00
Fangrui Song
c4dc5ed825 [ELF] Avoid some toStr and ErrAlways 2024-11-24 11:43:40 -08:00
Fangrui Song
c790d6f53f [ELF] isCompatile: avoid a toStr and 2 ErrAlways 2024-11-24 11:30:21 -08:00
Fangrui Song
360718fb90 [test] Improve symbol-location.s to check --defsym 2024-11-24 11:22:19 -08:00
Fangrui Song
d8495ede01 [ELF] Change getLocation to use ELFSyncStream. NFC 2024-11-24 11:16:52 -08:00
Fangrui Song
ff97b28334 [ELF] Simplif reportUndefinedSymbol. NFC 2024-11-24 10:34:11 -08:00
Jacek Caban
f942949a7c [LLD][COFF] Require explicit specification of ARM64EC target (#116281)
Inferring the ARM64EC target can lead to errors. The `-machine:arm64ec`
option may include x86_64 input files, and any valid ARM64EC input is
also valid for `-machine:arm64x`. MSVC requires an explicit `-machine`
argument with informative diagnostics; this patch adopts the same
behavior.
2024-11-24 14:33:14 +01:00
Fangrui Song
eb4d2f24a7 [ELF] Simplify reportMissingFeature. NFC 2024-11-23 22:49:28 -08:00
Fangrui Song
1a2cc2bce8 [ELF] Exclude sizeof(InputSection) to _WIN32
Structs with delicate packing are often larger in MSVC than Itanium.
099a52fd2f did not make
sizeof(InputSection) smaller for MSVC. Just exclude MSVC.
2024-11-23 21:42:22 -08:00
Fangrui Song
a87f776c1c [ELF] Avoid make in elf::writeARMCmseImportLib 2024-11-23 17:28:28 -08:00
Fangrui Song
e4e5206050 [ELF] Make OutputDesc unique_ptr
Store them in LinkerScript::descPool. This removes a SpecificAlloc
instantiation, makes lld smaller, and drops the small memory waste due
to the separate BumpPtrAllocator.
2024-11-23 17:14:43 -08:00
Fangrui Song
099a52fd2f [ELF] Reorder SectionBase/InputSectionBase members
Move `sectionKind` outside the bitfield and move bss/keepUnique to
InputSectionBase.

* sizeof(InputSection) decreases from 160 to 152 on 64-bit systems.
* The numerous `sectionKind` accesses are faster.
2024-11-23 16:34:21 -08:00
Fangrui Song
a5af6214dd [ELF] Make SyntheticSection parameter order match InputSection
And rename `/*alignment=*/` to `/*addralign=*/`
2024-11-23 15:16:36 -08:00
Fangrui Song
d4bed617f4 [ELF] -r: keep sh_entsize for SHF_MERGE sections with relocations
Follow-up to the NFC refactoring
43e3871a32 and test cleanup
3cecf17065.

SHF_MERGE sections with relocations are handled as InputSection (without
duplicate elimination). The output section retains the original
sh_entsize in non-relocatable links. This patch ports the behavior for
relocatable links as well.

https://github.com/ClangBuiltLinux/linux/issues/2057
2024-11-23 14:32:32 -08:00
Fangrui Song
43e3871a32 [ELF] Make section member orders consistent
SectionBase, InputSectionBase, InputSection, MergeInputSection, and
OutputSection have different member orders. Make them consistent and
adopt the order similar to the raw Elf64_Shdr.
2024-11-23 14:22:24 -08:00
Fangrui Song
3cecf17065 [ELF] Refactor merge-* tests 2024-11-23 12:46:35 -08:00
Tom Lin
b4e000e600 [LLD][MachO] Enable plugin support for LTO (#115690)
Add new CLI options for feature parity with ELF w.r.t pass plugins.
Most of the changes are ported directly from
0c86198b27.
With this change, it is now possible to load and run external pass
plugins during the LTO phase.
2024-11-22 15:01:59 -08:00
Martin Storsjö
063a6f70a6 [LLD] [MinGW] Get rid of trailing whitespace. NFC. 2024-11-22 12:33:54 +02:00
Fangrui Song
1490f38b22 [ELF] Avoid make<ArmCmseSGVeneer>
Store them as unique_ptr in sgVeneers instead.
2024-11-21 23:16:05 -08:00