Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/csu/common_elf Add support for invoking GNU C++ local de...
details: https://anonhg.NetBSD.org/src/rev/af5b6c04a946
branches: trunk
changeset: 519937:af5b6c04a946
user: thorpej <thorpej%NetBSD.org@localhost>
date: Mon Dec 31 00:40:11 2001 +0000
description:
Add support for invoking GNU C++ local destructors in shared objects
via the __cxa_finalize() mechanism.
XXX Only enabled for new-toolchain platforms, as it requires the assembler
to support the .hidden pseudo-op.
diffstat:
lib/csu/common_elf/Makefile.inc | 10 +++++++++-
lib/csu/common_elf/crtbegin.c | 33 ++++++++++++++++++++++++++++++---
2 files changed, 39 insertions(+), 4 deletions(-)
diffs (83 lines):
diff -r 25175a98d3d4 -r af5b6c04a946 lib/csu/common_elf/Makefile.inc
--- a/lib/csu/common_elf/Makefile.inc Mon Dec 31 00:35:21 2001 +0000
+++ b/lib/csu/common_elf/Makefile.inc Mon Dec 31 00:40:11 2001 +0000
@@ -1,4 +1,6 @@
-# $NetBSD: Makefile.inc,v 1.12 2001/12/31 00:11:13 thorpej Exp $
+# $NetBSD: Makefile.inc,v 1.13 2001/12/31 00:40:11 thorpej Exp $
+
+.include <bsd.own.mk>
.if !defined(ELFSIZE)
ELFSIZE=32
@@ -13,6 +15,12 @@
CPPFLAGS+= -DDWARF2_EH
CPPFLAGS+= -DJCR
+# XXX Temporary until all ELF ports use the new toolchain. The old
+# toolchain doesn't have support for "hidden" symbols.
+.if defined(USE_NEW_TOOLCHAIN)
+CPPFLAGS+= -DDSO_HANDLE
+.endif
+
.if !defined(MACHINE_ARCH) || ${MACHINE_ARCH} != "m68000"
COPTS+= -fPIC
.endif
diff -r 25175a98d3d4 -r af5b6c04a946 lib/csu/common_elf/crtbegin.c
--- a/lib/csu/common_elf/crtbegin.c Mon Dec 31 00:35:21 2001 +0000
+++ b/lib/csu/common_elf/crtbegin.c Mon Dec 31 00:40:11 2001 +0000
@@ -1,11 +1,11 @@
-/* $NetBSD: crtbegin.c,v 1.16 2001/12/30 23:45:01 thorpej Exp $ */
+/* $NetBSD: crtbegin.c,v 1.17 2001/12/31 00:40:11 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
- * by Paul Kranenburg and Ross Harvey.
+ * by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -75,6 +75,25 @@
__attribute__((section(".jcr"))) = { };
#endif
+#if defined(DSO_HANDLE) && defined(__GNUC__)
+/*
+ * The __dso_handle variable is used to hang C++ local destructors off
+ * of. In the main program (i.e. using crtbegin.o), the value is 0.
+ * In shared objects (i.e. using crtbeginS.o), the value must be unique.
+ * The symbol is hidden, but the dynamic linker will still relocate it.
+ */
+#ifdef SHARED
+void *__dso_handle = &__dso_handle;
+#else
+void *__dso_handle = NULL;
+#endif
+__asm(".hidden __dso_handle");
+
+#ifdef SHARED
+extern void __cxa_finalize(void *) __attribute__((weak));
+#endif
+#endif
+
static void __dtors(void);
static void __ctors(void);
@@ -149,6 +168,14 @@
_fini()
{
+#if defined(DSO_HANDLE) && defined(__GNUC__) && defined(SHARED)
+ /*
+ * Call local destructors.
+ */
+ if (__cxa_finalize != NULL)
+ __cxa_finalize(__dso_handle);
+#endif /* DSO_HANDLE && __GNUC__ && SHARED */
+
/*
* Call global destructors.
*/
Home |
Main Index |
Thread Index |
Old Index