diff --git a/include/linker/common-rom.ld b/include/linker/common-rom.ld index 6b28bc4f365..f96d328719c 100644 --- a/include/linker/common-rom.ld +++ b/include/linker/common-rom.ld @@ -17,17 +17,26 @@ { /* * The compiler fills the constructor pointers table below, - * hence symbol __CTOR_LIST__ must be aligned on 4 byte + * hence symbol __CTOR_LIST__ must be aligned on word * boundary. To align with the C++ standard, the first elment * of the array contains the number of actual constructors. The * last element is NULL. */ +#ifdef CONFIG_64BIT + . = ALIGN(8); + __CTOR_LIST__ = .; + QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2) + KEEP(*(SORT_BY_NAME(".ctors*"))) + QUAD(0) + __CTOR_END__ = .; +#else . = ALIGN(4); __CTOR_LIST__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) KEEP(*(SORT_BY_NAME(".ctors*"))) LONG(0) __CTOR_END__ = .; +#endif } GROUP_LINK_IN(ROMABLE_REGION) SECTION_PROLOGUE(init_array,,) diff --git a/subsys/cpp/cpp_ctors.c b/subsys/cpp/cpp_ctors.c index f0264850f6e..f91646282ac 100644 --- a/subsys/cpp/cpp_ctors.c +++ b/subsys/cpp/cpp_ctors.c @@ -35,7 +35,7 @@ void __do_global_ctors_aux(void) { unsigned int nCtors; - nCtors = (unsigned int)__CTOR_LIST__[0]; + nCtors = (unsigned long)__CTOR_LIST__[0]; while (nCtors >= 1U) { __CTOR_LIST__[nCtors--]();