QUERY · ISSUE
mpy_ld.py: "AttributeError: 'Symbol' object has no attribute 'section'" when relocating data section
bug
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:
CANDIDATE · PULL REQUEST
mpy_ld.py: Support complex RO sections
tools
Sometimes the sections are named .rodata.str1.1 etc, instead of just .rodata. Fix thanks to @phlash in #8783