← index #8782Issue #8783
Related · high · value 0.253
QUERY · ISSUE

mpy_ld.py: "AttributeError: 'Symbol' object has no attribute 'section'" when relocating data section

openby phlashopened 2022-06-19updated 2022-06-19
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 · ISSUE

mpy_ld.py: Unable to emit relocations in more complex .rodata.* sections

closedby phlashopened 2022-06-19updated 2023-09-01
bug

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:

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied