Xtensa --- dangerous relocation: windowed long call crosses 1GB boundary

1.8k views Asked by At

I got the following error during compilation

(.sram.text+0x1283): dangerous relocation: windowed longcall crosses 1GB boundary; return may fail: (UND+0xdeadcafe)

in one of the functions.

The architecture is Xtensa and the toolchain used is a GNU toolchain built for Xtensa. This error is inside the function elf_xtensa_do_reloc() in the file elf32-xtensa.c in binutils source code.

Please let me know the cause of this error and any possible solution.

2

There are 2 answers

0
Wellington On

After struggling with the same error when developing for ESP32 on PlatformIO, the solution I found was to change the optimatazion flags from -Os to -O3.

[env:esp32dev]
build_unflags = -Os
build_flags = -O3
0
LThode On

This is a known caveat of the default Xtensa windowed-register ABI. Quoting the Xtensa ISA reference manual:

The window increment stored with the return address register in a4 occupies the two most significant bits of the register, and therefore those bits must be filled in by the subroutine return. The RETW and RETW.N instructions fill in these bits from the two most significant bits of their own address. This prevents register-window calls from being used to call a routine in a different 1GB region of the address space.

You have two options to fix this:

  1. You can try adjusting the load base address for your code and/or make it smaller (!) until it fits within a 1GB region to fix it.
  2. If that doesn't work or isn't an option, you'll have to recompile everything running on your Xtensa system with a compiler that supports the alternative CALL0 ABI, which treats the register file as 'flat' and thus avoids the offending windowed call and return instructions.