1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- Thanks to Joerg Strohmayer, the GCC library build now manages to

invoke the library's constructor/destructor functions in a
  very particular order. That way, you can use constructor/destructor
  functions in your own code and not have them clash with the library's
  own functions.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14871 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-03-09 21:07:25 +00:00
parent 4d3dc4a77f
commit e3e82b3657
5 changed files with 56 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
# #
# $Id: GNUmakefile.os4,v 1.38 2005-03-09 16:56:04 obarthel Exp $ # $Id: GNUmakefile.os4,v 1.39 2005-03-09 21:07:20 obarthel Exp $
# #
# :ts=8 # :ts=8
# #
@@ -113,7 +113,7 @@ WARNINGS = \
INCLUDES = -Iinclude -I. -I$(SDK_INCLUDE) INCLUDES = -Iinclude -I. -I$(SDK_INCLUDE)
OPTIONS = -D__THREAD_SAFE -DNDEBUG -DUSE_64_BIT_INTS -D__USE_INLINE__ -Wa,-mregnames OPTIONS = -D__THREAD_SAFE -DNDEBUG -DUSE_64_BIT_INTS -D__USE_INLINE__ -Wa,-mregnames
OPTIMIZE = -O -fomit-frame-pointer -funroll-loops OPTIMIZE = -O -fomit-frame-pointer -funroll-loops
DEBUG = -g2 #DEBUG = -g
CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(CODE_TYPE) $(INCLUDES) CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(CODE_TYPE) $(INCLUDES)

View File

