Skip to content

Conversation

@jimmo
Copy link
Member

@jimmo jimmo commented Sep 17, 2022

This is an alternative to #9303.

The intent is to allow us to make breaking changes to the native ABI (e.g. changes to dynruntime.h) without needing the bytecode version to increment.

With this commit the two bits previously used for the feature flags (but now unused as of .mpy version 6) encode a sub-version. A bytecode-only .mpy file can be loaded as long as MPY_VERSION matches, but a native .mpy (i.e. one with an arch set) must also match MPY_SUB_VERSION. This allows 3 additional updates to the native ABI per bytecode revision.

This work was funded through GitHub Sponsors.

@dpgeorge
Copy link
Member

The merge_mpy function in tools/mpy-tool.py needs updating, something like this:

--- a/tools/mpy-tool.py
+++ b/tools/mpy-tool.py
@@ -1658,7 +1658,9 @@ def merge_mpy(compiled_modules, output_file):
     else:
         main_cm_idx = None
         for idx, cm in enumerate(compiled_modules):
-            if cm.header[2]:
+            feature_byte = cm.header[2]
+            mpy_native_arch = feature_byte >> 2
+            if mpy_native_arch:
                 # Must use qstr_table and obj_table from this raw_code
                 if main_cm_idx is not None:
                     raise Exception("can't merge files when more than one contains native code")

The intent is to allow us to make breaking changes to the native ABI
(e.g. changes to dynruntime.h) without needing the bytecode version to
increment.

With this commit the two bits previously used for the feature flags (but
now unused as of .mpy version 6) encode a sub-version. A bytecode-only .mpy
file can be loaded as long as MPY_VERSION matches, but a native .mpy
(i.e. one with an arch set) must also match MPY_SUB_VERSION. This allows 3
additional updates to the native ABI per bytecode revision.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
@jimmo
Copy link
Member Author

jimmo commented Sep 19, 2022

The merge_mpy function in tools/mpy-tool.py needs updating, something like this:

Thanks.

In a future PR we should make mpy-tool.py and mpy_ld.py use helpers to access these bytes (like persistentcode.c does).

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Sep 19, 2022
@dpgeorge
Copy link
Member

I've updated the tests and docs.

@dpgeorge
Copy link
Member

Merged in d94141e with changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants