Commit Graph

17094 Commits

Author SHA1 Message Date
NAKAMURA Takumi
59085e9c3f Fix more lld warnings introduced in #111434 [-Wnontrivial-memaccess] 2024-10-29 16:18:27 +09:00
NAKAMURA Takumi
828467a54e Fix warnings introduced in #111434 [-Wnontrivial-memaccess] 2024-10-29 14:18:24 +09:00
Jacek Caban
31a6dbe941 [LLD][COFF] Add Support for ARM64EC pseudo relocations (#113832) 2024-10-28 18:44:23 +01:00
SharonXSharon
6827a00d4d [lld][InstrProf] Do not use cstring offset hashes in function order for compression (#113606) 2024-10-28 09:47:21 -07:00
Dan Gohman
1bc2cd98c5 [WebAssembly] Enable nontrapping-fptoint and bulk-memory by default. (#112049)
We were prepared to enable these features [back in February], but they
got pulled for what appear to be unrelated reasons. So let's have
another try at enabling them!

Another motivation here is that it'd be convenient for the [Lime1
proposal] if "lime1" is close to a subset of "generic" (missing only
for extended-const).

[back in February]:
https://github.com/WebAssembly/tool-conventions/issues/158#issuecomment-1931119512
[Lime1 proposal]: https://github.com/llvm/llvm-project/pull/112035
2024-10-25 13:52:51 -07:00
Jacek Caban
6bb6922de9 [LLD][COFF] Allow overriding EC alias symbols with alternate names (#113456) 2024-10-25 11:53:47 +02:00
Alexander Richardson
a35ebcf255 [lld][WebAssembly] Update datalayout strings to latest version
These mismatched data layouts are exposed by the refactoring in
https://github.com/llvm/llvm-project/pull/105734 that now also
compares the non-integral pointers list of the data layout.

I dropped the explicit definition from all tests that use opt/llc since
those tools will insert the correct value, but for the llvm-as based
tests and explicit layout is required.

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/107276
2024-10-24 18:11:35 -07:00
Daniil Kovalev
a4ace3de1b [PAC][lld] Fix reloc against adrp imm in PAC PLT header (#113429)
The PAC PLT header contains adrp instruction which immediate should be
filled. In https://reviews.llvm.org/D62609, the adrp instruction address
was calculated incorrectly. This patch resolves the issue.

The test is already present in test/ELF/aarch64-feature-pac.s
2024-10-23 19:47:56 +03:00
Jacek Caban
98bc5295ec [LLD][COFF] Check both mangled and demangled symbols before adding a lazy archive symbol to the symbol table on ARM64EC (#113284)
On ARM64EC, a function symbol may appear in both mangled and demangled
forms:
- ARM64EC archives contain only the mangled name, while the demangled
symbol is defined by the object file as an alias.
- x86_64 archives contain only the demangled name (the mangled name is
usually defined by an object referencing the symbol as an alias to a
guess exit thunk).
- ARM64EC import files contain both the mangled and demangled names for
thunks.

If more than one archive defines the same function, this could lead to
different libraries being used for the same function depending on how
they are referenced. Avoid this by checking if the paired symbol is
already defined before adding a symbol to the table.
2024-10-23 13:10:07 +02:00
Jacek Caban
9b88792291 [LLD][COFF] Allow overriding EC alias symbols with lazy archive symbols (#113283)
On ARM64EC, external function calls emit a pair of weak-dependency
aliases: `func` to `#func` and `#func` to the `func` guess exit thunk
(instead of a single undefined `func` symbol, which would be emitted on
other targets). Allow such aliases to be overridden by lazy archive
symbols, just as we would for undefined symbols.
2024-10-23 12:43:38 +02:00
Sam Clegg
0764e55c91 [lld][WebAssembly] Improve -v/-V/--version flag compat (#113204)
Fixes: #112836
2024-10-22 10:47:57 -07:00
Arthur Eubanks
dca43a1c82 [lld/Macho][test] Mark objc-category-merging-minimal.s as unsupported on Windows (#113209)
With #112981, the test uses awk, which gnuwin32 doesn't seem to have.
2024-10-21 12:45:51 -07:00
Ellis Hoag
ed5072ee28 [NFC][lld-macho] Generate test bodies for icf-safe-thunk tests (#111927)
Autogenerate `.ll` code from cpp code in some `-icf-safe-thunk` tests
using `update_test_body.py`

```
PATH=build/bin:$PATH llvm/utils/update_test_body.py lld/test/MachO/icf-safe-thunks.ll lld/test/MachO/icf-safe-thunks-dwarf.ll
```
https://llvm.org/docs/TestingGuide.html#elaborated-tests

I recently became aware of this tool and I wanted to practice using it.
This also allows to remove the custom instructions to generate the `.ll`
code.
2024-10-21 10:46:21 -07:00
Jacek Caban
f1ba8943c8 [LLD][COFF] Support anti-dependency symbols (#112542)
Co-authored-by: Billy Laws <blaws05@gmail.com>

Anti-dependency symbols are allowed to be duplicated, with the first
definition taking precedence. If a regular weak alias is present, it is
preferred over an anti-dependency definition. Chaining anti-dependencies
is not allowed.
2024-10-21 11:44:31 +02:00
Fangrui Song
e6625a2c10 [ELF] Pass Ctx & 2024-10-19 21:08:50 -07:00
Fangrui Song
5d928ffce2 [ELF] Remove error-prone RelocationBaseSection::classof 2024-10-19 21:02:03 -07:00
Fangrui Song
861bd36bce [ELF] Pass Ctx & to Symbol::getVA 2024-10-19 20:32:58 -07:00
Fangrui Song
fe8af49a1b [ELF] Pass Ctx & to Defined & CommonSymbol 2024-10-20 01:38:16 +00:00
alx32
b35b583809 [lld-macho] Fix category merging sed issue - Try nr.2 (#112981)
We replace sed with awk as I couldn't find a syntax that works
consistently on Linux/Mac for sed.
Repro'ed original issue on Mac and confirmed working now on Mac/Linux.
2024-10-18 15:45:00 -07:00
alx32
caa9e41814 [lld-macho] Fix category merging sed issue (#112955)
Fix 'sed' spacing to ensure compatibility with all platforms. 

Original failure:
https://lab.llvm.org/buildbot/#/builders/190/builds/7903
```
RUN: at line 33: sed -E '/^__OBJC_\$_CATEGORY_MyBaseClass_\$_Category01:/ { n; s/^[ \t]*\.quad[ \t]+l_OBJC_CLASS_NAME_$/\t.quad\tL_OBJC_IMAGE_INFO+3/ }' merge_cat_minimal.s > merge_cat_minimal_bad_name.s
+ sed -E '/^__OBJC_\$_CATEGORY_MyBaseClass_\$_Category01:/ { n; s/^[ \t]*\.quad[ \t]+l_OBJC_CLASS_NAME_$/\t.quad\tL_OBJC_IMAGE_INFO+3/ }' merge_cat_minimal.s
sed: 1: "/^__OBJC_\$_CATEGORY_My ...": bad flag in substitute command: '}'
```
2024-10-18 11:51:21 -07:00
alx32
f9d3e98207 [lld-macho] Improve robustness of ObjC category merging (#112618)
This patch enhances the robustness of lld's Objective-C category
merging. Currently, the category merger assumes it can fully parse and
understand the format of all categories in the input, triggering an
assert if any invalid category data is encountered.

This will end up causing asserts in certain rare corner cases that are
difficult to reproduce in small test cases. The proposed changes modify
the behavior so that if invalid category data is detected, category
merging is skipped for that specific class and all other categories
sharing the same base class. This approach allows the linker to continue
processing other categories without failing entirely due to a single
problematic input.

We also add a LIT test to where we corrupt category data and check that
category merging for that class was skipped but the link was successful.
2024-10-18 11:03:16 -07:00
Fangrui Song
682925ef43 [ELF] Pass Ctx & to Partition 2024-10-15 22:58:07 -07:00
Karl-Johan Karlsson
cfc10bea9d [lld] Fix warning in SymbolTable.cpp (#112323)
Fix gcc warning:

lld/ELF/SymbolTable.cpp:340:33: warning: enumeral and non-enumeral type
in conditional expression [-Wextra]
2024-10-16 06:34:54 +02:00
Jacek Caban
ba898dba48 [LLD][COFF] Fix handling of weak aliases referencing lazy symbols (#112243)
The assumption that a symbol is either `Defined` or `Undefined` is not
always true for some cases. For example, `mangleMaybe` may create a weak
alias to a lazy archive symbol.
2024-10-15 22:58:13 +02:00
Fangrui Song
a2359a865a [ELF] Fix PROVIDE_HIDDEN -shared regression with bitcode file references
The inaccurate #111945 condition fixes a PROVIDE regression (#111478)
but introduces another regression: in a DSO link, if a symbol referenced
only by bitcode files is defined as PROVIDE_HIDDEN, lld would not set
the visibility correctly, leading to an assertion failure in
DynamicReloc::getSymIndex (https://reviews.llvm.org/D123985).
This is because `(sym->isUsedInRegularObj || sym->exportDynamic)` is
initially false (bitcode undef does not set `isUsedInRegularObj`) then
true (in `addSymbol`, after LTO compilation).

Fix this by making the condition accurate: use a map to track defined
symbols.

Reviewers: smithp35

Reviewed By: smithp35

Pull Request: https://github.com/llvm/llvm-project/pull/112386
2024-10-15 09:20:10 -07:00
Kazu Hirata
3c2e1d3a00 [lld] Avoid repeated hash lookups (NFC) (#112299) 2024-10-15 07:35:42 -07:00
Yuta Saito
58bf78ce9e [lld][WebAssembly] Fix build break when building liblldWasm.so (#112275)
Fix `BUILD_SHARED_LIBS=ON` build for
d4efc3e097
2024-10-15 07:04:27 +09:00
Yuta Saito
d4efc3e097 [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (#111332)
Currently, WebAssembly/WASI target does not provide direct support for
code coverage.
This patch set fixes several issues to unlock the feature. The main
changes are:

1. Port `compiler-rt/lib/profile` to WebAssembly/WASI.
2. Adjust profile metadata sections for Wasm object file format.
- [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections
instead of data segments.
    - [lld] Align the interval space of custom sections at link time.
- [llvm-cov] Copy misaligned custom section data if the start address is
not aligned.
    - [llvm-cov] Read `__llvm_prf_names` from data segments
3. [clang] Link with profile runtime libraries if requested

See each commit message for more details and rationale.
This is part of the effort to add code coverage support in Wasm target
of Swift toolchain.
2024-10-15 02:41:43 +09:00
Fangrui Song
2c5dd03f55 [ELF] Pass Ctx & to check* 2024-10-13 11:14:40 -07:00
Fangrui Song
0dbc85a59f [ELF] Pass Ctx & to Arch-specific code 2024-10-13 11:08:06 -07:00
Fangrui Song
9fe567f0bf [ELF] Pass Ctx & to Mips 2024-10-13 10:55:05 -07:00
Fangrui Song
002ca63b3f [ELF] Pass Ctx & to (read|write)(16|64) 2024-10-13 10:47:18 -07:00
Fangrui Song
38dfcd9ac9 [ELF] Pass Ctx & to read32/write32 2024-10-13 10:37:47 -07:00
Kazu Hirata
1641745530 [lld] Avoid repeated hash lookups (NFC) (#112119) 2024-10-13 07:33:32 -07:00
Fangrui Song
a3bad9adcb [ELF] Pass Ctx & 2024-10-12 09:56:05 -07:00
Fangrui Song
dbd197118d [ELF] Pass Ctx & to Symbol 2024-10-11 23:34:43 -07:00
Fangrui Song
dd326b1225 [ELF] Pass Ctx & 2024-10-11 21:10:05 -07:00
Fangrui Song
d0606c265e [ELF] Make .comment have a non-full file
This ensures that SectionBase::file is non-null except
InputSection::discarded.
2024-10-11 20:55:21 -07:00
Fangrui Song
c33133279b [ELF] Pass Ctx & to InputSection 2024-10-11 20:39:53 -07:00
Fangrui Song
9bf2e20b17 [ELF] Pass Ctx & to OutputSection 2024-10-11 20:28:58 -07:00
Fangrui Song
6dd773b650 [ELF] Pass Ctx & 2024-10-11 20:15:02 -07:00
Fangrui Song
1c28f31133 [ELF] Pass Ctx & 2024-10-11 18:35:02 -07:00
Brian Cain
77aa8257ac [lld][Hexagon] Support predicated-add GOT_16_X mask lookup (#111896)
When encountering an instruction like `if (p0) r0 = add(r0,##bar@GOT)`,
lld would fail with:
```
ld.lld: error: unrecognized instruction for 16_X type: 0x7400C000
```

This issue was encountered while building libreadline with clang 19.1.0.

Fixes: #111876
2024-10-11 14:31:41 -05:00
Fangrui Song
1c6688ae34 [ELF] Make shouldAddProvideSym return values consistent when demoted to Undefined
Case: `PROVIDE(f1 = bar);` when both `f1` and `bar` are in separate
sections that would be discarded by GC.

Due to `demoteDefined`, `shouldAddProvideSym(f1)` may initially return
false (when Defined) and then return true (been demoted to Undefined).

```
addScriptReferencedSymbolsToSymTable
  shouldAddProvideSym(f1): false
  // the RHS (bar) is not added to `referencedSymbols` and may be GCed
declareSymbols
  shouldAddProvideSym(f1): false
markLive
demoteSymbolsAndComputeIsPreemptible
  // demoted f1 to Undefined
processSymbolAssignments
  addSymbol
    shouldAddProvideSym(f1): true
```

The inconsistency can cause `cmd->expression()` in `addSymbol` to be
evaluated, leading to `symbol not found: bar` errors (since `bar` in the
RHS is not in `referencedSymbols` and is GCed) (#111478).

Fix this by adding a `sym->isUsedInRegularObj` condition, making
`shouldAddProvideSym(f1)` values consistent. In addition, we need a
`sym->exportDynamic` condition to keep provide-shared.s working.

Fixes: ebb326a51f

Pull Request: https://github.com/llvm/llvm-project/pull/111945
2024-10-11 08:47:07 -07:00
Fangrui Song
81bd712f92 [ELF] Revert Ctx & parameters from SyntheticSection
Since Ctx &ctx is a member variable,
1f391a75af
7a5b9ef54e
e2f0ec3a3a can be reverted.
2024-10-10 23:43:21 -07:00
Fangrui Song
d91c103a10 [ELF] Pass Ctx & to SyntheticSections 2024-10-10 23:28:25 -07:00
Fangrui Song
25cda9e069 [ELF] Pass Ctx & to SyntheticSection 2024-10-10 23:07:02 -07:00
Fangrui Song
e018f550d0 [ELF] Pass Ctx & 2024-10-10 22:22:25 -07:00
Fangrui Song
c22588c7cd [ELF] Move InputSectionBase::file to SectionBase
... and add getCtx (file->ctx). This allows InputSectionBase and
OutputSection to access ctx without taking an extra function argument.
2024-10-10 22:15:10 -07:00
Fangrui Song
bf81bd800f [ELF] Pass Ctx & 2024-10-10 21:36:51 -07:00