This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: V3 support for arm-none-symbianelf


We're working on a port to Symbian OS for ARM.  Since Symbian OS has
its own C++ runtime, we need libsupc++ -- but not libstdc++.  This
patch makes the freestanding support more vigorous; you can now build
libsupc++ without any target headers other than those which GCC itself
genrates.

Tested on i686-pc-linux-gnu, in the usual way, and on
arm-none-symbianelf by building libsupc++.a.  Applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-08-02  Mark Mitchell  <mark@codesourcery.com>

	* Makefile.am (hosted_source): Add libmath and testsuite.
	(SUBDIRS): Remove them.
	* acinclude.m4: (GLIBCXX_ENABLED_HOSTED): Default to freestanding
	on arm*-*-symbianelf*.
	* crossconfig.m4: Add arm*-*-symbianelf* support.
	* include/c_std/std/std_cstdlib.h (stdlib.h): Do not include it
	when freestanding.  Do not bring names into std:: namespace with
	"using" when freestanding.  Declare required functions and macros
	when freestanding. 
	* libsupc++/Makefile.am (c_sources): Do not include cp-demangle.c
	when freestanding.
	* libsupc++/del_op.cc: Declare "free" only when freestanding.
	* libsupc++/eh_alloc.cc (cstring): Include it only when hosted.
	(malloc): Declare when freestanding.
	(free): Likewise.
	(memset): Likewise.
	(__cxa_allocate_exception): Call malloc, not std::malloc.  Likewise
	for memset.
	(__cxa_free_exception): Likewise for free.
	* libsupc++/new_op.cc: Declare "malloc" when freestanding.
	* libsupc++/pure.cc (writestr): Define to nothing when
	freestanding.
	* libsupc++/vterminate.cc: Do not define anything when
	freestanding.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.
	* include/Makefile.in: Likewise.
	* libmath/Makefile.in: Likewise.
	* libsupc++/Makefile.in: Likewise.
	* po/Makefile.in: Likewise.
	* src/Makefile.in: Likewise.
	* testsuite/Makefile.in: Likewise.

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/Makefile.am,v
retrieving revision 1.50
diff -c -5 -p -r1.50 Makefile.am
*** Makefile.am	15 Jun 2004 14:47:05 -0000	1.50
--- Makefile.am	2 Aug 2004 19:33:37 -0000
***************
*** 23,37 ****
  ## USA.
  
  include $(top_srcdir)/fragment.am
  
  if GLIBCXX_HOSTED
!   # Possibly libmath as well...
!   hosted_source = src po
  endif
  ## Keep this list sync'd with acinclude.m4:GLIBCXX_CONFIGURE.
