From: Jason Merrill Date: Thu, 20 Nov 1997 23:21:26 +0000 (+0000) Subject: Makefile.in (LIB2FUNCS): Remove C++ memory management support. X-Git-Tag: releases/egcs-1.0.0~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=988cf86b46322d9cfaf4b8940ea3397247894496;p=thirdparty%2Fgcc.git Makefile.in (LIB2FUNCS): Remove C++ memory management support. ./: * Makefile.in (LIB2FUNCS): Remove C++ memory management support. * libgcc2.c: Remove __builtin_new, __builtin_vec_new, set_new_handler, __builtin_delete, and __builtin_vec_delete. * except.c (output_exception_table): Don't bother with __EXCEPTION_END__. cp/: * Make-lang.in (CXX_LIB2FUNCS): Add new op new and op delete objs. (various.o): Likewise. * inc/new: Add placement deletes. Add throw specs for default new. * new.cc (set_new_handler): Move here from libgcc2. * new1.cc (new (nothrow)): Catch a bad_alloc thrown from the handler. (new): Move from libgcc2. Throw bad_alloc. * new2.cc: Move the rest of the op news and op deletes from libgcc2. * decl.c (init_decl_processing): Update exception specs on new and delete. From-SVN: r16619 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0d87bcfa161a..dc54a6c8e240 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +Thu Nov 20 14:42:15 1997 Jason Merrill + + * Makefile.in (LIB2FUNCS): Remove C++ memory management support. + * libgcc2.c: Remove __builtin_new, __builtin_vec_new, set_new_handler, + __builtin_delete, and __builtin_vec_delete. + + * except.c (output_exception_table): Don't bother with + __EXCEPTION_END__. + Thu Nov 20 16:11:50 1997 Jeffrey A Law (law@cygnus.com) * pa.md (pre_stwm, post_stwm, pre_ldwm, post_ldwm): Base register diff --git a/gcc/Makefile.in b/gcc/Makefile.in index b02f0c6ec076..3779ae2e6362 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -631,8 +631,8 @@ LIB2FUNCS = _muldi3 _divdi3 _moddi3 _udivdi3 _umoddi3 _negdi2 \ _fixunsdfsi _fixunssfsi _fixunsdfdi _fixdfdi _fixunssfdi _fixsfdi \ _fixxfdi _fixunsxfdi _floatdixf _fixunsxfsi \ _fixtfdi _fixunstfdi _floatditf \ - __gcc_bcmp _varargs __dummy _eprintf _op_new _op_vnew _new_handler \ - _op_delete _op_vdel _bb _shtab _clear_cache _trampoline __main _exit \ + __gcc_bcmp _varargs __dummy _eprintf \ + _bb _shtab _clear_cache _trampoline __main _exit \ _ctors _eh _pure # The files that "belong" in CONFIG_H are deliberately omitted diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 99f18d1f8777..74d70fbbcd76 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,15 @@ Thu Nov 20 14:40:17 1997 Jason Merrill + * Make-lang.in (CXX_LIB2FUNCS): Add new op new and op delete objs. + (various.o): Likewise. + * inc/new: Add placement deletes. Add throw specs for default new. + * new.cc (set_new_handler): Move here from libgcc2. + * new1.cc (new (nothrow)): Catch a bad_alloc thrown from the handler. + (new): Move from libgcc2. Throw bad_alloc. + * new2.cc: Move the rest of the op news and op deletes from libgcc2. + * decl.c (init_decl_processing): Update exception specs on new and + delete. + * method.c (build_decl_overload_real): Don't mess with global placement delete. diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 903faffc2ace..fa0f1dd62893 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -58,7 +58,8 @@ CXX_EXTRA_HEADERS = $(srcdir)/cp/inc/typeinfo $(srcdir)/cp/inc/exception \ $(srcdir)/cp/inc/new $(srcdir)/cp/inc/new.h # Extra code to include in libgcc2. -CXX_LIB2FUNCS = tinfo.o tinfo2.o new.o new1.o new2.o exception.o +CXX_LIB2FUNCS = tinfo.o tinfo2.o new.o opnew.o opnewnt.o opvnew.o opvnewnt.o \ + opdel.o opdelnt.o opvdel.o opvdelnt.o exception.o CXX_LIB2SRCS = $(srcdir)/cp/new.cc $(srcdir)/cp/new1.cc $(srcdir)/cp/new2.cc \ $(srcdir)/cp/exception.cc $(srcdir)/cp/tinfo.cc \ $(srcdir)/cp/tinfo2.cc $(srcdir)/cp/tinfo.h @@ -147,12 +148,30 @@ exception.o: cc1plus $(srcdir)/cp/exception.cc new.o: cc1plus $(srcdir)/cp/new.cc $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ -c $(srcdir)/cp/new.cc -new1.o: cc1plus $(srcdir)/cp/new1.cc +opnew.o: cc1plus $(srcdir)/cp/new1.cc $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ - -c $(srcdir)/cp/new1.cc -new2.o: cc1plus $(srcdir)/cp/new2.cc + -c $(srcdir)/cp/new1.cc -DL_op_new -o opnew.o +opnewnt.o: cc1plus $(srcdir)/cp/new1.cc $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ - -c $(srcdir)/cp/new2.cc + -c $(srcdir)/cp/new1.cc -DL_op_newnt -o opnewnt.o +opvnew.o: cc1plus $(srcdir)/cp/new2.cc + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ + -c $(srcdir)/cp/new2.cc -DL_op_vnew -o opvnew.o +opvnewnt.o: cc1plus $(srcdir)/cp/new2.cc + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ + -c $(srcdir)/cp/new2.cc -DL_op_vnewnt -o opvnewnt.o +opdel.o: cc1plus $(srcdir)/cp/new2.cc + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ + -c $(srcdir)/cp/new2.cc -DL_op_delete -o opdel.o +opdelnt.o: cc1plus $(srcdir)/cp/new2.cc + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ + -c $(srcdir)/cp/new2.cc -DL_op_delnt -o opdelnt.o +opvdel.o: cc1plus $(srcdir)/cp/new2.cc + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ + -c $(srcdir)/cp/new2.cc -DL_op_vdel -o opvdel.o +opvdelnt.o: cc1plus $(srcdir)/cp/new2.cc + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) \ + -c $(srcdir)/cp/new2.cc -DL_op_vdelnt -o opvdelnt.o # We want to update cplib2.txt if any of the source files change... cplib2.txt: $(CXX_LIB2SRCS) $(CXX_EXTRA_HEADERS) cplib2.ready diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index b60f842fa43b..233153ba9972 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5577,14 +5577,18 @@ init_decl_processing () /* Now, C++. */ current_lang_name = lang_name_cplusplus; - auto_function (ansi_opname[(int) NEW_EXPR], ptr_ftype_sizetype, - NOT_BUILT_IN); - auto_function (ansi_opname[(int) VEC_NEW_EXPR], ptr_ftype_sizetype, - NOT_BUILT_IN); - auto_function (ansi_opname[(int) DELETE_EXPR], void_ftype_ptr, - NOT_BUILT_IN); - auto_function (ansi_opname[(int) VEC_DELETE_EXPR], void_ftype_ptr, - NOT_BUILT_IN); + { + tree bad_alloc_type_node = xref_tag + (class_type_node, get_identifier ("bad_alloc"), NULL_TREE, 1); + tree newtype = build_exception_variant + (ptr_ftype_sizetype, build_tree_list (NULL_TREE, bad_alloc_type_node)); + tree deltype = build_exception_variant + (void_ftype_ptr, build_tree_list (NULL_TREE, NULL_TREE)); + auto_function (ansi_opname[(int) NEW_EXPR], newtype, NOT_BUILT_IN); + auto_function (ansi_opname[(int) VEC_NEW_EXPR], newtype, NOT_BUILT_IN); + auto_function (ansi_opname[(int) DELETE_EXPR], deltype, NOT_BUILT_IN); + auto_function (ansi_opname[(int) VEC_DELETE_EXPR], deltype, NOT_BUILT_IN); + } abort_fndecl = define_function ("__pure_virtual", void_ftype, diff --git a/gcc/cp/inc/new b/gcc/cp/inc/new index f4b0b975cdbb..23fe6eb9e6bb 100644 --- a/gcc/cp/inc/new +++ b/gcc/cp/inc/new @@ -22,23 +22,21 @@ namespace std { struct nothrow_t {}; extern const nothrow_t nothrow; typedef void (*new_handler)(); - extern "C" new_handler set_new_handler (new_handler); + new_handler set_new_handler (new_handler); #if 0 } // namespace std #endif -// G++ implementation internals -extern new_handler __new_handler; -extern "C" void __default_new_handler (void); - // replaceable signatures -void *operator new (size_t); -void *operator new (size_t, const nothrow_t&) throw(); -void *operator new[] (size_t); -void *operator new[] (size_t, const nothrow_t&) throw(); +void *operator new (size_t) throw (std::bad_alloc); +void *operator new[] (size_t) throw (std::bad_alloc); void operator delete (void *) throw(); void operator delete[] (void *) throw(); +void *operator new (size_t, const nothrow_t&) throw(); +void *operator new[] (size_t, const nothrow_t&) throw(); +void operator delete (void *, const nothrow_t&) throw(); +void operator delete[] (void *, const nothrow_t&) throw(); // default placement versions of operator new inline void *operator new(size_t, void *place) throw() { return place; } diff --git a/gcc/cp/new.cc b/gcc/cp/new.cc index 0db3497f1fa2..33cf190108cb 100644 --- a/gcc/cp/new.cc +++ b/gcc/cp/new.cc @@ -29,3 +29,13 @@ #include "new" const nothrow_t nothrow = { }; + +new_handler __new_handler; + +new_handler +set_new_handler (new_handler handler) +{ + new_handler prev_handler = __new_handler; + __new_handler = handler; + return prev_handler; +} diff --git a/gcc/cp/new1.cc b/gcc/cp/new1.cc index 0ee111d29395..98c2a4a955e2 100644 --- a/gcc/cp/new1.cc +++ b/gcc/cp/new1.cc @@ -1,4 +1,4 @@ -// Support routine for the -*- C++ -*- dynamic memory management. +// Support routines for the -*- C++ -*- dynamic memory management. // Copyright (C) 1997 Free Software Foundation // This file is part of GNU CC. @@ -28,15 +28,16 @@ #include "new" extern "C" void *malloc (size_t); +extern new_handler __new_handler; -typedef void (*vfp)(void); -extern vfp __new_handler; -extern void __default_new_handler (void); +#define WEAK(x) \ + x __attribute__ ((weak)); \ + x -void *operator new (size_t sz, const nothrow_t&) throw() +#ifdef L_op_newnt +WEAK (void * operator new (size_t sz, const nothrow_t&) throw()) { void *p; - vfp handler = __new_handler; /* malloc (0) is unpredictable; avoid it. */ if (sz == 0) @@ -44,11 +45,43 @@ void *operator new (size_t sz, const nothrow_t&) throw() p = (void *) malloc (sz); while (p == 0) { + new_handler handler = __new_handler; if (! handler) return 0; - (*handler) (); + try + { + handler (); + } + catch (bad_alloc &) + { + return 0; + } + + p = (void *) malloc (sz); + } + + return p; +} +#endif + +#ifdef L_op_new +WEAK (void * operator new (size_t sz) throw (std::bad_alloc)) +{ + void *p; + + /* malloc (0) is unpredictable; avoid it. */ + if (sz == 0) + sz = 1; + p = (void *) malloc (sz); + while (p == 0) + { + new_handler handler = __new_handler; + if (! handler) + throw bad_alloc (); + handler (); p = (void *) malloc (sz); } - + return p; } +#endif diff --git a/gcc/cp/new2.cc b/gcc/cp/new2.cc index 5aca49d21d11..d5320f99502c 100644 --- a/gcc/cp/new2.cc +++ b/gcc/cp/new2.cc @@ -1,4 +1,4 @@ -// Support routine for the -*- C++ -*- dynamic memory management. +// Boilerplate support routines for -*- C++ -*- dynamic memory management. // Copyright (C) 1997 Free Software Foundation // This file is part of GNU CC. @@ -27,7 +27,54 @@ #include "new" -void *operator new[] (size_t sz, const nothrow_t& nothrow) throw() +extern "C" void free (void *); + +#define WEAK(x) \ + x __attribute__ ((weak)); \ + x + +#ifdef L_op_vnew +WEAK(void * operator new[] (size_t sz) throw (std::bad_alloc)) +{ + return ::operator new(sz); +} +#endif + +#ifdef L_op_vnewnt +WEAK(void *operator new[] (size_t sz, const nothrow_t& nothrow) throw()) { return ::operator new(sz, nothrow); } +#endif + +#ifdef L_op_delete +WEAK (void operator delete (void *ptr) throw ()) +{ + if (ptr) + free (ptr); +} +#endif + +#ifdef L_op_vdel +WEAK (void operator delete[] (void *ptr) throw ()) +{ + if (ptr) + free (ptr); +} +#endif + +#ifdef L_op_delnt +WEAK (void operator delete (void *ptr, const std::nothrow_t&) throw ()) +{ + if (ptr) + free (ptr); +} +#endif + +#ifdef L_op_vdelnt +WEAK (void operator delete[] (void *ptr, const std::nothrow_t&) throw ()) +{ + if (ptr) + free (ptr); +} +#endif diff --git a/gcc/except.c b/gcc/except.c index d0496690174e..3892f964d088 100644 --- a/gcc/except.c +++ b/gcc/except.c @@ -1573,7 +1573,6 @@ output_exception_table () free (eh_table); /* Ending marker for table. */ - assemble_label ("__EXCEPTION_END__"); assemble_integer (constm1_rtx, POINTER_SIZE / BITS_PER_UNIT, 1); assemble_integer (constm1_rtx, POINTER_SIZE / BITS_PER_UNIT, 1); assemble_integer (constm1_rtx, POINTER_SIZE / BITS_PER_UNIT, 1); diff --git a/gcc/libgcc2.c b/gcc/libgcc2.c index 6c34da7acf52..7fec5cdd45ed 100644 --- a/gcc/libgcc2.c +++ b/gcc/libgcc2.c @@ -42,10 +42,6 @@ Boston, MA 02111-1307, USA. */ #undef abort #endif -#if (SUPPORTS_WEAK == 1) && (defined (ASM_OUTPUT_DEF) || defined (ASM_OUTPUT_WEAK_ALIAS)) -#define WEAK_ALIAS -#endif - /* Permit the tm.h file to select the endianness to use just for this file. This is used when the endianness is determined when the compiler is run. */ @@ -2436,157 +2432,6 @@ stack_overflow:; #endif /* not BLOCK_PROFILER_CODE */ #endif /* L_bb */ -/* Default free-store management functions for C++, per sections 12.5 and - 17.3.3 of the Working Paper. */ - -#ifdef L_op_new -/* operator new (size_t), described in 17.3.3.5. This function is used by - C++ programs to allocate a block of memory to hold a single object. */ - -typedef void (*vfp)(void); -extern vfp __new_handler; -extern void __default_new_handler (void); - -#ifdef WEAK_ALIAS -void * __builtin_new (size_t sz) - __attribute__ ((weak, alias ("___builtin_new"))); -void * -___builtin_new (size_t sz) -#else -void * -__builtin_new (size_t sz) -#endif -{ - void *p; - vfp handler = (__new_handler) ? __new_handler : __default_new_handler; - - /* malloc (0) is unpredictable; avoid it. */ - if (sz == 0) - sz = 1; - p = (void *) malloc (sz); - while (p == 0) - { - (*handler) (); - p = (void *) malloc (sz); - } - - return p; -} -#endif /* L_op_new */ - -#ifdef L_op_vnew -/* void * operator new [] (size_t), described in 17.3.3.6. This function - is used by C++ programs to allocate a block of memory for an array. */ - -extern void * __builtin_new (size_t); - -#ifdef WEAK_ALIAS -void * __builtin_vec_new (size_t sz) - __attribute__ ((weak, alias ("___builtin_vec_new"))); -void * -___builtin_vec_new (size_t sz) -#else -void * -__builtin_vec_new (size_t sz) -#endif -{ - return __builtin_new (sz); -} -#endif /* L_op_vnew */ - -#ifdef L_new_handler -/* set_new_handler (fvoid_t *) and the default new handler, described in - 17.3.3.2 and 17.3.3.5. These functions define the result of a failure - to allocate the amount of memory requested from operator new or new []. */ - -#ifndef inhibit_libc -/* This gets us __GNU_LIBRARY__. */ -#undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */ -#include - -#ifdef __GNU_LIBRARY__ - /* Avoid forcing the library's meaning of `write' on the user program - by using the "internal" name (for use within the library) */ -#define write(fd, buf, n) __write((fd), (buf), (n)) -#endif -#endif /* inhibit_libc */ - -typedef void (*vfp)(void); -void __default_new_handler (void); - -vfp __new_handler = (vfp) 0; - -vfp -set_new_handler (vfp handler) -{ - vfp prev_handler; - - prev_handler = __new_handler; - if (handler == 0) handler = __default_new_handler; - __new_handler = handler; - return prev_handler; -} - -#define MESSAGE "Virtual memory exceeded in `new'\n" - -void -__default_new_handler () -{ -#ifndef inhibit_libc - /* don't use fprintf (stderr, ...) because it may need to call malloc. */ - /* This should really print the name of the program, but that is hard to - do. We need a standard, clean way to get at the name. */ - write (2, MESSAGE, sizeof (MESSAGE)); -#endif - /* don't call exit () because that may call global destructors which - may cause a loop. */ - _exit (-1); -} -#endif - -#ifdef L_op_delete -/* operator delete (void *), described in 17.3.3.3. This function is used - by C++ programs to return to the free store a block of memory allocated - as a single object. */ - -#ifdef WEAK_ALIAS -void __builtin_delete (void *ptr) - __attribute__ ((weak, alias ("___builtin_delete"))); -void -___builtin_delete (void *ptr) -#else -void -__builtin_delete (void *ptr) -#endif -{ - if (ptr) - free (ptr); -} -#endif - -#ifdef L_op_vdel -/* operator delete [] (void *), described in 17.3.3.4. This function is - used by C++ programs to return to the free store a block of memory - allocated as an array. */ - -extern void __builtin_delete (void *); - -#ifdef WEAK_ALIAS -void __builtin_vec_delete (void *ptr) - __attribute__ ((weak, alias ("___builtin_vec_delete"))); -void -___builtin_vec_delete (void *ptr) -#else -void -__builtin_vec_delete (void *ptr) -#endif -{ - __builtin_delete (ptr); -} -#endif - -/* End of C++ free-store management functions */ - #ifdef L_shtab unsigned int __shtab[] = { 0x00000001, 0x00000002, 0x00000004, 0x00000008,