wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

build-scripts/build_llvm.py: bump to llvm 19

Open yamt opened this issue 8 months ago • 17 comments

cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4210

why 19, not 20? because, as of writing this, 19 is the latest released version for the xtensa fork of llvm: https://github.com/espressif/llvm-project while we can use different versions for different targets, it's nicer to use the same version everywhere when possible.

yamt avatar Apr 25 '25 01:04 yamt

wamrc --target=riscv32 --target-abi=ilp32 --cpu=generic-rv32 --cpu-features=+m,+a,+c --xip --bounds-checks=0 generates a few text relocations with llvm16 and later for the following module:

(module
  (func (export "foo") (result i32)
    i32.const 13
    i32.ctz
  )
)

with llvm16:

        .text
        .attribute      4, 16
        .attribute      5, "rv32i2p0"
        .file   "WASM Module"
        .section        .rodata.cst32,"aM",@progbits,32
.LCPI0_0:                               # -- Begin function aot_func#0
        .ascii  "\000\001\034\002\035\016\030\003\036\026\024\017\031\021\004\b\037\033\r\027\025\023\020\007\032\f\022\006\013\005\n\t"
        .text
        .globl  "aot_func#0"
        .p2align        2
        .type   "aot_func#0",@function
"aot_func#0":                           # @"aot_func#0"
# %bb.0:                                # %func_end
        addi    sp, sp, -16
        sw      ra, 12(sp)                      # 4-byte Folded Spill
        lw      a0, 32(a0)
        lw      a0, 0(a0)
        beqz    a0, .LBB0_2
# %bb.1:                                # %cond.false
        neg     a1, a0
        and     a0, a0, a1
        lui     a1, 30667
        addi    a1, a1, 1329
        call    __mulsi3@plt
        srli    a0, a0, 27
        lui     a1, %hi(.LCPI0_0)
        addi    a1, a1, %lo(.LCPI0_0)
        add     a0, a1, a0
        lbu     a0, 0(a0)
        j       .LBB0_3
.LBB0_2:                                # %cond.end
        li      a0, 32
.LBB0_3:                                # %cond.end
        lw      ra, 12(sp)                      # 4-byte Folded Reload
        addi    sp, sp, 16
        ret
.Lfunc_end0:
        .size   "aot_func#0", .Lfunc_end0-"aot_func#0"
                                        # -- End function
        .section        ".note.GNU-stack","",@progbits

with llvm15:

	.text
	.attribute	4, 16
	.attribute	5, "rv32i2p0"
	.file	"WASM Module"
	.globl	"aot_func#0"                    # -- Begin function aot_func#0
	.p2align	2
	.type	"aot_func#0",@function
"aot_func#0":                           # @"aot_func#0"
# %bb.0:                                # %func_end
	addi	sp, sp, -16
	sw	ra, 12(sp)                      # 4-byte Folded Spill
	lw	a0, 32(a0)
	lw	a0, 0(a0)
	beqz	a0, .LBB0_2
# %bb.1:                                # %cond.false
	addi	a1, a0, -1
	not	a0, a0
	and	a0, a0, a1
	srli	a1, a0, 1
	lui	a2, 349525
	addi	a2, a2, 1365
	and	a1, a1, a2
	sub	a0, a0, a1
	lui	a1, 209715
	addi	a1, a1, 819
	and	a2, a0, a1
	srli	a0, a0, 2
	and	a0, a0, a1
	add	a0, a2, a0
	srli	a1, a0, 4
	add	a0, a0, a1
	lui	a1, 61681
	addi	a1, a1, -241
	and	a0, a0, a1
	lui	a1, 4112
	addi	a1, a1, 257
	call	__mulsi3@plt
	srli	a0, a0, 24
	j	.LBB0_3
.LBB0_2:                                # %cond.end
	li	a0, 32
.LBB0_3:                                # %cond.end
	lw	ra, 12(sp)                      # 4-byte Folded Reload
	addi	sp, sp, 16
	ret
.Lfunc_end0:
	.size	"aot_func#0", .Lfunc_end0-"aot_func#0"
                                        # -- End function
	.section	".note.GNU-stack","",@progbits

yamt avatar May 01 '25 08:05 yamt

wamrc --target=riscv32 --target-abi=ilp32 --cpu=generic-rv32 --cpu-features=+m,+a,+c --xip --bounds-checks=0 generates a few text relocations with llvm16 and later for the following module:

because of https://reviews.llvm.org/D128911

yamt avatar May 01 '25 09:05 yamt

for some reasons, it seems a few tests using llvm-jit are timed out on the ci. (ubuntu) i couldn't reproduce them on macOS.

yamt avatar May 02 '25 09:05 yamt

for some reasons, it seems a few tests using llvm-jit are timed out on the ci. (ubuntu) i couldn't reproduce them on macOS.

where it stalls doesn't seem consistent.

it used to be in Test_callback_chain, Test_memory. https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/14696495796/job/41264236395

but now it's in Test_global, Test_hostref, Test_memory. https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/14870500344/job/41757793101?pr=4213

yamt avatar May 06 '25 23:05 yamt

I use this patch test pass --invoke-c-api-import --enable-tail-call --format=aot --target=x86_64-pc-linux-gnu --enable-segue for linux.

For windows, get this error with --invoke-c-api-import --enable-tail-call --format=aot --target=x86_64-w64-windows-gnu: (x86_64-pc-windows-msvc has same result)