@@ -40,6 +40,12 @@
- Moved a few __delete_semaphore() calls into conditional compilation - Moved a few __delete_semaphore() calls into conditional compilation
sections where they should have been in the first place. sections where they should have been in the first place.
- Thanks to Joerg Strohmayer, the GCC library build now manages to
invoke the library's constructor/destructor functions in a
very particular order. That way, you can use constructor/destructor
functions in your own code and not have them clash with the library's
own functions.
c.lib 1.189 (5.3.2005) c.lib 1.189 (5.3.2005)

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: crtbegin.c,v 1.4 2005-02-25 10:14:21 obarthel Exp $ * $Id: crtbegin.c,v 1.5 2005-03-09 21:07:25 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -25,22 +25,24 @@
* with a NULL pointer entry and is put at the end of the sections. This way, the init * with a NULL pointer entry and is put at the end of the sections. This way, the init
* code can find the global constructor/destructor pointers * code can find the global constructor/destructor pointers
*/ */
static void (*__CTOR_LIST__[1]) (void) __attribute__((section(".ctors"))) = { (void *)-1 }; static void (*__CTOR_LIST__[1]) (void) __attribute__(( used, section(".ctors"), aligned(sizeof(void (*)(void))) ));
static void (*__DTOR_LIST__[1]) (void) __attribute__((section(".dtors"))) = { (void *)-1 }; static void (*__DTOR_LIST__[1]) (void) __attribute__(( used, section(".dtors"), aligned(sizeof(void (*)(void))) ));
/****************************************************************************/ /****************************************************************************/
STATIC VOID STATIC VOID
_do_ctors(void) _do_ctors(void)
{ {
void (**pFuncPtr)(void); int num_ctors;
int i;
/* Skip the first entry in the list (it's -1 anyway) */ num_ctors = 0;
pFuncPtr = __CTOR_LIST__ + 1;
/* Call all constructors in forward order */ for(i = 1 ; __CTOR_LIST__[i] != NULL ; i++)
while (*pFuncPtr != NULL) num_ctors++;
(**pFuncPtr++)();
for(i = 0 ; i < num_ctors ; i++)
__CTOR_LIST__[num_ctors - i]();
} }
/****************************************************************************/ /****************************************************************************/
@@ -48,25 +50,16 @@ _do_ctors(void)
STATIC VOID STATIC VOID
_do_dtors(void) _do_dtors(void)
{ {
ULONG i = (ULONG)__DTOR_LIST__[0]; int num_dtors;
void (**pFuncPtr)(void); int i;
if (i == ~0UL) num_dtors = 0;
{
/* Find the end of the destructors list */
i = 1;
while (__DTOR_LIST__[i] != NULL) for(i = 1 ; __DTOR_LIST__[i] != NULL ; i++)
i++; num_dtors++;
/* We're at the NULL entry now. Go back by one */ for(i = 0 ; i < num_dtors ; i++)
i--; __DTOR_LIST__[i+1]();
}
/* Call all destructors in reverse order */
pFuncPtr = __DTOR_LIST__ + i;
while (i-- > 0)
(**pFuncPtr--)();
} }
/****************************************************************************/ /****************************************************************************/

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: crtend.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ * $Id: crtend.c,v 1.2 2005-03-09 21:07:25 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -10,9 +10,10 @@
/****************************************************************************/ /****************************************************************************/
static volatile void (*__CTOR_LIST__[1]) (void) __attribute__((used,section(".ctors"))) = { (void *)0 }; static void (*__CTOR_LIST__[1]) (void) __attribute__((used, section(".ctors"), aligned(sizeof(void (*)(void))) ));
static volatile void (*__DTOR_LIST__[1]) (void) __attribute__((used,section(".dtors"))) = { (void *)0 }; static void (*__DTOR_LIST__[1]) (void) __attribute__((used, section(".dtors"), aligned(sizeof(void (*)(void))) ));
/****************************************************************************/ /****************************************************************************/
#endif /*__amigaos4__ */ #endif /*__amigaos4__ */

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: macros.h,v 1.9 2005-02-25 10:14:21 obarthel Exp $ * $Id: macros.h,v 1.10 2005-03-09 21:07:25 obarthel Exp $
* *
* :ts=4 * :ts=4
* *
@@ -163,12 +163,31 @@
#endif /* __SASC */ #endif /* __SASC */
#ifdef __GNUC__ #ifdef __GNUC__
#define CLIB_CONSTRUCTOR(name) STATIC VOID __attribute__((constructor)) name##_ctor(void) #define CLIB_CONSTRUCTOR(name) \
#define CLIB_DESTRUCTOR(name) STATIC VOID __attribute__((destructor)) name##_dtor(void) STATIC VOID __attribute__((used)) name##_ctor(void); \
#define PROFILE_CONSTRUCTOR(name) STATIC VOID __attribute__((constructor)) name##_ctor(void) STATIC VOID (*__name##_ctor)(void) __attribute__((used,section(".ctors.00500"))) = name##_ctor; \
#define PROFILE_DESTRUCTOR(name) STATIC VOID __attribute__((destructor)) name##_dtor(void) STATIC VOID name##_ctor(void)
#define CONSTRUCTOR_SUCCEED() return
#define CONSTRUCTOR_FAIL() exit(RETURN_FAIL) /* ZZZ not a nice thing to do; fix the constructor invocation code! */ #define CLIB_DESTRUCTOR(name) \
STATIC VOID __attribute__((used)) name##_dtor(void); \
STATIC VOID (*__name##_dtor)(void) __attribute__((used,section(".dtors.00500"))) = name##_dtor; \
STATIC VOID name##_dtor(void)
#define PROFILE_CONSTRUCTOR(name) \
STATIC VOID __attribute__((used)) name##_ctor(void); \
STATIC VOID (*__name##_ctor)(void) __attribute__((used,section(".ctors.00150"))) = name##_ctor; \
STATIC VOID name##_ctor(void)
#define PROFILE_DESTRUCTOR(name) \
STATIC VOID __attribute__((used)) name##_dtor(void); \
STATIC VOID (*__name##_dtor)(void) __attribute__((used,section(".dtors.00150"))) = name##_dtor; \
STATIC VOID name##_ctor(void)
#define CONSTRUCTOR_SUCCEED() \
return
#define CONSTRUCTOR_FAIL() \
exit(RETURN_FAIL) /* ZZZ not a nice thing to do; fix the constructor invocation code! */
#endif /* __GNUC__ */ #endif /* __GNUC__ */
/****************************************************************************/ /****************************************************************************/