! SUBDIRS = include libmath libsupc++ $(hosted_source) testsuite
  
  # These rules are messy, but are hella worth it.
  doxygen:
  	-(srcdir=`cd ${top_srcdir}; ${PWD_COMMAND}`; \
  	  builddir=`${PWD_COMMAND}`; \
--- 23,36 ----
  ## USA.
  
  include $(top_srcdir)/fragment.am
  
  if GLIBCXX_HOSTED
!   hosted_source = libmath src po testsuite
  endif
  ## Keep this list sync'd with acinclude.m4:GLIBCXX_CONFIGURE.
! SUBDIRS = include libsupc++ $(hosted_source)
  
  # These rules are messy, but are hella worth it.
  doxygen:
  	-(srcdir=`cd ${top_srcdir}; ${PWD_COMMAND}`; \
  	  builddir=`${PWD_COMMAND}`; \
Index: acinclude.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/acinclude.m4,v
retrieving revision 1.294
diff -c -5 -p -r1.294 acinclude.m4
*** acinclude.m4	15 Jul 2004 17:38:42 -0000	1.294
--- acinclude.m4	2 Aug 2004 19:33:37 -0000
*************** dnl  _GLIBCXX_HOSTED   (always defined, 
*** 1381,1391 ****
  dnl
  AC_DEFUN([GLIBCXX_ENABLE_HOSTED], [
    AC_ARG_ENABLE([hosted-libstdcxx],
      AC_HELP_STRING([--disable-hosted-libstdcxx],
                     [only build freestanding C++ runtime support]),,
!     [enable_hosted_libstdcxx=yes])
    if test "$enable_hosted_libstdcxx" = no; then
      AC_MSG_NOTICE([Only freestanding libraries will be built])
      is_hosted=no
      hosted_define=0
      enable_abi_check=no
--- 1381,1398 ----
  dnl
  AC_DEFUN([GLIBCXX_ENABLE_HOSTED], [
    AC_ARG_ENABLE([hosted-libstdcxx],
      AC_HELP_STRING([--disable-hosted-libstdcxx],
                     [only build freestanding C++ runtime support]),,
!     [case "$host" in
! 	arm*-*-symbianelf*) 
! 	    enable_hosted_libstdcxx=no
! 	    ;;
!         *) 
! 	    enable_hosted_libstdcxx=yes
! 	    ;;
!      esac])
    if test "$enable_hosted_libstdcxx" = no; then
      AC_MSG_NOTICE([Only freestanding libraries will be built])
      is_hosted=no
      hosted_define=0
      enable_abi_check=no
Index: crossconfig.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/crossconfig.m4,v
retrieving revision 1.16
diff -c -5 -p -r1.16 crossconfig.m4
*** crossconfig.m4	7 Jul 2004 01:07:05 -0000	1.16
--- crossconfig.m4	2 Aug 2004 19:33:40 -0000
*************** dnl
*** 2,11 ****
--- 2,15 ----
  dnl This file contains stuff.
  dnl
  
  # Base decisions on target environment.
  case "${host}" in
+   arm*-*-symbianelf*)
+     # This is a freestanding configuration; there is nothing to do here.
+     ;;
+ 
    *-darwin*)
      # Darwin versions vary, but the linker should work in a cross environment,
      # so we just check for all the features here.
      # Check for available headers.
      AC_CHECK_HEADERS([nan.h ieeefp.h endian.h sys/isa_defs.h machine/endian.h \
Index: include/c_std/std_cstdlib.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/std_cstdlib.h,v
retrieving revision 1.9
diff -c -5 -p -r1.9 std_cstdlib.h
*** include/c_std/std_cstdlib.h	9 Dec 2003 03:44:35 -0000	1.9
--- include/c_std/std_cstdlib.h	2 Aug 2004 19:33:41 -0000
***************
*** 47,57 ****
--- 47,63 ----
  #pragma GCC system_header
  
  #include <bits/c++config.h>
  #include <cstddef>
  
+ #if _GLIBCXX_HOSTED
+ /* The C standard does not require a freestanding implementation to
+    provide <stdlib.h>.  However, the C++ standard does still require
+    <cstdlib> -- but only the functionality mentioned in
+    [lib.support.start.term].  */
  #include <stdlib.h>
+ #endif
  
  // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
  #undef abort
  #undef abs
  #undef atexit
***************
*** 81,90 ****
--- 87,97 ----
  #undef wcstombs
  #undef wctomb
  
  namespace std
  {
+ #if _GLIBCXX_HOSTED
    using ::div_t;
    using ::ldiv_t;
  
    using ::abort;
    using ::abs;
*************** namespace std
*** 122,131 ****
--- 129,147 ----
    inline long
    abs(long __i) { return labs(__i); }
  
    inline ldiv_t
    div(long __i, long __j) { return ldiv(__i, __j); }
+ #else
+   /* Provide the minimal set of definitions required of a freestanding
+      implementation.  */
+   #define EXIT_SUCCESS 0
+   #define EXIT_FAILURE 1
+   extern "C" void abort(void);
+   extern "C" int atexit(void (*)());
+   extern "C" void exit(int);
+ #endif
  }
  
  #if _GLIBCXX_USE_C99
  
  #undef _Exit
Index: libsupc++/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/Makefile.am,v
retrieving revision 1.49
diff -c -5 -p -r1.49 Makefile.am
*** libsupc++/Makefile.am	27 Feb 2004 03:21:15 -0000	1.49
--- libsupc++/Makefile.am	2 Aug 2004 19:33:41 -0000
*************** noinst_LTLIBRARIES = libsupc++convenienc
*** 32,43 ****
  
  
  headers = \
  	exception new typeinfo cxxabi.h exception_defines.h
  
! c_sources = \
  	cp-demangle.c 
  
  sources = \
  	del_op.cc \
  	del_opnt.cc \
  	del_opv.cc \
--- 32,45 ----
  
  
  headers = \
  	exception new typeinfo cxxabi.h exception_defines.h
  
! if GLIBCXX_HOSTED
!   c_sources = \
  	cp-demangle.c 
+ endif
  
  sources = \
  	del_op.cc \
  	del_opnt.cc \
  	del_opv.cc \
Index: libsupc++/del_op.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/del_op.cc,v
retrieving revision 1.4
diff -c -5 -p -r1.4 del_op.cc
*** libsupc++/del_op.cc	7 Apr 2004 03:33:35 -0000	1.4
--- libsupc++/del_op.cc	2 Aug 2004 19:33:41 -0000
***************
*** 27,39 ****
  // the GNU General Public License.  This exception does not however
  // invalidate any other reasons why the executable file might be covered by
  // the GNU General Public License.
  
  #include "new"
  
! // We can't rely on having stdlib.h if we're freestanding.
! extern "C" void free (void *);
  
  void
  operator delete (void *ptr) throw ()
  {
    if (ptr)
--- 27,46 ----
  // the GNU General Public License.  This exception does not however
  // invalidate any other reasons why the executable file might be covered by
  // the GNU General Public License.
  
  #include "new"
+ #include <cstdlib>
  
! #if _GLIBCXX_HOSTED
! using std::free;
! #else
! // In a freestanding environment, "free" may not be available.  In
! // that case, it may make sense not to define "operator delete" at
! // all.  For now, we assume that "free" will work.
! extern "C" void free(void *);
! #endif
  
  void
  operator delete (void *ptr) throw ()
  {
    if (ptr)
Index: libsupc++/eh_alloc.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/eh_alloc.cc,v
retrieving revision 1.9
diff -c -5 -p -r1.9 eh_alloc.cc
*** libsupc++/eh_alloc.cc	7 Apr 2004 03:33:35 -0000	1.9
--- libsupc++/eh_alloc.cc	2 Aug 2004 19:33:41 -0000
***************
*** 29,47 ****
  
  // This is derived from the C++ ABI for IA-64.  Where we diverge
  // for cross-architecture compatibility are noted with "@@@".
  
  #include <cstdlib>
  #include <cstring>
  #include <climits>
  #include <exception>
  #include "unwind-cxx.h"
  #include "bits/c++config.h"
  #include "bits/gthr.h"
  
! using namespace __cxxabiv1;
  
  
  // ??? How to control these parameters.
  
  // Guess from the size of basic types how large a buffer is reasonable.
  // Note that the basic c++ exception header has 13 pointers and 2 ints,
--- 29,60 ----
  
  // This is derived from the C++ ABI for IA-64.  Where we diverge
  // for cross-architecture compatibility are noted with "@@@".
  
  #include <cstdlib>
+ #if _GLIBCXX_HOSTED
  #include <cstring>
+ #endif
  #include <climits>
  #include <exception>
  #include "unwind-cxx.h"
  #include "bits/c++config.h"
  #include "bits/gthr.h"
  
! #if _GLIBCXX_HOSTED
! using std::free;
! using std::malloc;
! using std::memcpy;
! #else
! // In a freestanding environment, these functions may not be
! // available -- but for now, we assume that they are.
! extern "C" void *malloc (std::size_t);
! extern "C" void free(void *);
! extern "C" int memset (void *, int, std::size_t);
! #endif
  
+ using namespace __cxxabiv1;
  
  // ??? How to control these parameters.
  
  // Guess from the size of basic types how large a buffer is reasonable.
  // Note that the basic c++ exception header has 13 pointers and 2 ints,
*************** extern "C" void *
*** 97,107 ****
  __cxa_allocate_exception(std::size_t thrown_size) throw()
  {
    void *ret;
  
    thrown_size += sizeof (__cxa_exception);
!   ret = std::malloc (thrown_size);
  
    if (! ret)
      {
  #ifdef __GTHREADS
  #ifdef __GTHREAD_MUTEX_INIT_FUNCTION
--- 110,120 ----
  __cxa_allocate_exception(std::size_t thrown_size) throw()
  {
    void *ret;
  
    thrown_size += sizeof (__cxa_exception);
!   ret = malloc (thrown_size);
  
    if (! ret)
      {
  #ifdef __GTHREADS
  #ifdef __GTHREAD_MUTEX_INIT_FUNCTION
*************** __cxa_allocate_exception(std::size_t thr
*** 132,142 ****
  #endif
        if (!ret)
  	std::terminate ();
      }
  
!   std::memset (ret, 0, sizeof (__cxa_exception));
  
    return (void *)((char *)ret + sizeof (__cxa_exception));
  }
  
  
--- 145,155 ----
  #endif
        if (!ret)
  	std::terminate ();
      }
  
!   memset (ret, 0, sizeof (__cxa_exception));
  
    return (void *)((char *)ret + sizeof (__cxa_exception));
  }
  
  
*************** __cxa_free_exception(void *vptr) throw()
*** 157,163 ****
  #else
        emergency_used &= ~((bitmask_type)1 << which);
  #endif
      }
    else
!     std::free (ptr - sizeof (__cxa_exception));
  }
--- 170,176 ----
  #else
        emergency_used &= ~((bitmask_type)1 << which);
  #endif
      }
    else
!     free (ptr - sizeof (__cxa_exception));
  }
Index: libsupc++/new_op.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/new_op.cc,v
retrieving revision 1.6
diff -c -5 -p -r1.6 new_op.cc
*** libsupc++/new_op.cc	24 May 2003 16:22:03 -0000	1.6
--- libsupc++/new_op.cc	2 Aug 2004 19:33:41 -0000
***************
*** 31,41 ****
--- 31,48 ----
  #include <cstdlib>
  #include <exception_defines.h>
  
  using std::new_handler;
  using std::bad_alloc;
+ #if _GLIBCXX_HOSTED
  using std::malloc;
+ #else
+ // In a freestanding environment, "malloc" may not be available.  In
+ // that case, it may make sense not to define "operator new" at all.
+ // For now, we assume that "malloc" will work.
+ extern "C" void *malloc (std::size_t);
+ #endif
  
  extern new_handler __new_handler;
  
  void *
  operator new (std::size_t sz) throw (std::bad_alloc)
Index: libsupc++/pure.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/pure.cc,v
retrieving revision 1.11
diff -c -5 -p -r1.11 pure.cc
*** libsupc++/pure.cc	5 Jul 2003 04:05:40 -0000	1.11
--- libsupc++/pure.cc	2 Aug 2004 19:33:41 -0000
***************
*** 28,37 ****
--- 28,38 ----
  // the GNU General Public License.
  
  #include <bits/c++config.h>
  #include "unwind-cxx.h"
  
+ #if _GLIBCXX_HOSTED
  #ifdef _GLIBCXX_HAVE_UNISTD_H
  # include <unistd.h>
  # define writestr(str)	write(2, str, sizeof(str) - 1)
  # ifdef __GNU_LIBRARY__
    /* Avoid forcing the library's meaning of `write' on the user program
***************
*** 40,49 ****
--- 41,53 ----
  # endif
  #else
  # include <cstdio>
  # define writestr(str)	std::fputs(str, stderr)
  #endif
+ #else
+ # define writestr(str) /* Empty */
+ #endif
  
  extern "C" void
  __cxa_pure_virtual (void)
  {
    writestr ("pure virtual method called\n");
Index: libsupc++/vterminate.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/vterminate.cc,v
retrieving revision 1.5
diff -c -5 -p -r1.5 vterminate.cc
*** libsupc++/vterminate.cc	23 Feb 2004 19:17:06 -0000	1.5
--- libsupc++/vterminate.cc	2 Aug 2004 19:33:41 -0000
***************
*** 26,35 ****
--- 26,36 ----
  // the GNU General Public License.  This exception does not however
  // invalidate any other reasons why the executable file might be covered by
  // the GNU General Public License.
  
  #include <bits/c++config.h>
+ #if _GLIBCXX_HOSTED
  #include <cstdlib>
  #include <exception>
  #include <exception_defines.h>
  #include <cxxabi.h>
  # include <cstdio>
*************** namespace __gnu_cxx
*** 94,98 ****
--- 95,100 ----
        fputs("terminate called without an active exception\n", stderr);
      
      abort();
    }
  } // namespace __gnu_cxx
+ #endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]