Update LLVM from 18 to 22#4951
Draft
stertl wants to merge 2 commits into
Draft
Conversation
Contributor
|
@TianlongLiang Please feel free to jump in
|
656bb20 to
29b9b03
Compare
The RISC-V AOT relocation loader assumed that the R_RISCV_PCREL_LO12_I/S instruction always immediately follows its R_RISCV_PCREL_HI20 (AUIPC) at AUIPC+4. The HI20 handler patched both the AUIPC high 20 bits and the instruction at AUIPC+4, while the LO12 handler did nothing unless it sat exactly 4 bytes after the AUIPC (otherwise it took the unimplemented goto fail_addr_out_of_range path). This assumption holds for older toolchains but breaks with LLVM 22, whose instruction scheduler may place unrelated instructions between the AUIPC and its %pcrel_lo instruction (and may emit several %pcrel_lo accesses sharing a single AUIPC). The result was corrupted code: the HI20 handler clobbered the unrelated instruction at AUIPC+4, and the LO12 patch was skipped, leading to illegal-instruction faults or hangs at runtime (e.g. i32.ctz de Bruijn tables, switch/br_table jump tables, and any PC-relative rodata access). Pair the two relocations by address, the way a linker does: - Split R_RISCV_CALL/CALL_PLT (whose AUIPC+JALR pair really is adjacent) into its own case, leaving its AUIPC+4 patching unchanged. - R_RISCV_PCREL_HI20 now patches only the AUIPC high 20 bits and records the resolved PC-relative value keyed by the AUIPC address in a small thread-local most-recently-used cache. - R_RISCV_PCREL_LO12_I/S reconstructs the AUIPC address from symbol+addend, looks up the cached value, and patches its own instruction with the correct I-type (load/ADDI) or S-type (store) immediate. This works regardless of instruction placement and when multiple LO12 accesses share one AUIPC. The cache is thread-local so concurrent module loads do not interfere. Fixes the RISC-V64 AOT spec-test suite under QEMU/NuttX.
29b9b03 to
8793961
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Bumps the LLVM version from LLVM 18 (
llvmorg-18.1.8) to LLVM 22 (llvmorg-22.1.6). The ARC architecture target branch is updated accordingly fromrelease/18.xtorelease/22.x.Motivation
LLVM 22 delivers a significant AoT compilation speedup compared to LLVM 18. Compiling an example program (example.c.zip — a large C file with many global variables) to AOT shows:
wamrcversion~5× speedup — the updated compiler takes roughly one fifth of the time of the previous version for this workload.
Testing