[06:27:37:277 - 7FF7666DA940]: Warning: loader mmap memory address is not in the first 2 Gigabytes of the process address space.
[06:27:37:282 - 7FF7666DA940]: Warning: loader mmap memory address is not in the first 2 Gigabytes of the process address space.
[06:27:37:287 - 7FF7666DA940]: Warning: loader mmap memory address is not in the first 2 Gigabytes of the process address space.
[06:27:37:291 - 7FF7666DA940]: the buffer is not ELF entry!                                                                     
[06:27:37:293 - 7FF7666DA940]: Warning: loader mmap memory address is not in the first 2 Gigabytes of the process address space.
[06:27:37:298 - 7FF7666DA940]: wamr\core\iwasm\common\wasm_runtime_common.c, line 1498, WASM module load failed                                        
[06:27:37:301 - 7FF7666DA940]: AOT module load failed: relocation truncated to fit IMAGE_REL_AMD64_ADDR32 failed. Try using wamrc with --size-level=1 option.
[06:27:37:306 - 7FF7666DA940]: wasm_module_new_ex failed          

change -size-level=1 not fix the problem, -size-level=0 get crash.

for darwin --invoke-c-api-import --enable-tail-call --format=aot --target=x86_64-apple-darwin --enable-segue:

[00:16:33:841 - 7FF84AE43BC0]: the buffer is not ELF entry!
[00:16:33:843 - 7FF84AE43BC0]: wamr/core/iwasm/common/wasm_runtime_common.c, line 1498, WASM module load failed
[00:16:33:843 - 7FF84AE43BC0]: AOT module load failed: relocation truncated to fit R_X86_64_32S failed. Try using wamrc with --size-level=1 or 0 option.
[00:16:33:843 - 7FF84AE43BC0]: wasm_module_new_ex failed

for a simple fib number without wasi, all 3 platform work ok.

fresh build from https://github.com/bytecodealliance/wasm-micro-runtime/commit/0e8b57d8a8af644cc44bc3f0f44ed78d409c834c

calvin2021y avatar May 07 '25 06:05 calvin2021y

@calvin2021y i'm not sure what you are trying with this PR. can you give me a context?

yamt avatar May 07 '25 06:05 yamt

I am build this PR with llvm19, and try run AOT app for linux/apple/windows platform.

calvin2021y avatar May 07 '25 06:05 calvin2021y

I am build this PR with llvm19, and try run AOT app for linux/apple/windows platform.

why? are you trying to find out regressions?

yamt avatar May 07 '25 06:05 yamt

I am not try find out regressions, this is my first time to try this combination.

calvin2021y avatar May 07 '25 07:05 calvin2021y

for some reasons, it seems a few tests using llvm-jit are timed out on the ci. (ubuntu) i couldn't reproduce them on macOS.

where it stalls doesn't seem consistent.

it used to be in Test_callback_chain, Test_memory. https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/14696495796/job/41264236395

but now it's in Test_global, Test_hostref, Test_memory. https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/14870500344/job/41757793101?pr=4213

it seems the stall was due to an unrelated bug. (a proposed fix: https://github.com/bytecodealliance/wasm-micro-runtime/pull/4252)

i don't know how llvm-19 exposed the issue though. maybe heap activities in a bad timing?

yamt avatar May 07 '25 09:05 yamt

i feel https://github.com/espressif/llvm-project/issues/112 is a show blocker. what do you think?

yamt avatar May 07 '25 10:05 yamt

use --invoke-c-api-import --enable-tail-call --format=aot --target=x86_64-pc-linux-gnu --opt-level=1 --size-level=0 work for apple x64 aot.

use --invoke-c-api-import --enable-tail-call --format=aot --target=aarch64v8.5-unknown-linux-android for apple arm64 aot.

windows still get Segmentation fault for --size-level=0, use --size-level=1 get this:

AOT module load failed: relocation truncated to fit IMAGE_REL_AMD64_ADDR32 failed. Try using wamrc with --size-level=1 option.

calvin2021y avatar May 07 '25 13:05 calvin2021y

after patch with https://github.com/bytecodealliance/wasm-micro-runtime/pull/4092, windows --size-level=0 not Segmentation fault at start but after finish run.

--size-level=1 still get AOT module load failed: relocation truncated to fit IMAGE_REL_AMD64_ADDR32 failed. Try using wamrc with --size-level=1 option. error like apple x64.

calvin2021y avatar May 07 '25 18:05 calvin2021y

i feel espressif/llvm-project#112 is a show blocker. what do you think?

for now i gave up and submit an alternative with llvm 18: https://github.com/bytecodealliance/wasm-micro-runtime/pull/4259

yamt avatar May 08 '25 08:05 yamt

Should we close it or leave it open?

lum1n0us avatar May 12 '25 02:05 lum1n0us

Should we close it or leave it open?

leave it for a whlie. let's see how long https://github.com/espressif/llvm-project/issues/112 takes.

yamt avatar May 12 '25 02:05 yamt

why 19, not 20? because, as of writing this, 19 is the latest released version for the xtensa fork of llvm: https://github.com/espressif/llvm-project while we can use different versions for different targets, it's nicer to use the same version everywhere when possible.

the espressif fork of llvm is now swiching their dev branch to llvm 20. hopefully we can use it for the next attempt.

yamt avatar Jul 11 '25 04:07 yamt