diff options
author | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-09-19 23:01:43 +0000 |
---|---|---|
committer | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-09-19 23:01:43 +0000 |
commit | 5c61dffde4155ade15ba96592de9c109114853ed (patch) | |
tree | f05aac60973502a95d5f948b92f108c0ec5d7dde /gcc/crtstuff.c | |
parent | f9b635ed4a8644a0514541caa771452455e933ad (diff) | |
download | gcc-5c61dffde4155ade15ba96592de9c109114853ed.tar.gz |
* configure.in: Disable collect2 for nextstep. Instead use
crtbegin/crtend.
* configure: Rebuilt.
* config/nextstep.h (STARTFILE_SPEC): Add crtbegin.
(ENDFILE_SPEC): Define.
(OBJECT_FORMAT_MACHO): Define.
(EH_FRAME_SECTION_ASM_OP): Define.
* crtstuff.c: Handle MACHO.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@22487 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/crtstuff.c')
-rw-r--r-- | gcc/crtstuff.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c index 8e50ac740d7..ce2c9561e64 100644 --- a/gcc/crtstuff.c +++ b/gcc/crtstuff.c @@ -56,6 +56,8 @@ Boston, MA 02111-1307, USA. */ #include <stddef.h> #include "frame.h" +#ifndef OBJECT_FORMAT_MACHO + /* Provide default definitions for the pseudo-ops used to switch to the .ctors and .dtors sections. @@ -458,3 +460,71 @@ STATIC ui32 __FRAME_END__[] __attribute__ ((__unused__)) = { 0 }; #endif /* EH_FRAME_SECTION */ #endif /* defined(CRT_END) */ + +#else /* OBJECT_FORMAT_MACHO */ + +/* For Mach-O format executables, we assume that the system's runtime is + smart enough to handle constructors and destructors, but doesn't have + an init section (if it can't even handle constructors/destructors + you should be using INVOKE__main, not crtstuff). All we need to do + is install/deinstall the frame information for exceptions. We do this + by putting a constructor in crtbegin.o and a destructor in crtend.o. + + crtend.o also puts in the terminating zero in the frame information + segment. */ + +/* The crtstuff for other object formats use the symbol __EH_FRAME_BEGIN__ + to figure out the start of the exception frame, but here we use + getsectbynamefromheader to find this value. Either method would work, + but this method avoids creating any global symbols, which seems + cleaner. */ + +#include <mach-o/ldsyms.h> +extern const struct section * + getsectbynamefromheader (const struct mach_header *, + const char *, const char *); + +#ifdef CRT_BEGIN + +static void __reg_frame_ctor () __attribute__ ((constructor)); + +static void +__reg_frame_ctor () +{ + static struct object object; + const struct section *eh_frame; + + eh_frame = getsectbynamefromheader (&_mh_execute_header, + "__TEXT", "__eh_frame"); + __register_frame_info ((void *) eh_frame->addr, &object); +} + +#endif /* CRT_BEGIN */ + +#ifdef CRT_END + +static void __dereg_frame_dtor () __attribute__ ((destructor)); + +static +void __dereg_frame_dtor () +{ + const struct section *eh_frame; + + eh_frame = getsectbynamefromheader (&_mh_execute_header, + "__TEXT", "__eh_frame"); + __deregister_frame_info ((void *) eh_frame->addr); +} + +/* Terminate the frame section with a final zero. */ + +/* Force cc1 to switch to .data section. */ +static void * force_to_data[0] __attribute__ ((__unused__)) = { }; + +typedef unsigned int ui32 __attribute__ ((mode (SI))); +asm (EH_FRAME_SECTION_ASM_OP); +static ui32 __FRAME_END__[] __attribute__ ((__unused__)) = { 0 }; + +#endif /* CRT_END */ + +#endif /* OBJECT_FORMAT_MACHO */ + |