Skip to content

Should the C++ constructor and destructor tables move into FLASH? #8731

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

Closed
metarutaiga opened this issue Nov 26, 2022 · 4 comments · Fixed by #8737
Closed

Should the C++ constructor and destructor tables move into FLASH? #8731

metarutaiga opened this issue Nov 26, 2022 · 4 comments · Fixed by #8737

Comments

@metarutaiga
Copy link
Contributor

metarutaiga commented Nov 26, 2022

. = (. + 3) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
__init_array_start = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__init_array_end = ABSOLUTE(.);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))

and

. = ALIGN(4); /* this table MUST be 4-byte aligned */
_bss_table_start = ABSOLUTE(.);
LONG(_bss_start)
LONG(_bss_end)
_bss_table_end = ABSOLUTE(.);

These are all 32bit pointers.
It should move into flash to reduce memory usage.

I change it in my repo.
metarutaiga@3bc7ce4

@mcspr
Copy link
Collaborator

mcspr commented Nov 26, 2022

We could just copy-paste those .{c,d}tor entries from the vtables .h .rodata into the .irom0 one? No relation to vtables, just move those to flash at all times

@earlephilhower
Copy link
Collaborator

IIRC they're in RAM now because of IRQ safety. If any classes are used in IRQ handlers, you can't be sure the flash is accessible so risk crashes. There was a bug I can't find opened about this after the original memory map shuffling...

@mcspr
Copy link
Collaborator

mcspr commented Nov 26, 2022

Arent dtors & ctors (and the whole init array) are supposed to be used for global objects? IRQ code will inject ctor / dtor call when needed, where the actual section can be changed with the IRAM attr

@earlephilhower
Copy link
Collaborator

Good catch, that sounds right.

The __init_array_start/end are only used in the CRT initialization (now handled by us in main.cpp)

static void do_global_ctors(void) {
static struct object ob;
__register_frame_info( __eh_frame, &ob );
void (**p)(void) = &__init_array_end;
while (p != &__init_array_start)
(*--p)();
}

BSS start/end, I think is used by the ROM code to do the bzero but I can't find where we stuff it for the ROM to find right this morning.

I'd say move it at this point. We're not saving all that much space at this point, but every byte counts...

@d-a-v d-a-v added the alpha included in alpha release label Dec 16, 2022
@d-a-v d-a-v added this to the 3.1 milestone Dec 16, 2022
@d-a-v d-a-v removed the alpha included in alpha release label Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants