Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
phlash opened this issue Jun 19, 2022 · 4 comments
Closed
Labels

Comments

@phlash
Copy link

phlash commented Jun 19, 2022

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:
@jonnor
Copy link
Contributor

jonnor commented Jul 30, 2023

I hit the same issue when working on https://github.com/emlearn/emlearn-micropython - which was some quite simple 100 line code. I did some other hack, but will try to test this fix.

jonnor added a commit to jonnor/micropython that referenced this issue Jul 30, 2023
Sometimes the sections are named .rodata.str1.1 etc, instead of just .rodata.
Avoid crashing in that case. Instead treat it like any other RO section.

Fix thanks to @phlash
Closes micropython#8783
@jonnor
Copy link
Contributor

jonnor commented Jul 30, 2023

This fix looks to work for me. I have created a merge request with your fix @phlash - hope you dont mind

jonnor added a commit to jonnor/micropython that referenced this issue Jul 30, 2023
Sometimes the sections are named .rodata.str1.1 etc, instead of just .rodata.
Avoid crashing in that case. Instead treat it like any other RO section.

Fix thanks to @phlash
Closes micropython#8783
jonnor added a commit to jonnor/micropython that referenced this issue Jul 30, 2023
Sections sometimes named .rodata.str1.1 etc, instead of just .rodata.
Avoid crashing in that case. Instead treat it like any other RO section.

Fix thanks to @phlash
Closes micropython#8783

Signed-off-by: Jon Nordby <jononor@gmail.com>
@phlash
Copy link
Author

phlash commented Jul 30, 2023

You're welcome, I didn't have a fork to commit to / issue a PR from, so thanks!

dpgeorge pushed a commit to jonnor/micropython that referenced this issue Sep 1, 2023
Sections sometimes named .rodata.str1.1 etc, instead of just .rodata.
Avoid crashing in that case.  Instead treat it like any other RO section.

Fix thanks to @phlash.

Fixes issue micropython#8783.

Signed-off-by: Jon Nordby <jononor@gmail.com>
@dpgeorge
Copy link
Member

dpgeorge commented Sep 1, 2023

Fixed by 4837ec3

@dpgeorge dpgeorge closed this as completed Sep 1, 2023
xuancong84 pushed a commit to xuancong84/micropython that referenced this issue Sep 12, 2023
Sections sometimes named .rodata.str1.1 etc, instead of just .rodata.
Avoid crashing in that case.  Instead treat it like any other RO section.

Fix thanks to @phlash.

Fixes issue micropython#8783.

Signed-off-by: Jon Nordby <jononor@gmail.com>
jprodriguez-nbs pushed a commit to jprodriguez-nbs/micropython that referenced this issue Sep 21, 2023
Sections sometimes named .rodata.str1.1 etc, instead of just .rodata.
Avoid crashing in that case.  Instead treat it like any other RO section.

Fix thanks to @phlash.

Fixes issue micropython#8783.

Signed-off-by: Jon Nordby <jononor@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants