[En-Nut-Discussion] Class constructor doesn't execute

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Mon Dec 5 14:59:23 CET 2016


>>>>> "Krzysztof" == Krzysztof Sawicki <krzysztof.sawicki at mlabs.pl> writes:

    Krzysztof> Hi, recently I tried some C++ with NutOS and realised that
    Krzysztof> class' constructors are not executed. I did some research and
    Krzysztof> realised that following code fixes this issue:

    Krzysztof> in linker script add: .preinit_array : { PROVIDE_HIDDEN
    Krzysztof> (__preinit_array_start = .); KEEP (*(.preinit_array*))
    Krzysztof> PROVIDE_HIDDEN (__preinit_array_end = .); } > FLASH0
   	
    Krzysztof>    	.init_array : { PROVIDE_HIDDEN (__init_array_start =
    Krzysztof> .); KEEP (*(SORT(.init_array.*))) KEEP (*(.init_array*))
    Krzysztof> PROVIDE_HIDDEN (__init_array_end = .); } > FLASH0
   	
    Krzysztof>    	.fini_array : { PROVIDE_HIDDEN (__fini_array_start =
    Krzysztof> .); KEEP (*(SORT(.fini_array.*))) KEEP (*(.fini_array*))
    Krzysztof> PROVIDE_HIDDEN (__fini_array_end = .); } > FLASH0

    Krzysztof> in main() at the beginning add: /* Call static constructors
    Krzysztof> */ asm("bl __libc_init_array");


    Krzysztof> and anywhere in the code:

    Krzysztof> 	extern "C" { void *__dso_handle = NULL; void _init(void){} }


Why does app/cppdemo build?

What of these prerequisites is Gnu specific, what is processor specific and
what is generic. I think anything generic can be added guarded with
#if defined(__cpluplus)

Any ideas?

Bye
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------


More information about the En-Nut-Discussion mailing list