Changed our nice crt0.c to something more GCC compatible; we're not calling

the global constructors/desctructors ourselves anymore, but let GCC do
that using crtbegin/end.o how it's thought to be done.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10946 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-01-22 13:36:31 +00:00
parent 34a71f30fe
commit 5af708a20c
7 changed files with 79 additions and 72 deletions

View File

@ -1,8 +1,8 @@
SubDir OBOS_TOP src kernel glue ;
KernelObjects
crt0.c
init_term_dyn.c
start_dyn.c
;
SubInclude OBOS_TOP src kernel glue arch ;

View File

@ -0,0 +1 @@
SubInclude OBOS_TOP src kernel glue arch $(OBOS_ARCH) ;

View File

@ -0,0 +1,7 @@
SubDir OBOS_TOP src kernel glue arch x86 ;
KernelObjects
crti.S
crtn.S
;

View File

@ -0,0 +1,38 @@
/*
* Copyright 2005, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
/** This file contains the first part of the ".init" and ".fini" sections in
* the ELF executable.
* The functions defined here will be called during initialization/termination
* of the loaded executable/library. The ".init" and ".fini" sections are
* stacked together like this:
*
* crti.S entry point
* call to _init_before/_term_before
* crtbegin.S GCC specific: constructors/destructors are called, ...
* crtend.S
* crtn.S call to _init_after/_term_after
* exit
*/
#define FUNCTION(x) .global x; .type x,@function; x
.section .init
FUNCTION(_init):
pushl %ebp
movl %esp, %ebp
pushl 0xc(%ebp) // program args
pushl 0x8(%ebp) // image ID
call _init_before
// crtbegin.o stuff comes here
.section .fini
FUNCTION(_fini):
pushl %ebp
movl %esp, %ebp
pushl 0xc(%ebp) // program args
pushl 0x8(%ebp) // image ID
call _term_before
// crtbegin.o stuff comes here

View File

@ -0,0 +1,23 @@
/*
* Copyright 2005, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
/** This file contains the final part of the ".init" and ".fini" sections in
* the ELF executable. It is tightly connected to crti.S.
* Have a look at crti.S to find a description of what happens here.
*/
.section .init
// the image ID and program args are still on the stack
call _init_after
movl %ebp, %esp
popl %ebp
ret
.section .fini
// the image ID and program args are still on the stack
call _term_after
movl %ebp, %esp
popl %ebp
ret

View File

@ -1,62 +0,0 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include "init_term_dyn.h"
void _init(int id, void *args) __attribute__((section(".init")));
void _fini(int id, void *args) __attribute__((section(".fini")));
// constructor/destructor lists as defined in the ld-script
extern void (*__ctor_list)(void);
extern void (*__ctor_end)(void);
extern void (*__dtor_list)(void);
extern void (*__dtor_end)(void);
static void
_call_ctors(void)
{
void (**f)(void);
for (f = &__ctor_list; f < &__ctor_end; f++) {
(**f)();
}
}
static void
_call_dtors(void)
{
void (**f)(void);
for (f = &__dtor_list; f < &__dtor_end; f++) {
(**f)();
}
}
void
_init(int id, void *args)
{
_init_before(id, args);
_call_ctors();
_init_after(id, args);
}
void
_fini(int id, void *args)
{
_term_before(id, args);
_call_dtors();
_term_after(id, args);
}

View File

@ -1,7 +1,7 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
/*
* Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <user_runtime.h>
@ -10,11 +10,11 @@
#include "init_term_dyn.h"
/* These functions are called from _init()/_fini() (in crti.S, crtn.S)
* _init/fini_before() is called before crtbegin/end code is executed,
* _init/fini_after() after this.
* crtbegin contains code to initialize all global constructors and
* probably other GCC related things.
/** These functions are called from _init()/_fini() (in crti.S, crtn.S)
* _init/_term_before() is called before crtbegin/end code is executed,
* _init/_term_after() after this.
* crtbegin contains code to initialize all global constructors and
* other GCC related things (like exception frames).
*/