diff options
author | Damien George <damien@micropython.org> | 2022-05-26 10:51:29 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-06-07 13:19:55 +1000 |
commit | b37b57821476d9ea80cdcc89d325dcabded3ffb7 (patch) | |
tree | 8be44de48aeb5b1be95a163d2bd9e20289c75c9e /py | |
parent | 2111ca0b8fdcbef6177a8d37fde53085de2a798a (diff) |
py/persistentcode: Remove remaining native qstr linking support.
Support for architecture-specific qstr linking was removed in
d4d53e9e114d779523e382c4ea38f0398e880aae, where native code was changed to
access qstr values via qstr_table. The only remaining use for the special
qstr link table in persistentcode.c is to support native module written in
C, linked via mpy_ld.py. But native modules can also use the standard
module-level qstr_table (and obj_table) which was introduced in the .mpy
file reworking in f2040bfc7ee033e48acef9f289790f3b4e6b74e5.
This commit removes the remaining native qstr liking support in
persistentcode.c's load_raw_code function, and adds two new relocation
options for constants.qstr_table and constants.obj_table. mpy_ld.py is
updated to use these relocations options instead of the native qstr link
table.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py')
-rw-r--r-- | py/persistentcode.c | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/py/persistentcode.c b/py/persistentcode.c index d19a817aa..6304d1ff0 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -71,6 +71,7 @@ STATIC size_t read_uint(mp_reader_t *reader); typedef struct _reloc_info_t { mp_reader_t *reader; + mp_module_context_t *context; uint8_t *rodata; uint8_t *bss; } reloc_info_t; @@ -112,11 +113,17 @@ void mp_native_relocate(void *ri_in, uint8_t *text, uintptr_t reloc_text) { dest = (uintptr_t)ri->bss; } } else if (op == 6) { + // Destination is qstr_table + dest = (uintptr_t)ri->context->constants.qstr_table; + } else if (op == 7) { + // Destination is obj_table + dest = (uintptr_t)ri->context->constants.obj_table; + } else if (op == 8) { // Destination is mp_fun_table itself dest = (uintptr_t)&mp_fun_table; } else { // Destination is an entry in mp_fun_table - dest = ((uintptr_t *)&mp_fun_table)[op - 7]; + dest = ((uintptr_t *)&mp_fun_table)[op - 9]; } while (n--) { *addr_to_adjust++ += dest; @@ -205,7 +212,7 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) { } } -STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) { +STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *context) { // Load function kind and data length size_t kind_len = read_uint(reader); int kind = (kind_len & 3) + MP_CODE_BYTECODE; @@ -239,24 +246,6 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) { MP_PLAT_ALLOC_EXEC(fun_data_len, (void **)&fun_data, &fun_alloc); read_bytes(reader, fun_data, fun_data_len); - if (kind == MP_CODE_NATIVE_PY || kind == MP_CODE_NATIVE_VIPER) { - // Parse qstr link table and link native code - size_t n_qstr_link = read_uint(reader); - for (size_t i = 0; i < n_qstr_link; ++i) { - size_t off = read_uint(reader); - qstr qst = load_qstr(reader); - uint8_t *dest = fun_data + (off >> 2); - if ((off & 3) == 0) { - // Generic 16-bit link - dest[0] = qst & 0xff; - dest[1] = (qst >> 8) & 0xff; - } else if ((off & 3) == 3) { - // Generic, aligned qstr-object link - *(mp_obj_t *)dest = MP_OBJ_NEW_QSTR(qst); - } - } - } - if (kind == MP_CODE_NATIVE_PY) { // Read prelude offset within fun_data, and extract scope flags. prelude_offset = read_uint(reader); @@ -315,7 +304,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) { n_children = read_uint(reader); children = m_new(mp_raw_code_t *, n_children + (kind == MP_CODE_NATIVE_PY)); for (size_t i = 0; i < n_children; ++i) { - children[i] = load_raw_code(reader); + children[i] = load_raw_code(reader, context); } } @@ -349,7 +338,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) { #endif // Relocate and commit code to executable address space - reloc_info_t ri = {reader, rodata, bss}; + reloc_info_t ri = {reader, context, rodata, bss}; #if defined(MP_PLAT_COMMIT_EXEC) void *opt_ri = (native_scope_flags & MP_SCOPE_FLAG_VIPERRELOC) ? &ri : NULL; fun_data = MP_PLAT_COMMIT_EXEC(fun_data, fun_data_len, opt_ri); @@ -429,7 +418,7 @@ mp_compiled_module_t mp_raw_code_load(mp_reader_t *reader, mp_module_context_t * // Load top-level module. mp_compiled_module_t cm2; - cm2.rc = load_raw_code(reader); + cm2.rc = load_raw_code(reader, context); cm2.context = context; #if MICROPY_PERSISTENT_CODE_SAVE @@ -567,11 +556,6 @@ STATIC void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { mp_print_bytes(print, rc->fun_data, rc->fun_data_len); #if MICROPY_EMIT_MACHINE_CODE - if (rc->kind == MP_CODE_NATIVE_PY || rc->kind == MP_CODE_NATIVE_VIPER) { - // Save qstr link table for native code - mp_print_uint(print, 0); - } - if (rc->kind == MP_CODE_NATIVE_PY) { // Save prelude size mp_print_uint(print, rc->prelude_offset); |