Subject: Re: ctor/dtor bug in crtbegin.c
To: None <tech-toolchain@netbsd.org>
From: Krister Walfridsson <cato@df.lth.se>
List: tech-toolchain
Date: 10/08/2001 19:52:05
By popular demand, I'm resending the patch as a context diff.
As an additional data point, you can look at the elf versions of
__do_global_ctors_aux() and __do_global_dtors_aux() in
src/gnu/dist/toolchain/gcc/crtstuff.c
/Krister
Index: lib/csu/common_elf/crtbegin.c
===================================================================
RCS file: /cvsroot/basesrc/lib/csu/common_elf/crtbegin.c,v
retrieving revision 1.13
diff -c -r1.13 crtbegin.c
*** lib/csu/common_elf/crtbegin.c 2001/08/03 05:54:44 1.13
--- lib/csu/common_elf/crtbegin.c 2001/10/08 17:34:11
***************
*** 82,107 ****
static void
__ctors()
{
! void (**p)(void) = __CTOR_LIST__ + 1;
!
! while (*p)
! (**p++)();
! }
!
! static void
! __dtors()
! {
! unsigned long i = (unsigned long) __DTOR_LIST__[0];
void (**p)(void);
if (i == -1) {
! for (i = 1; __DTOR_LIST__[i] != NULL; i++)
;
i--;
}
! p = __DTOR_LIST__ + i;
while (i--)
(**p--)();
}
void
--- 82,107 ----
static void
__ctors()
{
! unsigned long i = (unsigned long) __CTOR_LIST__[0];
void (**p)(void);
if (i == -1) {
! for (i = 1; __CTOR_LIST__[i] != NULL; i++)
;
i--;
}
! p = __CTOR_LIST__ + i;
while (i--)
(**p--)();
+ }
+
+ static void
+ __dtors()
+ {
+ void (**p)(void) = __DTOR_LIST__ + 1;
+
+ while (*p)
+ (**p++)();
}
void