summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/csu/crtbegin.c23
-rw-r--r--lib/libc/Makefile4
-rw-r--r--lib/libc/Symbols.list4
-rw-r--r--lib/libc/hidden/pthread.h25
-rw-r--r--lib/libc/hidden/stdlib.h4
-rw-r--r--lib/libc/stdlib/atexit.c14
-rw-r--r--lib/libc/sys/stack_protector.c16
-rw-r--r--lib/libc/thread/atfork.c19
8 files changed, 78 insertions, 31 deletions
diff --git a/lib/csu/crtbegin.c b/lib/csu/crtbegin.c
index 2917bd38260..37a315d276d 100644
--- a/lib/csu/crtbegin.c
+++ b/lib/csu/crtbegin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbegin.c,v 1.19 2015/04/07 01:27:06 guenther Exp $ */
+/* $OpenBSD: crtbegin.c,v 1.20 2015/11/10 04:14:03 guenther Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -83,27 +83,6 @@ __asm(".hidden __dso_handle");
long __guard_local __dso_hidden __attribute__((section(".openbsd.randomdata")));
-extern int __cxa_atexit(void (*)(void *), void *, void *) __attribute__((weak));
-
-int
-atexit(void (*fn)(void))
-{
- return (__cxa_atexit((void (*)(void *))fn, NULL, NULL));
-}
-
-/*
- * Ditto for pthread_atfork()
- */
-int _thread_atfork(void (*)(void), void (*)(void), void (*)(void), void *)
- __attribute__((weak));
-
-int
-pthread_atfork(void (*prep)(void), void (*parent)(void), void (*child)(void))
-{
- return (_thread_atfork(prep, parent, child, NULL));
-}
-asm(".weak pthread_atfork");
-
static const init_f __CTOR_LIST__[1]
__attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index 7808e7c382a..a0fb9b479bd 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.37 2015/10/25 10:22:09 bluhm Exp $
+# $OpenBSD: Makefile,v 1.38 2015/11/10 04:14:03 guenther Exp $
#
# The YP functions are always in libc. To choose that getpwent() and friends
# actually call the YP functions, put -DYP on the CFLAGS line below.
@@ -9,7 +9,7 @@ LIB=c
CLEANFILES+=tags Symbols.map
CFLAGS+=-Wimplicit
#CFLAGS+=-Werror
-LDADD=-nodefaultlibs -lgcc
+LDADD=-nostdlib -lgcc
VERSION_SCRIPT= Symbols.map
SYMBOL_LISTS= ${LIBCSRCDIR}/Symbols.list \
diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list
index c1b9e261579..2c9c55189ca 100644
--- a/lib/libc/Symbols.list
+++ b/lib/libc/Symbols.list
@@ -7,8 +7,6 @@
*/
/* symbols that no one should be using currently */
-_init
-_fini
__data_start
__bss_start
_edata
@@ -1434,6 +1432,7 @@ __isthreaded
a64l
abort
abs
+atexit
atof
atoi
atol
@@ -1622,6 +1621,7 @@ _thread_mutex_unlock
_thread_tag_lock
_thread_tag_storage
_thread_tag_unlock
+pthread_atfork
/* time */
asctime
diff --git a/lib/libc/hidden/pthread.h b/lib/libc/hidden/pthread.h
new file mode 100644
index 00000000000..c390753a1c2
--- /dev/null
+++ b/lib/libc/hidden/pthread.h
@@ -0,0 +1,25 @@
+/* $OpenBSD: pthread.h,v 1.1 2015/11/10 04:14:03 guenther Exp $ */
+/*
+ * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LIBC_PTHREAD_H_
+#define _LIBC_PTHREAD_H_
+
+#include_next <pthread.h>
+
+PROTO_DEPRECATED(pthread_atfork);
+
+#endif /* !_LIBC_PTHREAD_H_ */
diff --git a/lib/libc/hidden/stdlib.h b/lib/libc/hidden/stdlib.h
index 36e46072c50..0370fb8f5fe 100644
--- a/lib/libc/hidden/stdlib.h
+++ b/lib/libc/hidden/stdlib.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: stdlib.h,v 1.5 2015/10/25 18:01:24 guenther Exp $ */
+/* $OpenBSD: stdlib.h,v 1.6 2015/11/10 04:14:03 guenther Exp $ */
/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */
/*-
@@ -54,7 +54,7 @@ PROTO_NORMAL(abs);
PROTO_NORMAL(arc4random);
PROTO_NORMAL(arc4random_buf);
PROTO_NORMAL(arc4random_uniform);
-/*PROTO_NORMAL(atexit); actually in csu */
+PROTO_NORMAL(atexit);
PROTO_STD_DEPRECATED(atof);
PROTO_NORMAL(atoi);
PROTO_STD_DEPRECATED(atol);
diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c
index a44de37c880..83cc1282a98 100644
--- a/lib/libc/stdlib/atexit.c
+++ b/lib/libc/stdlib/atexit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atexit.c,v 1.23 2015/10/25 18:03:17 guenther Exp $ */
+/* $OpenBSD: atexit.c,v 1.24 2015/11/10 04:14:03 guenther Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
* All rights reserved.
@@ -110,6 +110,18 @@ unlock:
DEF_STRONG(__cxa_atexit);
/*
+ * Copy of atexit() used by libc and anything staticly linked into the
+ * executable. This passes NULL for the dso, so the callbacks are only
+ * invoked by exit() and not dlclose()
+ */
+int
+atexit(void (*fn)(void))
+{
+ return (__cxa_atexit((void (*)(void *))fn, NULL, NULL));
+}
+DEF_STRONG(atexit);
+
+/*
* Call all handlers registered with __cxa_atexit() for the shared
* object owning 'dso'.
* Note: if 'dso' is NULL, then all remaining handlers are called.
diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/sys/stack_protector.c
index e4716f832b6..75c7ef83d79 100644
--- a/lib/libc/sys/stack_protector.c
+++ b/lib/libc/sys/stack_protector.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stack_protector.c,v 1.17 2015/09/10 18:13:46 guenther Exp $ */
+/* $OpenBSD: stack_protector.c,v 1.18 2015/11/10 04:14:03 guenther Exp $ */
/*
* Copyright (c) 2002 Hiroaki Etoh, Federico G. Schwindt, and Miodrag Vallat.
@@ -32,6 +32,20 @@
#include <syslog.h>
#include <unistd.h>
+/*
+ * Note: test below is for PIC not __PIC__. This code must only be included
+ * in the shared library and not in libc.a, but __PIC__ is set for libc.a
+ * objects where PIE is supported
+ *
+ * XXX would this work? #if defined(__PIC__) && !defined(__PIE__)
+ * XXX any archs which are always PIC (like mips64) but don't have PIE?
+ */
+#ifdef PIC
+#include <../csu/os-note-elf.h>
+
+long __guard_local __dso_hidden __attribute__((section(".openbsd.randomdata")));
+#endif /* PIC */
+
void
__stack_smash_handler(const char func[], int damaged)
{
diff --git a/lib/libc/thread/atfork.c b/lib/libc/thread/atfork.c
index e4ae398df5a..09e1c1cef5d 100644
--- a/lib/libc/thread/atfork.c
+++ b/lib/libc/thread/atfork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atfork.c,v 1.1 2015/04/07 01:27:07 guenther Exp $ */
+/* $OpenBSD: atfork.c,v 1.2 2015/11/10 04:14:03 guenther Exp $ */
/*
* Copyright (c) 2008 Kurt Miller <kurt@openbsd.org>
@@ -32,10 +32,15 @@
#include <errno.h>
#include <stdlib.h>
+#include <pthread.h>
#include "thread_private.h"
#include "atfork.h"
+int _thread_atfork(void (*_prepare)(void), void (*_parent)(void),
+ void (*_child)(void), void *_dso);
+PROTO_NORMAL(_thread_atfork);
+
int
_thread_atfork(void (*prepare)(void), void (*parent)(void),
void (*child)(void), void *dso)
@@ -54,3 +59,15 @@ _thread_atfork(void (*prepare)(void), void (*parent)(void),
_ATFORK_UNLOCK();
return (0);
}
+DEF_STRONG(_thread_atfork);
+
+/*
+ * Copy of pthread_atfork() used by libc and anything staticly linked
+ * into the executable. This passes NULL for the dso, so the callbacks
+ * are never removed by dlclose()
+ */
+int
+pthread_atfork(void (*prep)(void), void (*parent)(void), void (*child)(void))
+{
+ return (_thread_atfork(prep, parent, child, NULL));
+}