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

"invalid relocation offset" when trying to execute AOT binary on ESP32-S3

Open SneezingCactus opened this issue 1 year ago • 2 comments

Hello, I've been using WAMR for my project and I recently decided to give AOT compilation a go. However, I can't seem to get any AOT binary to load and execute properly. It would always throw this error on wasm_runtime_load:

AOT module load failed: invalid relocation offset.

I also tried compiling with the wamrc --xip option enabled as I figured this would make it so that the instructions are executed directly from PSRAM without having to copy into IRAM (which is something I'd want anyways), however by doing this I'm met with a different wasm_runtime_load error:

AOT module load failed: cannot apply relocation to text section for aot file generated with "--enable-indirect-mode" flag

Looking into WAMR's source code and doing some extra logging, I found out that the binary's .rela.literal section was being determined to have a size of 0, causing check_reloc_offset to throw the invalid relocation offset error when relocating this section. This goes way out of my lane of knowledge however, so I don't think I can comment on this further.

I am using the 2.2.0 release of WAMR (though I also tried main branch with same results), AOT binaries are being compiled on Ubuntu 22.04 with LLVM 17.0.1 (Espressif fork), and the WASM host is an ESP32-S3 running on ESP-IDF v5.4.

Is there something I'm missing here? Any help would be very much appreciated.

SneezingCactus avatar Jan 15 '25 00:01 SneezingCactus

I'm facing a similar issue on a Coretx-M33. In my case, I'm AOT compiling the binary following the XIP recommendations. When I run wamrc I see that there were 56 relocations in the .rel.text section as follows:

 wamrc --target=thumbv4t --xip -o out.wasm demo_workload
Create AoT compiler with:
  target:        thumbv4t
  target cpu:
  target triple: thumbv4t-unknown-none-gnu
  cpu features:
  opt level:     3
  size level:    3
  output format: AoT file
[20:34:38:938 - 7F37E8AA4780]: 56 text relocations in .rel.text section for indirect mode
Compile success, file out.wasm was generated.

But this hits the comparison here and fails with the error above.

Even running wamrc with --enable-builtin-intrinsics=all fails.

srberard avatar Apr 09 '25 10:04 srberard

I managed to get my example working. Turns out my build script was selecting a thumbv4t as the ISA. Changing that to thumbv7 or thumbv8 fixed this problem. Likely due to the fact that the built-in intrinsics were not needed.

As for your issue, I believe the ESP32-S3 only has the xtensa target. Make sure you're specifying the appropriate ISA when doing the XIP compile. Also, check out how to tune the built in intrinsics (see here). When I got my working, I not longer saw the message about text relocations. Hopefully this helps you out.

srberard avatar Apr 09 '25 11:04 srberard