cpp: support for 64-bit constructors

Make constructors work in a 64-bit build.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2019-07-30 17:38:00 -04:00 committed by Andrew Boie
commit 2bdfede0f8
2 changed files with 11 additions and 2 deletions

View file

@ -17,17 +17,26 @@
{ {
/* /*
* The compiler fills the constructor pointers table below, * 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 * boundary. To align with the C++ standard, the first elment
* of the array contains the number of actual constructors. The * of the array contains the number of actual constructors. The
* last element is NULL. * 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); . = ALIGN(4);
__CTOR_LIST__ = .; __CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
KEEP(*(SORT_BY_NAME(".ctors*"))) KEEP(*(SORT_BY_NAME(".ctors*")))
LONG(0) LONG(0)
__CTOR_END__ = .; __CTOR_END__ = .;
#endif
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
SECTION_PROLOGUE(init_array,,) SECTION_PROLOGUE(init_array,,)

View file

@ -35,7 +35,7 @@ void __do_global_ctors_aux(void)
{ {
unsigned int nCtors; unsigned int nCtors;
nCtors = (unsigned int)__CTOR_LIST__[0]; nCtors = (unsigned long)__CTOR_LIST__[0];
while (nCtors >= 1U) { while (nCtors >= 1U) {
__CTOR_LIST__[nCtors--](); __CTOR_LIST__[nCtors--]();