[Mips] Fix getInstSizeInBytes for instructions with delay slots (#216665)
MIPS branch/jump instructions (B, BEQ, JALR64Pseudo, PseudoReturn64,
etc.) have a delay slot. The actual encoded size is 8 bytes (instr +
NOP). This fixes "out of range PC16 fixup" errors on large functions.
This issue was exposed in llvm 23 by commit pr #191460 which changed
MipsBranchExpansion to use MBB::iterator instead of instr_iterator,
making the MBB size calculation more accurate and revealing the
pre-existing bug.
Thanks for the pr #187703 `AllowOverEstimate` to help find instr which
actual size mismatch expected size .
Fix #112010.
(cherry picked from commit a97f512d71574c0b9adc9bc6216909387499e0e8)
[llvm][AArch64] Avoid iterating off the beginning of a BB in a backward scan (#217752)
... using a reversed range, rather than raw iterator comparisons, which
got us in trouble previously in a block that was entirely made up of
FrameDestroy instructions.
rdar://185425744
[X86] lowerFPToIntToFP - handle signedness for fp->int and int->fp independently (#217404)
We were assuming that both conversions were for the same integer
signedness
Fixes #217355
(cherry picked from commit fc70e3de24b441c8dc01b0759f9ab1b1242e507d)
[lld][WebAssembly] Update incorrect assertion in global relocation code (#215929)
When extended-const is enabled, non-TLS global relocations are handled
via extended constant expressions. However, TLS GOT entries still
require runtime relocation code in `__wasm_apply_global_tls_relocs`
because TLS global addresses depend on `__tls_base`.
Allow `GlobalSection::generateRelocationCode` to be called when `TLS` is
true even if `ctx.arg.extendedConst` is set.
(cherry picked from commit 82ea231835eb238ee38ee379574eea02465d325b)
[LegalizeTypes] Allow v1i128 as a valid SETCC result type during vector operand scalarization (#216136)
PowerPC registers v1i128 as a legal type when P8Altivec is available.
When lowering <4 x fp128> comparisons, the type legalizer hits a v1i1
only assert. Generalize the assert to accept any single-element vector
result type.
(cherry picked from commit 9f4703cbe60fa1e15e407256c856c9cc761141b7)
[ARM] Allow tTAILJMPd on v8-M Baseline (#216747)
a1189106d5a1 added B.W to v8-M Baseline, relaxing t2B, tCBZ and tCBNZ
from Requires<[IsThumb2]> to Requires<[IsThumb, HasV8MBaseline]>, and
enabled tail calls for it. It missed tTAILJMPd, which expands to t2B but
still required IsThumb2, so emitting a tail call for a Thumb1 MachO
target failed:
> LLVM ERROR: Attempting to emit tTAILJMPd instruction but the
Feature_IsThumb2 predicate(s) are not met
(cherry picked from commit 0ef7e0c4076e8a8d590b82bdd0fa6904d20ab2fb)
[lit][bazel] Fall back to a default PATHEXT when the variable is unset (#217416)
When running tests on Windows with Bazel, we can enter a scenario where
`PATHEXT` is stripped from the environment before python starts,
resulting in binaries not being found. This change adds a common
fallback in the event `PATHEXT` is ever undefined or set to an empty
value.
[WebAssembly] Fix __init_tls_base global in coop threading (#208597)
This commit updates how `wasm-ld` initializes the `__init_tls_base`
global during module instantiation. Previously this global was left
entirely unmodified meaning that it was always 0. This change updates
the `__wasm_init_memory` function to set this global dynamically in PIC
mode based on the TLS address calculation, or in non-PIC mode the
generation of `__wasm_init_memory` correctly sets it to the desired TLS
address.
cc https://github.com/WebAssembly/wasi-libc/issues/819
[WebAssembly] Fix issues combining coop threads and PIC (#208332)
This commit fixes a few issues that have surfaced in `wasm-ld`'s
handling of `--cooperative-threading` with `-shared`. Two primary issues
fixed are:
* The `__wasm_init_memory` function was not valid as it referenced
nonexistent locals. This was fixed by adjusting how locals are declared
to make this a bit more flexible.
* Combining data segments for PIC without extended-const is generalized
to only operate on active data segments and is now orthogonal to
threading. With coop threads there's a mixture of passive/active
segments (TLS is passive, other data is active) and the active segments
still need combining while TLS stays passive.
The latter fix ended up touching a few more areas. The first is that
`.tdata` sections are now sorted just before `.bss`, the end section,
rather than first. This is done to ensure that active segments when
combined can indeed start at a relative address of 0 (as required
[3 lines not shown]
[lld][WebAssembly] Follow relocations of TLS-base accessors during GC (#206831)
With `--gc-sections` (the default), `wasm-ld` garbage-collects functions
that are only reachable through `__wasm_get_tls_base` /
`__wasm_set_tls_base` in the cooperative-threading (libcall
thread-context) configuration. This produces a linked module that is
invalid or behaves incorrectly: the relocation inside
`__wasm_set_tls_base` is left dangling / mis-resolved, so callers trap
at runtime (e.g. `validation error: ... values remaining on stack at end
of block`, or a call to an unrelated function).
In cooperative-threading mode (`--cooperative-threading`, added in
#200855), per-task thread context is accessed through libcalls rather
than wasm globals. `wasm-ld` synthesizes `__wasm_init_tls` /
`__wasm_init_memory`, which invoke `__wasm_get_tls_base` and
`__wasm_set_tls_base` via **raw `call` instructions that carry no
relocations**. To keep those accessors in the output, the linker marks
them live with `Symbol::markLive()`.
[77 lines not shown]
[WebAssembly] Default export tables with `--cooperative-threading` (#208263)
This commit is a change to `wasm-ld`'s behavior when the
`--cooperative-threading` flag is passed to the linker. The change here
is to by default work as if `--export-table` was passed as well. This is
required conventionally on this target because the table is where
function pointers are read from in the component model
`thread.new-indirect` intrinsic. If the table is not exported then
there's no way to turn the core module into a component so it's
effectively required. This behavior only applies to when the table isn't
otherwise imported, for example in shared libraries.
The other motivation behind this change is that it'll avoid the need to
manually specify `-Wl,--export-table` when compiling for the
`wasm32-wasip3` target. This additionally avoids the need for the Clang
driver to figure out if flags like `--import-table` were otherwise
passed. Basically it seemed best to put this in `wasm-ld` itself to
avoid as little juggling of pieces as necessary.
cc WebAssembly/wasi-libc#808
[ObjcARCContract] Do not replace llvm.lifetime argument. (#216991)
Only alloca or poison is allowed as arguments for lifetime intrinsics.
Before replacing, check if the operand can be replaced with a variable
and skip replacement if it is not valid.
Fixes a verifier crash in the added test case.
PR: https://github.com/llvm/llvm-project/pull/216991
(cherry picked from commit 13034ef965533cdc9d215a8d506ee8250ead972b)
[lldb] Serve MemoryCache::ReadRanges from the L2 cache as well as L1 (#216318)
`MemoryCache::Read` fetches a whole L2 cache line for any read that fits
in one,
so reading a few bytes caches the line around them. `ReadRanges` probed
only L1,
and re-fetched ranges that line already held. Callers hit this whenever
they
read an array's header and then batch the elements that follow it in the
same
line, as `AppleObjCRuntimeV2::SharedCacheImageHeaders` and
`ClassDescriptorV2::method_list_t` both do. #201166 uses MemoryCache in
`Process::ReadRangesFromMemory`, but I didn't see why is L1 used only.
Add `FindL2CacheEntry`, a lookup that never reads from the inferior, and
consult
it after L1. When it serves every range in a batch, `ReadRanges` returns
without
calling `Process::DoReadMemoryRanges`, so no packet is sent. As in the
[18 lines not shown]
[LLDB] Let ValueObject::CanSetValue() return a reason (#217454)
This API will be called, for example, by DIL to determine whether
expressions with assignments can be evaluated. In these cases it will be
beneficial to also return a reason for the denial to the user.
This patch also updates the SBAPI variant of this
method. Unfortunately `bool SBValue::CanSetValue()` is already in the
stable/23.x branch, so I am adding a new method `SBError
SBValue::CanSet()`. The "Value" in the name is redundant, so this should
be a nice API cleanup.
[LV] Add additional tests with redundant wide IV operations (NFC). (#217749)
Add test cases where wide IVs survive, even though only the first lane
is used.
[InstCombine] Fix miscompile when folding a select into a masked load (#216730)
`visitSelectInst` folds:
select(mask, masked.load(ptr, mask, PT), FV)
into:
masked.load(ptr, mask, FV)
The replacement load was previously created at the select, effectively
moving the memory access past any intervening instructions. If one of
them writes the loaded memory, the replacement load reads the updated
value instead of the original one. This was also observed downstream in
[ispc/ispc#3891](https://github.com/ispc/ispc/issues/3891).
The fold was added in `eb8589987267`. The issue is labelled
`regression:22`, so it affects LLVM 22.1 as well as current trunk.
[15 lines not shown]
[lldb] Fix SBValue.format property (#216802)
lldb.SBValue.format should map to GetFormat instead of GetName
(cherry picked from commit 91ba38d018aaf672fad6c7a41da8d725f659417f)
[SSAF] Fix Expected return type in TypeConstrainedPointers deserialization (gcc 7.5.0) (#211331)
GCC 7.5.0 fails to compile this code. Use explicit upcasts from
std::unique_ptr<Derived> to std::unique_ptr<Base> in deserializeSummary
and deserializeAnalysisResult. This resolves a compilation error where
llvm::Expected<std::unique_ptr<Base>> could not be constructed from
unique_ptr of derived summary/result types.
[clang][KCFI] Skip the KCFIPass on Hexagon (#211716)
Hexagon implements KCFI operand-bundle lowering in the back end
HexagonTargetLowering::EmitKCFICheck emits a KCFI_CHECK pseudo, which
HexagonAsmPrinter::LowerKCFI_CHECK expands into a type-hash check and a
trap - like PS_crash.
Hexagon was never added to the list in addKCFIPass() of targets whose
back end lowers the bundles, so Clang kept running the middle-end
KCFIPass for it.
Add Hexagon to the addKCFIPass() early-return so the "kcfi" bundles
reach the back end, which then emits the trapping load that actually
blocks the call.
(cherry picked from commit 23a601dc9690d42a0b6e69b10279a6f002708ee6)
[lldb][debugserver] Expedite the stopped frame's stack memory in jThreadsInfo (#212706)
Add `ReadFrameZeroStackMemory`, which expedites the innermost frame's stack
memory so a variables view on a stop is served from lldb's memory cache. When
frame 0's `$fp` looks usable, two windows are expedited:
* `[$fp + 2*ptr_size, $fp + 2*ptr_size + k_expedite_stack_arg_size)` for stack-passed
parameters, starting above the saved `{fp, lr}` pair the backchain already covers.
* `[$fp - below, $fp)`, `below = min($fp - $sp, k_expedite_stack_window - k_expedite_stack_arg_size)`,
for locals and spilled register arguments. A small frame gets all of `[$sp, $fp)`; a large one keeps the part nearest `$fp`, so the cost stays bounded.
If `$fp` fails validation (frameless leaf, or `$fp` used as a scratch GPR),
a single `[$sp, $sp + k_expedite_stack_window)` window is expedited instead.
Each window is a separate chunk, because lldb's L1 cache only serves reads
fully contained in one expedited chunk. Only the thread that stopped gets
these windows, so the stop reply does not grow with thread count.
`GetJSONThreadsInfo` now builds the `"memory"` array from both sources and
[4 lines not shown]