mpy_ld.py: "AttributeError: 'Symbol' object has no attribute 'section'" when relocating data section
While linking a larg(ish) project, with the latest micropython and ESP-IDF compiler, I had a failure in mpy_ld.py due to a relocation in a .data.rel.ro section that went via an unresolved (UND) symbol. The symbol was correctly resolved later on, however the logic in do_relocation_data does not take account of this fact, and fails when trying to de-reference the non-existant section attribute. Applying similar logic to that in do_relocation_text (see diff below) appears to fix this issue:
@@ -638,6 +639,9 @@ def do_relocation_data(env, text_addr, r):
or env.arch.name == "EM_XTENSA"
and r_info_type == R_XTENSA_32
):
+ # Bug fix: use resolved symbol if available (as per text relocs)
+ if hasattr(s, "resolved"):
+ s = s.resolved
# Relocation in data.rel.ro to internal/external symbol
if env.arch.word_size == 4:
tools/mpy_ld.py: support absolute relocations in text section on Thumb targets
Summary
Add support for R_ARM_ABS32 relocations in native .mpy files.
Also, enable float by default on armv6m and armv7m native mpy targets, since soft-float now works correctly.
Should fix issue #14430.
Testing
Tested with ARCH=armv6m on RPI_PICO_W, and ARCH=armv7emdp on PYBD_SF6. The update features2 -- calling sin() and cos() -- works on both these targets.
Trade-offs and Alternatives
This is a relatively minimal change, but nonetheless tools/mpy_ld.py is getting quite unwieldy now and pretty hard to follow what relocations are/aren't allowed. Maybe in the future it can be cleaned up, but we'd need more tests before doing that to ensure something doesn't break.