Add support for static constructors and destructors
This commit is contained in:
parent
cba01fff5e
commit
b2df978eae
@ -29,6 +29,10 @@
|
|||||||
|
|
||||||
/* Symbols exported by the linker script(s): */
|
/* Symbols exported by the linker script(s): */
|
||||||
extern unsigned _data_loadaddr, _data, _edata, _ebss, _stack;
|
extern unsigned _data_loadaddr, _data, _edata, _ebss, _stack;
|
||||||
|
typedef void (*funcp_t) (void);
|
||||||
|
extern funcp_t __preinit_array_start, __preinit_array_end;
|
||||||
|
extern funcp_t __init_array_start, __init_array_end;
|
||||||
|
extern funcp_t __fini_array_start, __fini_array_end;
|
||||||
|
|
||||||
void main(void);
|
void main(void);
|
||||||
void blocking_handler(void);
|
void blocking_handler(void);
|
||||||
@ -55,6 +59,7 @@ vector_table_t vector_table = {
|
|||||||
void WEAK __attribute__ ((naked)) reset_handler(void)
|
void WEAK __attribute__ ((naked)) reset_handler(void)
|
||||||
{
|
{
|
||||||
volatile unsigned *src, *dest;
|
volatile unsigned *src, *dest;
|
||||||
|
funcp_t *fp;
|
||||||
|
|
||||||
for (src = &_data_loadaddr, dest = &_data; dest < &_edata; src++, dest++)
|
for (src = &_data_loadaddr, dest = &_data; dest < &_edata; src++, dest++)
|
||||||
*dest = *src;
|
*dest = *src;
|
||||||
@ -62,11 +67,21 @@ void WEAK __attribute__ ((naked)) reset_handler(void)
|
|||||||
while (dest < &_ebss)
|
while (dest < &_ebss)
|
||||||
*dest++ = 0;
|
*dest++ = 0;
|
||||||
|
|
||||||
|
/* Constructors. */
|
||||||
|
for (fp = &__preinit_array_start; fp < &__preinit_array_end; fp++)
|
||||||
|
(*fp)();
|
||||||
|
for (fp = &__init_array_start; fp < &__init_array_end; fp++)
|
||||||
|
(*fp)();
|
||||||
|
|
||||||
/* might be provided by platform specific vector.c */
|
/* might be provided by platform specific vector.c */
|
||||||
pre_main();
|
pre_main();
|
||||||
|
|
||||||
/* Call the application's entry point. */
|
/* Call the application's entry point. */
|
||||||
main();
|
main();
|
||||||
|
|
||||||
|
/* Destructors. */
|
||||||
|
for (fp = &__fini_array_start; fp < &__fini_array_end; fp++)
|
||||||
|
(*fp)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void blocking_handler(void)
|
void blocking_handler(void)
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -42,6 +42,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -43,6 +43,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
@ -38,6 +38,29 @@ SECTIONS
|
|||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
} >rom
|
} >rom
|
||||||
|
|
||||||
|
/* C++ Static constructors/destructors, also used for __attribute__
|
||||||
|
* ((constructor)) and the likes */
|
||||||
|
.preinit_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__preinit_array_start = .;
|
||||||
|
KEEP (*(.preinit_array))
|
||||||
|
__preinit_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.init_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__init_array_start = .;
|
||||||
|
KEEP (*(SORT(.init_array.*)))
|
||||||
|
KEEP (*(.init_array))
|
||||||
|
__init_array_end = .;
|
||||||
|
} >rom
|
||||||
|
.fini_array : {
|
||||||
|
. = ALIGN(4);
|
||||||
|
__fini_array_start = .;
|
||||||
|
KEEP (*(.fini_array))
|
||||||
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
|
__fini_array_end = .;
|
||||||
|
} >rom
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another section used by C++ stuff, appears when using newlib with
|
* Another section used by C++ stuff, appears when using newlib with
|
||||||
* 64bit (long long) printf support
|
* 64bit (long long) printf support
|
||||||
|
Loading…
x
Reference in New Issue
Block a user