aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2013-03-19 17:53:07 +0100
committerNicolas Schodet2013-03-19 18:08:28 +0100
commit5d3975ab89e623af16573345ec0d6d665612fd1b (patch)
tree63a5f98f20ecd08df6d66183c2aaad8ccc72dd13
parent48e654ea14d9f7c8c80ba2d089624277c10c604c (diff)
Add support for static constructors and destructorsinit-fini-2
-rw-r--r--lib/cm3/vector.c15
-rw-r--r--lib/efm32/efm32g/libopencm3_efm32g.ld23
-rw-r--r--lib/efm32/efm32gg/libopencm3_efm32gg.ld23
-rw-r--r--lib/efm32/efm32lg/libopencm3_efm32lg.ld23
-rw-r--r--lib/efm32/efm32tg/libopencm3_efm32tg.ld23
-rw-r--r--lib/lm3s/libopencm3_lm3s.ld23
-rw-r--r--lib/lpc13xx/libopencm3_lpc13xx.ld23
-rw-r--r--lib/lpc17xx/libopencm3_lpc17xx.ld23
-rw-r--r--lib/lpc43xx/libopencm3_lpc43xx.ld23
-rw-r--r--lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld23
-rw-r--r--lib/stm32/f1/libopencm3_stm32f1.ld23
-rw-r--r--lib/stm32/f2/libopencm3_stm32f2.ld23
-rw-r--r--lib/stm32/f4/libopencm3_stm32f4.ld23
-rw-r--r--lib/stm32/l1/libopencm3_stm32l1.ld23
14 files changed, 314 insertions, 0 deletions
diff --git a/lib/cm3/vector.c b/lib/cm3/vector.c
index 2706b6d..43e8917 100644
--- a/lib/cm3/vector.c
+++ b/lib/cm3/vector.c
@@ -29,6 +29,10 @@
/* Symbols exported by the linker script(s): */
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 blocking_handler(void);
@@ -55,6 +59,7 @@ vector_table_t vector_table = {
void WEAK __attribute__ ((naked)) reset_handler(void)
{
volatile unsigned *src, *dest;
+ funcp_t *fp;
for (src = &_data_loadaddr, dest = &_data; dest < &_edata; src++, dest++)
*dest = *src;
@@ -62,11 +67,21 @@ void WEAK __attribute__ ((naked)) reset_handler(void)
while (dest < &_ebss)
*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 */
pre_main();
/* Call the application's entry point. */
main();
+
+ /* Destructors. */
+ for (fp = &__fini_array_start; fp < &__fini_array_end; fp++)
+ (*fp)();
}
void blocking_handler(void)
diff --git a/lib/efm32/efm32g/libopencm3_efm32g.ld b/lib/efm32/efm32g/libopencm3_efm32g.ld
index b18da7f..87d6ee6 100644
--- a/lib/efm32/efm32g/libopencm3_efm32g.ld
+++ b/lib/efm32/efm32g/libopencm3_efm32g.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/efm32/efm32gg/libopencm3_efm32gg.ld b/lib/efm32/efm32gg/libopencm3_efm32gg.ld
index b18da7f..87d6ee6 100644
--- a/lib/efm32/efm32gg/libopencm3_efm32gg.ld
+++ b/lib/efm32/efm32gg/libopencm3_efm32gg.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/efm32/efm32lg/libopencm3_efm32lg.ld b/lib/efm32/efm32lg/libopencm3_efm32lg.ld
index b18da7f..87d6ee6 100644
--- a/lib/efm32/efm32lg/libopencm3_efm32lg.ld
+++ b/lib/efm32/efm32lg/libopencm3_efm32lg.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/efm32/efm32tg/libopencm3_efm32tg.ld b/lib/efm32/efm32tg/libopencm3_efm32tg.ld
index b18da7f..87d6ee6 100644
--- a/lib/efm32/efm32tg/libopencm3_efm32tg.ld
+++ b/lib/efm32/efm32tg/libopencm3_efm32tg.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/lm3s/libopencm3_lm3s.ld b/lib/lm3s/libopencm3_lm3s.ld
index ceb391a..6c8c7f2 100644
--- a/lib/lm3s/libopencm3_lm3s.ld
+++ b/lib/lm3s/libopencm3_lm3s.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/lpc13xx/libopencm3_lpc13xx.ld b/lib/lpc13xx/libopencm3_lpc13xx.ld
index 4e0f1df..bd0005c 100644
--- a/lib/lpc13xx/libopencm3_lpc13xx.ld
+++ b/lib/lpc13xx/libopencm3_lpc13xx.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/lpc17xx/libopencm3_lpc17xx.ld b/lib/lpc17xx/libopencm3_lpc17xx.ld
index 4e0f1df..bd0005c 100644
--- a/lib/lpc17xx/libopencm3_lpc17xx.ld
+++ b/lib/lpc17xx/libopencm3_lpc17xx.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/lpc43xx/libopencm3_lpc43xx.ld b/lib/lpc43xx/libopencm3_lpc43xx.ld
index 9402a54..5dad9ec 100644
--- a/lib/lpc43xx/libopencm3_lpc43xx.ld
+++ b/lib/lpc43xx/libopencm3_lpc43xx.ld
@@ -42,6 +42,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld b/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld
index 06f7708..39602b5 100644
--- a/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld
+++ b/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld
@@ -43,6 +43,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/stm32/f1/libopencm3_stm32f1.ld b/lib/stm32/f1/libopencm3_stm32f1.ld
index 9d165f6..3fc2ccb 100644
--- a/lib/stm32/f1/libopencm3_stm32f1.ld
+++ b/lib/stm32/f1/libopencm3_stm32f1.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/stm32/f2/libopencm3_stm32f2.ld b/lib/stm32/f2/libopencm3_stm32f2.ld
index 9d165f6..3fc2ccb 100644
--- a/lib/stm32/f2/libopencm3_stm32f2.ld
+++ b/lib/stm32/f2/libopencm3_stm32f2.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/stm32/f4/libopencm3_stm32f4.ld b/lib/stm32/f4/libopencm3_stm32f4.ld
index 9d165f6..3fc2ccb 100644
--- a/lib/stm32/f4/libopencm3_stm32f4.ld
+++ b/lib/stm32/f4/libopencm3_stm32f4.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support
diff --git a/lib/stm32/l1/libopencm3_stm32l1.ld b/lib/stm32/l1/libopencm3_stm32l1.ld
index 9d165f6..3fc2ccb 100644
--- a/lib/stm32/l1/libopencm3_stm32l1.ld
+++ b/lib/stm32/l1/libopencm3_stm32l1.ld
@@ -38,6 +38,29 @@ SECTIONS
. = ALIGN(4);
} >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
* 64bit (long long) printf support