Skip to content

Commit e531f99

Browse files
author
Martin Klang
authored
changed init to allow static ctors to use heap (test!)
1 parent ae90066 commit e531f99

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Source/main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ extern "C" {
2626
}
2727

2828
int main(void){
29-
#ifdef STARTUP_CODE
29+
#ifdef STARTUP_CODE
3030
memcpy(_sidata, _sdata, _sdata-_edata); // Copy the data segment initializers
3131
memset(_sbss, 0, _ebss-_sbss); // zero fill the BSS segment
32-
__libc_init_array(); // Call static constructors
3332
#endif /* STARTUP_CODE */
3433

35-
/* Defined by the linker */
34+
/* Defined by the linker */
3635
extern char _fastheap, _fasteheap; // internal RAM dedicated to heap
3736
extern char _eprogram, _eram; // remaining program space
3837
extern char _heap, _eheap; // external memory
@@ -42,7 +41,11 @@ int main(void){
4241
{ ( uint8_t * )&_heap, (size_t)(&_eheap - &_heap) },
4342
{ NULL, 0 } /* Terminates the array. */
4443
};
45-
vPortDefineHeapRegions( xHeapRegions );
44+
vPortDefineHeapRegions( xHeapRegions ); // call before static initialisers to allow heap use
45+
46+
#ifdef STARTUP_CODE
47+
__libc_init_array(); // Call static constructors
48+
#endif /* STARTUP_CODE */
4649

4750
ProgramVector* pv = getProgramVector();
4851
if(pv->checksum >= PROGRAM_VECTOR_CHECKSUM_V12){

0 commit comments

Comments
 (0)