diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index 3fdcc9d0d79..e0332204309 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -42,11 +42,20 @@ KEEP(*(SORT_BY_NAME(._##struct_type.static.*))); \ _CONCAT(_##struct_type, _list_end) = . +#define Z_LINK_ITERABLE_GC_ALLOWED(struct_type) \ + _CONCAT(_##struct_type, _list_start) = .; \ + *(SORT_BY_NAME(._##struct_type.static.*)); \ + _CONCAT(_##struct_type, _list_end) = . + /* Define an output section which will set up an iterable area * of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE. * Input sections will be sorted by name, per ld's SORT_BY_NAME. * * This macro should be used for read-only data. + * + * Note that this keeps the symbols in the image even though + * they are not being directly referenced. Use this when symbols + * are indirectly referenced by iterating through the section. */ #define Z_ITERABLE_SECTION_ROM(struct_type, subalign) \ SECTION_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \ @@ -54,11 +63,29 @@ Z_LINK_ITERABLE(struct_type); \ } GROUP_LINK_IN(ROMABLE_REGION) +/* Define an output section which will set up an iterable area + * of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE. + * Input sections will be sorted by name, per ld's SORT_BY_NAME. + * + * This macro should be used for read-only data. + * + * Note that the symbols within the section can be garbage collected. + */ +#define Z_ITERABLE_SECTION_ROM_GC_ALLOWED(struct_type, subalign) \ + SECTION_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \ + { \ + Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \ + } GROUP_LINK_IN(ROMABLE_REGION) + /* Define an output section which will set up an iterable area * of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE. * Input sections will be sorted by name, per ld's SORT_BY_NAME. * * This macro should be used for read-write data that is modified at runtime. + * + * Note that this keeps the symbols in the image even though + * they are not being directly referenced. Use this when symbols + * are indirectly referenced by iterating through the section. */ #define Z_ITERABLE_SECTION_RAM(struct_type, subalign) \ SECTION_DATA_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \ @@ -66,6 +93,21 @@ Z_LINK_ITERABLE(struct_type); \ } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + +/* Define an output section which will set up an iterable area + * of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE. + * Input sections will be sorted by name, per ld's SORT_BY_NAME. + * + * This macro should be used for read-write data that is modified at runtime. + * + * Note that the symbols within the section can be garbage collected. + */ +#define Z_ITERABLE_SECTION_RAM_GC_ALLOWED(struct_type, subalign) \ + SECTION_DATA_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \ + { \ + Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \ + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + /* * generate a symbol to mark the start of the objects array for * the specified object and level, then link all of those objects