Module Name: src
Committed By: joerg
Date: Mon Mar 7 05:09:12 UTC 2011
Modified Files:
src/lib/csu/alpha: crt0.c
src/lib/csu/arm_elf: crt0.c
src/lib/csu/common: crt0-common.c
src/lib/csu/common_elf: common.h
src/lib/csu/hppa: crt0.c
src/lib/csu/ia64: crt0.c
src/lib/csu/m68k_elf: crt0.c
src/lib/csu/powerpc: crt0.c
src/lib/csu/powerpc64: crt0.c
src/lib/csu/sh3_elf: crt0.c
src/lib/csu/sparc64: crt0.c
src/lib/csu/sparc_elf: crt0.c
src/lib/csu/vax_elf: crt0.c
src/lib/libc/dlfcn: dlfcn_elf.c
src/lib/libc/misc: initfini.c
src/lib/libc/stdlib: exit.c
src/sys/compat/netbsd32: netbsd32_exec_elf32.c
src/sys/kern: exec_elf.c
Log Message:
Pass down ELF Auxillary Vectors for static NetBSD binaries too.
Rename __libc_init to _libc_init and call it explicitly from CSU code.
This enforces the constructor run order for newly linked programs.
Keep it as constructor with run-once semantic for binary compatibility.
Implement dl_iterate_phdr for statically linked programs.
This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/csu/alpha/crt0.c
cvs rdiff -u -r1.8 -r1.9 src/lib/csu/arm_elf/crt0.c
cvs rdiff -u -r1.4 -r1.5 src/lib/csu/common/crt0-common.c
cvs rdiff -u -r1.14 -r1.15 src/lib/csu/common_elf/common.h
cvs rdiff -u -r1.9 -r1.10 src/lib/csu/hppa/crt0.c
cvs rdiff -u -r1.3 -r1.4 src/lib/csu/ia64/crt0.c
cvs rdiff -u -r1.12 -r1.13 src/lib/csu/m68k_elf/crt0.c
cvs rdiff -u -r1.28 -r1.29 src/lib/csu/powerpc/crt0.c
cvs rdiff -u -r1.3 -r1.4 src/lib/csu/powerpc64/crt0.c
cvs rdiff -u -r1.11 -r1.12 src/lib/csu/sh3_elf/crt0.c
cvs rdiff -u -r1.25 -r1.26 src/lib/csu/sparc64/crt0.c
cvs rdiff -u -r1.13 -r1.14 src/lib/csu/sparc_elf/crt0.c
cvs rdiff -u -r1.11 -r1.12 src/lib/csu/vax_elf/crt0.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/dlfcn/dlfcn_elf.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/misc/initfini.c
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdlib/exit.c
cvs rdiff -u -r1.32 -r1.33 src/sys/compat/netbsd32/netbsd32_exec_elf32.c
cvs rdiff -u -r1.28 -r1.29 src/sys/kern/exec_elf.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/csu/alpha/crt0.c
diff -u src/lib/csu/alpha/crt0.c:1.25 src/lib/csu/alpha/crt0.c:1.26
--- src/lib/csu/alpha/crt0.c:1.25 Tue Feb 22 05:45:05 2011
+++ src/lib/csu/alpha/crt0.c Mon Mar 7 05:09:09 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.25 2011/02/22 05:45:05 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.26 2011/03/07 05:09:09 joerg Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
@@ -69,6 +69,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -84,7 +86,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.25 2011/02/22 05:45:05 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.26 2011/03/07 05:09:09 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/arm_elf/crt0.c
diff -u src/lib/csu/arm_elf/crt0.c:1.8 src/lib/csu/arm_elf/crt0.c:1.9
--- src/lib/csu/arm_elf/crt0.c:1.8 Tue Feb 22 05:45:05 2011
+++ src/lib/csu/arm_elf/crt0.c Mon Mar 7 05:09:09 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.8 2011/02/22 05:45:05 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.9 2011/03/07 05:09:09 joerg Exp $ */
/*
* Copyright (C) 1997 Mark Brinicombe
@@ -68,7 +68,7 @@
" b " ___STRING(_C_LABEL(___start)) " ");
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.8 2011/02/22 05:45:05 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.9 2011/03/07 05:09:09 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
void
@@ -93,6 +93,8 @@
_rtld_setup(cleanup, obj);
#endif /* DYNAMIC */
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.4 src/lib/csu/common/crt0-common.c:1.5
--- src/lib/csu/common/crt0-common.c:1.4 Tue Feb 22 05:45:06 2011
+++ src/lib/csu/common/crt0-common.c Mon Mar 7 05:09:09 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.4 2011/02/22 05:45:06 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.5 2011/03/07 05:09:09 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: crt0-common.c,v 1.4 2011/02/22 05:45:06 joerg Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.5 2011/03/07 05:09:09 joerg Exp $");
#include <sys/types.h>
#include <sys/syscall.h>
@@ -50,6 +50,7 @@
extern void _init(void);
extern void _fini(void);
+extern void _libc_init(void);
/*
* Arrange for _DYNAMIC to be weak and undefined (and therefore to show up
@@ -115,6 +116,8 @@
atexit(cleanup);
}
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&__eprol, (u_long)&__etext);
Index: src/lib/csu/common_elf/common.h
diff -u src/lib/csu/common_elf/common.h:1.14 src/lib/csu/common_elf/common.h:1.15
--- src/lib/csu/common_elf/common.h:1.14 Tue Feb 22 05:45:06 2011
+++ src/lib/csu/common_elf/common.h Mon Mar 7 05:09:09 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: common.h,v 1.14 2011/02/22 05:45:06 joerg Exp $ */
+/* $NetBSD: common.h,v 1.15 2011/03/07 05:09:09 joerg Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
@@ -71,6 +71,7 @@
extern void _init(void);
extern void _fini(void);
+extern void _libc_init(void);
#ifdef DYNAMIC
void _rtld_setup(void (*)(void), const Obj_Entry *obj);
Index: src/lib/csu/hppa/crt0.c
diff -u src/lib/csu/hppa/crt0.c:1.9 src/lib/csu/hppa/crt0.c:1.10
--- src/lib/csu/hppa/crt0.c:1.9 Wed Feb 23 10:26:09 2011
+++ src/lib/csu/hppa/crt0.c Mon Mar 7 05:09:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.9 2011/02/23 10:26:09 skrll Exp $ */
+/* $NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $ */
/*
* Copyright (c) 2002 Matt Fredette
@@ -93,6 +93,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -131,7 +133,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.9 2011/02/23 10:26:09 skrll Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/ia64/crt0.c
diff -u src/lib/csu/ia64/crt0.c:1.3 src/lib/csu/ia64/crt0.c:1.4
--- src/lib/csu/ia64/crt0.c:1.3 Tue Feb 22 05:45:06 2011
+++ src/lib/csu/ia64/crt0.c Mon Mar 7 05:09:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.3 2011/02/22 05:45:06 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
@@ -76,6 +76,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -91,7 +93,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.3 2011/02/22 05:45:06 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/m68k_elf/crt0.c
diff -u src/lib/csu/m68k_elf/crt0.c:1.12 src/lib/csu/m68k_elf/crt0.c:1.13
--- src/lib/csu/m68k_elf/crt0.c:1.12 Tue Feb 22 05:45:06 2011
+++ src/lib/csu/m68k_elf/crt0.c Mon Mar 7 05:09:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.12 2011/02/22 05:45:06 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.13 2011/03/07 05:09:10 joerg Exp $ */
/*
* Copyright (c) 1999 Klaus Klein
@@ -79,6 +79,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -94,7 +96,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.12 2011/02/22 05:45:06 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.13 2011/03/07 05:09:10 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/powerpc/crt0.c
diff -u src/lib/csu/powerpc/crt0.c:1.28 src/lib/csu/powerpc/crt0.c:1.29
--- src/lib/csu/powerpc/crt0.c:1.28 Sat Feb 26 17:11:23 2011
+++ src/lib/csu/powerpc/crt0.c Mon Mar 7 05:09:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.28 2011/02/26 17:11:23 matt Exp $ */
+/* $NetBSD: crt0.c,v 1.29 2011/03/07 05:09:10 joerg Exp $ */
/*
* Copyright (c) 1997 Jason R. Thorpe.
@@ -92,6 +92,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -107,7 +109,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.28 2011/02/26 17:11:23 matt Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.29 2011/03/07 05:09:10 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/powerpc64/crt0.c
diff -u src/lib/csu/powerpc64/crt0.c:1.3 src/lib/csu/powerpc64/crt0.c:1.4
--- src/lib/csu/powerpc64/crt0.c:1.3 Tue Feb 22 05:45:07 2011
+++ src/lib/csu/powerpc64/crt0.c Mon Mar 7 05:09:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.3 2011/02/22 05:45:07 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $ */
/*
* Copyright (c) 1997 Jason R. Thorpe.
@@ -78,6 +78,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -93,7 +95,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.3 2011/02/22 05:45:07 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/sh3_elf/crt0.c
diff -u src/lib/csu/sh3_elf/crt0.c:1.11 src/lib/csu/sh3_elf/crt0.c:1.12
--- src/lib/csu/sh3_elf/crt0.c:1.11 Tue Feb 22 05:45:07 2011
+++ src/lib/csu/sh3_elf/crt0.c Mon Mar 7 05:09:11 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.11 2011/02/22 05:45:07 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
@@ -73,6 +73,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -88,7 +90,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.11 2011/02/22 05:45:07 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/sparc64/crt0.c
diff -u src/lib/csu/sparc64/crt0.c:1.25 src/lib/csu/sparc64/crt0.c:1.26
--- src/lib/csu/sparc64/crt0.c:1.25 Tue Feb 22 05:45:07 2011
+++ src/lib/csu/sparc64/crt0.c Mon Mar 7 05:09:11 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.25 2011/02/22 05:45:07 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.26 2011/03/07 05:09:11 joerg Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
@@ -98,6 +98,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -113,7 +115,7 @@
* NOTE: Leave the RCS ID _after_ _start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.25 2011/02/22 05:45:07 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.26 2011/03/07 05:09:11 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/sparc_elf/crt0.c
diff -u src/lib/csu/sparc_elf/crt0.c:1.13 src/lib/csu/sparc_elf/crt0.c:1.14
--- src/lib/csu/sparc_elf/crt0.c:1.13 Tue Feb 22 05:45:08 2011
+++ src/lib/csu/sparc_elf/crt0.c Mon Mar 7 05:09:11 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.13 2011/02/22 05:45:08 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.14 2011/03/07 05:09:11 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
@@ -83,6 +83,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -98,7 +100,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.13 2011/02/22 05:45:08 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.14 2011/03/07 05:09:11 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/csu/vax_elf/crt0.c
diff -u src/lib/csu/vax_elf/crt0.c:1.11 src/lib/csu/vax_elf/crt0.c:1.12
--- src/lib/csu/vax_elf/crt0.c:1.11 Tue Feb 22 05:45:08 2011
+++ src/lib/csu/vax_elf/crt0.c Mon Mar 7 05:09:11 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0.c,v 1.11 2011/02/22 05:45:08 joerg Exp $ */
+/* $NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $ */
/*
* Copyright (c) 1999 Matt Thomas
@@ -80,6 +80,8 @@
_rtld_setup(cleanup, obj);
#endif
+ _libc_init();
+
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
@@ -95,7 +97,7 @@
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: crt0.c,v 1.11 2011/02/22 05:45:08 joerg Exp $");
+__RCSID("$NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"
Index: src/lib/libc/dlfcn/dlfcn_elf.c
diff -u src/lib/libc/dlfcn/dlfcn_elf.c:1.7 src/lib/libc/dlfcn/dlfcn_elf.c:1.8
--- src/lib/libc/dlfcn/dlfcn_elf.c:1.7 Sat Oct 16 10:27:07 2010
+++ src/lib/libc/dlfcn/dlfcn_elf.c Mon Mar 7 05:09:11 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: dlfcn_elf.c,v 1.7 2010/10/16 10:27:07 skrll Exp $ */
+/* $NetBSD: dlfcn_elf.c,v 1.8 2011/03/07 05:09:11 joerg Exp $ */
/*
* Copyright (c) 2000 Takuya SHIOZAKI
@@ -27,10 +27,14 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: dlfcn_elf.c,v 1.7 2010/10/16 10:27:07 skrll Exp $");
+__RCSID("$NetBSD: dlfcn_elf.c,v 1.8 2011/03/07 05:09:11 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
+#include "reentrant.h"
#include "namespace.h"
+#include <elf.h>
+#include <errno.h>
+#include <string.h>
#undef dlopen
#undef dlclose
@@ -128,11 +132,61 @@
return -1;
}
+static once_t dl_iterate_phdr_once = ONCE_INITIALIZER;
+static const char *dlpi_name;
+static Elf_Addr dlpi_addr;
+static const Elf_Phdr *dlpi_phdr;
+static Elf_Half dlpi_phnum;
+
+/*
+ * Declare as common symbol to allow new libc with older binaries to
+ * not trigger an undefined reference.
+ */
+extern __dso_hidden void *__auxinfo;
+
+static void
+dl_iterate_phdr_setup(void)
+{
+ const AuxInfo *aux;
+
+ if (__auxinfo == NULL)
+ return;
+
+ for (aux = __auxinfo; aux->a_type != AT_NULL; ++aux) {
+ switch (aux->a_type) {
+ case AT_BASE:
+ dlpi_addr = aux->a_v;
+ break;
+ case AT_PHDR:
+ dlpi_phdr = (void *)aux->a_v;
+ break;
+ case AT_PHNUM:
+ dlpi_phnum = aux->a_v;
+ break;
+ case AT_SUN_EXECNAME:
+ dlpi_name = (void *)aux->a_v;
+ break;
+ }
+ }
+}
+
/*ARGSUSED*/
int
dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
void *data)
{
+ struct dl_phdr_info phdr_info;
- return 0;
+ if (__auxinfo == NULL)
+ return EOPNOTSUPP;
+
+ thr_once(&dl_iterate_phdr_once, dl_iterate_phdr_setup);
+
+ memset(&phdr_info, 0, sizeof(phdr_info));
+ phdr_info.dlpi_addr = dlpi_addr;
+ phdr_info.dlpi_phdr = dlpi_phdr;
+ phdr_info.dlpi_phnum = dlpi_phnum;
+ phdr_info.dlpi_name = dlpi_name;
+
+ return callback(&phdr_info, sizeof(phdr_info), data);
}
Index: src/lib/libc/misc/initfini.c
diff -u src/lib/libc/misc/initfini.c:1.7 src/lib/libc/misc/initfini.c:1.8
--- src/lib/libc/misc/initfini.c:1.7 Sun Nov 14 18:11:42 2010
+++ src/lib/libc/misc/initfini.c Mon Mar 7 05:09:11 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: initfini.c,v 1.7 2010/11/14 18:11:42 tron Exp $ */
+/* $NetBSD: initfini.c,v 1.8 2011/03/07 05:09:11 joerg Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,13 +30,17 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: initfini.c,v 1.7 2010/11/14 18:11:42 tron Exp $");
+__RCSID("$NetBSD: initfini.c,v 1.8 2011/03/07 05:09:11 joerg Exp $");
#ifdef _LIBC
#include "namespace.h"
#endif
-void __libc_init(void) __attribute__((__constructor__, __used__));
+#include <sys/param.h>
+#include <sys/exec.h>
+#include <stdbool.h>
+
+void _libc_init(void) __attribute__((__constructor__, __used__));
void __guard_setup(void);
void __libc_thr_init(void);
@@ -44,11 +48,30 @@
void __libc_atexit_init(void);
void __libc_env_init(void);
-/* LINTED used */
+static bool libc_initialised;
+
+void _libc_init(void);
+
+__dso_hidden void *__auxinfo;
+struct ps_strings *__ps_strings;
+
+/*
+ * _libc_init is called twice. The first time explicitly by crt0.o
+ * (for newer versions) and the second time as indirectly via _init().
+ */
void
-__libc_init(void)
+_libc_init(void)
{
+ if (libc_initialised)
+ return;
+
+ libc_initialised = 1;
+
+ if (__ps_strings != NULL)
+ __auxinfo = __ps_strings->ps_argvstr +
+ __ps_strings->ps_nargvstr + __ps_strings->ps_nenvstr + 2;
+
/* For -fstack-protector */
__guard_setup();
Index: src/lib/libc/stdlib/exit.c
diff -u src/lib/libc/stdlib/exit.c:1.13 src/lib/libc/stdlib/exit.c:1.14
--- src/lib/libc/stdlib/exit.c:1.13 Thu Sep 9 10:19:31 2010
+++ src/lib/libc/stdlib/exit.c Mon Mar 7 05:09:12 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: exit.c,v 1.13 2010/09/09 10:19:31 skrll Exp $ */
+/* $NetBSD: exit.c,v 1.14 2011/03/07 05:09:12 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: exit.c,v 1.13 2010/09/09 10:19:31 skrll Exp $");
+__RCSID("$NetBSD: exit.c,v 1.14 2011/03/07 05:09:12 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -45,13 +45,6 @@
#include "atexit.h"
#endif
-#ifdef _LIBC
-extern void __libc_init(void);
-#ifndef __lint
-static void (*force_ref)(void) __used = __libc_init;
-#endif
-#endif
-
void (*__cleanup) __P((void));
/*
Index: src/sys/compat/netbsd32/netbsd32_exec_elf32.c
diff -u src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.32 src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.33
--- src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.32 Mon Dec 14 04:09:38 2009
+++ src/sys/compat/netbsd32/netbsd32_exec_elf32.c Mon Mar 7 05:09:12 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_exec_elf32.c,v 1.32 2009/12/14 04:09:38 mrg Exp $ */
+/* $NetBSD: netbsd32_exec_elf32.c,v 1.33 2011/03/07 05:09:12 joerg Exp $ */
/* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */
/*
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.32 2009/12/14 04:09:38 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.33 2011/03/07 05:09:12 joerg Exp $");
#define ELFSIZE 32
@@ -115,7 +115,7 @@
extern const char machine32[];
(void)compat_elf_check_interp(epp, itp, machine32);
}
- epp->ep_flags |= EXEC_32;
+ epp->ep_flags |= EXEC_32 | EXEC_FORCEAUX;
epp->ep_vm_minaddr = VM_MIN_ADDRESS;
epp->ep_vm_maxaddr = USRSTACK32;
#ifdef ELF_INTERP_NON_RELOCATABLE
Index: src/sys/kern/exec_elf.c
diff -u src/sys/kern/exec_elf.c:1.28 src/sys/kern/exec_elf.c:1.29
--- src/sys/kern/exec_elf.c:1.28 Tue Feb 15 11:43:53 2011
+++ src/sys/kern/exec_elf.c Mon Mar 7 05:09:12 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.28 2011/02/15 11:43:53 pooka Exp $ */
+/* $NetBSD: exec_elf.c,v 1.29 2011/03/07 05:09:12 joerg Exp $ */
/*-
* Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.28 2011/02/15 11:43:53 pooka Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.29 2011/03/07 05:09:12 joerg Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -936,5 +936,6 @@
#elif defined(ELF_INTERP_NON_RELOCATABLE)
*pos = ELF_LINK_ADDR;
#endif
+ epp->ep_flags |= EXEC_FORCEAUX;
return 0;
}