This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: weak for Darwin


Benjamin Kosnik wrote:

> This is the right idea, however the default should be to do nothing, and
> config/os/darwin/os_defines.h should define _GLIBCXX_WEAK_DEFINITION to
> do the special stuff.

OK.  What do you think about this?  Geoffrey, does the comment in
config/os/bsd/darwin/os_defined.h say the right thing?

Aaron W. LaFramboise

2004-11-03  Aaron W. LaFramboise <aaronavay62@aaronwl.com>

	* config/os/bsd/darwin/os_defines.h
	(_GLIBCXX_WEAK_DEFINITION): Define.
	* include/bits/c++config (_GLIBCXX_WEAK_DEFINITION): Define.
	* libsupc++/del_op.cc (operator delete(void *)): Use
	_GLIBCXX_WEAK_DEFINITION.
	* libsupc++/del_opnt.cc
	(operator delete(void *, const std::nothrow_t&): Same.
	* libsupc++/del_opv.cc (operator delete[](void *)): Same.
	* libsupc++/del_opvnt.cc
	(operator delete[](void *, const std::nothrow_t&): Same.
	* libsupc++/new_op.cc (operator new(std::size_t)): Same.
	* libsupc++/new_opnt.cc
	(operator new(std::size_t, const std::nothrow_t&)): Same
	* libsupc++/new_opv.cc (operator new[](std::size_t)): Same.
	* libsupc++/new_opvnt.cc
	(operator new[](std::size_t, const std::nothrow_t&)): Same.

Index: gcc/libstdc++-v3/config/os/bsd/darwin/os_defines.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/os/bsd/darwin/os_defines.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 os_defines.h
*** gcc/libstdc++-v3/config/os/bsd/darwin/os_defines.h	30 Oct 2004 01:03:12 -0000	1.2
--- gcc/libstdc++-v3/config/os/bsd/darwin/os_defines.h	3 Nov 2004 01:29:11 -0000
***************
*** 38,41 ****
--- 38,47 ----
     links to, so there's no need for weak-ness for that.  */
  #define _GLIBCXX_GTHREAD_USE_WEAK 0
  
+ // On Darwin, in order to enable overriding of operator new and delete,
+ // GCC makes the definition of these functions weak, relies on the
+ // loader to implement weak semantics properly, and uses
+ // -flat_namespace to work around the way that it doesn't.
+ #define _GLIBCXX_WEAK_DEFINITION __attribute__ ((weak))
+ 
  #endif
Index: gcc/libstdc++-v3/include/bits/c++config
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/c++config,v
retrieving revision 1.1268
diff -c -3 -p -r1.1268 c++config
*** gcc/libstdc++-v3/include/bits/c++config	28 Oct 2004 00:16:17 -0000	1.1268
--- gcc/libstdc++-v3/include/bits/c++config	3 Nov 2004 01:29:11 -0000
***************
*** 51,56 ****
--- 51,63 ----
  # define _GLIBCXX_EXTERN_TEMPLATE 1
  #endif
  
+ // Certain function definitions that are meant to be overridable
+ // from user code are decorated with this macro.  For some targets,
+ // this macro causes these definitions to be weak.
+ #ifndef _GLIBCXX_WEAK_DEFINITION
+ #define _GLIBCXX_WEAK_DEFINITION
+ #endif
+ 
  // Debug mode support. Debug mode basic_string is not allowed to be
  // associated with std, because of locale and exception link
  // dependence.
Index: gcc/libstdc++-v3/libsupc++/del_op.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/del_op.cc,v
retrieving revision 1.7
diff -c -3 -p -r1.7 del_op.cc
*** gcc/libstdc++-v3/libsupc++/del_op.cc	26 Oct 2004 06:09:05 -0000	1.7
--- gcc/libstdc++-v3/libsupc++/del_op.cc	3 Nov 2004 01:29:11 -0000
*************** using std::free;
*** 39,45 ****
  extern "C" void free(void *);
  #endif
  
! __attribute__((weak)) void
  operator delete (void *ptr) throw ()
  {
    if (ptr)
--- 39,45 ----
  extern "C" void free(void *);
  #endif
  
! _GLIBCXX_WEAK_DEFINITION void
  operator delete (void *ptr) throw ()
  {
    if (ptr)
Index: gcc/libstdc++-v3/libsupc++/del_opnt.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/del_opnt.cc,v
retrieving revision 1.4
diff -c -3 -p -r1.4 del_opnt.cc
*** gcc/libstdc++-v3/libsupc++/del_opnt.cc	26 Oct 2004 06:09:05 -0000	1.4
--- gcc/libstdc++-v3/libsupc++/del_opnt.cc	3 Nov 2004 01:29:11 -0000
***************
*** 32,38 ****
  
  extern "C" void free (void *);
  
! __attribute__((weak)) void
  operator delete (void *ptr, const std::nothrow_t&) throw ()
  {
    if (ptr)
--- 32,38 ----
  
  extern "C" void free (void *);
  
! _GLIBCXX_WEAK_DEFINITION void
  operator delete (void *ptr, const std::nothrow_t&) throw ()
  {
    if (ptr)
Index: gcc/libstdc++-v3/libsupc++/del_opv.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/del_opv.cc,v
retrieving revision 1.4
diff -c -3 -p -r1.4 del_opv.cc
*** gcc/libstdc++-v3/libsupc++/del_opv.cc	26 Oct 2004 06:09:05 -0000	1.4
--- gcc/libstdc++-v3/libsupc++/del_opv.cc	3 Nov 2004 01:29:11 -0000
***************
*** 30,36 ****
  
  #include "new"
  
! __attribute__((weak)) void
  operator delete[] (void *ptr) throw ()
  {
    ::operator delete (ptr);
--- 30,36 ----
  
  #include "new"
  
! _GLIBCXX_WEAK_DEFINITION void
  operator delete[] (void *ptr) throw ()
  {
    ::operator delete (ptr);
Index: gcc/libstdc++-v3/libsupc++/del_opvnt.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/del_opvnt.cc,v
retrieving revision 1.4
diff -c -3 -p -r1.4 del_opvnt.cc
*** gcc/libstdc++-v3/libsupc++/del_opvnt.cc	26 Oct 2004 06:09:05 -0000	1.4
--- gcc/libstdc++-v3/libsupc++/del_opvnt.cc	3 Nov 2004 01:29:11 -0000
***************
*** 30,36 ****
  
  #include "new"
  
! __attribute__((weak)) void
  operator delete[] (void *ptr, const std::nothrow_t&) throw ()
  {
    ::operator delete (ptr);
--- 30,36 ----
  
  #include "new"
  
! _GLIBCXX_WEAK_DEFINITION void
  operator delete[] (void *ptr, const std::nothrow_t&) throw ()
  {
    ::operator delete (ptr);
Index: gcc/libstdc++-v3/libsupc++/new_op.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/new_op.cc,v
retrieving revision 1.9
diff -c -3 -p -r1.9 new_op.cc
*** gcc/libstdc++-v3/libsupc++/new_op.cc	26 Oct 2004 06:09:05 -0000	1.9
--- gcc/libstdc++-v3/libsupc++/new_op.cc	3 Nov 2004 01:29:11 -0000
*************** extern "C" void *malloc (std::size_t);
*** 43,49 ****
  
  extern new_handler __new_handler;
  
! __attribute__((weak)) void *
  operator new (std::size_t sz) throw (std::bad_alloc)
  {
    void *p;
--- 43,49 ----
  
  extern new_handler __new_handler;
  
! _GLIBCXX_WEAK_DEFINITION void *
  operator new (std::size_t sz) throw (std::bad_alloc)
  {
    void *p;
Index: gcc/libstdc++-v3/libsupc++/new_opnt.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/new_opnt.cc,v
retrieving revision 1.5
diff -c -3 -p -r1.5 new_opnt.cc
*** gcc/libstdc++-v3/libsupc++/new_opnt.cc	26 Oct 2004 06:09:05 -0000	1.5
--- gcc/libstdc++-v3/libsupc++/new_opnt.cc	3 Nov 2004 01:29:11 -0000
*************** using std::bad_alloc;
*** 36,42 ****
  extern "C" void *malloc (std::size_t);
  extern new_handler __new_handler;
  
! __attribute__((weak)) void *
  operator new (std::size_t sz, const std::nothrow_t&) throw()
  {
    void *p;
--- 36,42 ----
  extern "C" void *malloc (std::size_t);
  extern new_handler __new_handler;
  
! _GLIBCXX_WEAK_DEFINITION void *
  operator new (std::size_t sz, const std::nothrow_t&) throw()
  {
    void *p;
Index: gcc/libstdc++-v3/libsupc++/new_opv.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/new_opv.cc,v
retrieving revision 1.5
diff -c -3 -p -r1.5 new_opv.cc
*** gcc/libstdc++-v3/libsupc++/new_opv.cc	26 Oct 2004 06:09:05 -0000	1.5
--- gcc/libstdc++-v3/libsupc++/new_opv.cc	3 Nov 2004 01:29:11 -0000
***************
*** 30,36 ****
  
  #include "new"
  
! __attribute__((weak)) void *
  operator new[] (std::size_t sz) throw (std::bad_alloc)
  {
    return ::operator new(sz);
--- 30,36 ----
  
  #include "new"
  
! _GLIBCXX_WEAK_DEFINITION void *
  operator new[] (std::size_t sz) throw (std::bad_alloc)
  {
    return ::operator new(sz);
Index: gcc/libstdc++-v3/libsupc++/new_opvnt.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/new_opvnt.cc,v
retrieving revision 1.5
diff -c -3 -p -r1.5 new_opvnt.cc
*** gcc/libstdc++-v3/libsupc++/new_opvnt.cc	26 Oct 2004 06:09:05 -0000	1.5
--- gcc/libstdc++-v3/libsupc++/new_opvnt.cc	3 Nov 2004 01:29:11 -0000
***************
*** 30,36 ****
  
  #include "new"
  
! __attribute__((weak)) void *
  operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw()
  {
    return ::operator new(sz, nothrow);
--- 30,36 ----
  
  #include "new"
  
! _GLIBCXX_WEAK_DEFINITION void *
  operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw()
  {
    return ::operator new(sz, nothrow);

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