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:
mpy_ld.py: Unable to emit relocations in more complex .rodata.* sections
While linking a large(ish) project with the latest micropython and ESP-IDF compiler, I had a failure during writing of relocations in build_mpy due to a section named .rodata.str1.1 which was not matched by the kind checking logic, resulting in an attempt to concatenate an int with a str. Given such sections are part of the general read-only data, I applied the following fix which seems to work:
@@ -965,7 +976,7 @@ def build_mpy(env, entry_offset, fmpy, native_qstr_vals, native_qstr_objs):
for base, addr, kind in env.mpy_relocs:
if isinstance(kind, str) and kind.startswith(".text"):
kind = 0
- elif kind in (".rodata", ".data.rel.ro"):
+ elif isinstance(kind, str) and (kind.startswith(".rodata") or kind.startswith(".data.rel.ro")):
if env.arch.separate_rodata:
kind = rodata_const_table_idx
else: