summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorguenther <>2017-12-16 20:06:56 +0000
committerguenther <>2017-12-16 20:06:56 +0000
commit2eba43d0c1c78cf2d13b896bb9a608c482a585df (patch)
tree2fa5dfadabf13e01a2eeaa103c96c8e3c59c40c9 /src
parentcfcd6a9a82fccae3c7538bacdf933acc3f90fea2 (diff)
downloadopenbsd-2eba43d0c1c78cf2d13b896bb9a608c482a585df.tar.gz
openbsd-2eba43d0c1c78cf2d13b896bb9a608c482a585df.tar.bz2
openbsd-2eba43d0c1c78cf2d13b896bb9a608c482a585df.zip
Move __cxa_thread_atexit* to its own .c file to avoid pulling the code
(w/ _dlctl reference) into static executables. It's all Mark's code so put his preferred copyright on it. ok kettenis@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/Makefile.inc6
-rw-r--r--src/lib/libc/stdlib/atexit.c39
-rw-r--r--src/lib/libc/stdlib/atexit.h9
-rw-r--r--src/lib/libc/stdlib/thread_atexit.c49
4 files changed, 64 insertions, 39 deletions
diff --git a/src/lib/libc/stdlib/Makefile.inc b/src/lib/libc/stdlib/Makefile.inc
index e754e09196..55b8018522 100644
--- a/src/lib/libc/stdlib/Makefile.inc
+++ b/src/lib/libc/stdlib/Makefile.inc
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile.inc,v 1.63 2017/03/24 16:15:31 otto Exp $ 1# $OpenBSD: Makefile.inc,v 1.64 2017/12/16 20:06:55 guenther Exp $
2 2
3# stdlib sources 3# stdlib sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib 4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib
@@ -10,7 +10,9 @@ SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \
10 merge.c posix_pty.c qsort.c radixsort.c rand.c random.c \ 10 merge.c posix_pty.c qsort.c radixsort.c rand.c random.c \
11 realpath.c remque.c setenv.c strtoimax.c \ 11 realpath.c remque.c setenv.c strtoimax.c \
12 strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \ 12 strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \
13 system.c tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c \ 13 system.c \
14 tfind.c thread_atexit.c tsearch.c \
15 _rand48.c drand48.c erand48.c jrand48.c \
14 lcong48.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c \ 16 lcong48.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c \
15 _Exit.c icdb.c 17 _Exit.c icdb.c
16 18
diff --git a/src/lib/libc/stdlib/atexit.c b/src/lib/libc/stdlib/atexit.c
index fe4d5bc79f..ea9dd129c1 100644
--- a/src/lib/libc/stdlib/atexit.c
+++ b/src/lib/libc/stdlib/atexit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: atexit.c,v 1.26 2017/12/05 21:11:10 kettenis Exp $ */ 1/* $OpenBSD: atexit.c,v 1.27 2017/12/16 20:06:56 guenther Exp $ */
2/* 2/*
3 * Copyright (c) 2002 Daniel Hartmeier 3 * Copyright (c) 2002 Daniel Hartmeier
4 * All rights reserved. 4 * All rights reserved.
@@ -31,24 +31,14 @@
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/mman.h> 33#include <sys/mman.h>
34#include <dlfcn.h>
35#include <elf.h>
36#pragma weak _DYNAMIC
37#include <stdlib.h> 34#include <stdlib.h>
38#include <string.h> 35#include <string.h>
36#include <tib.h>
39#include <unistd.h> 37#include <unistd.h>
38
40#include "atexit.h" 39#include "atexit.h"
41#include "atfork.h" 40#include "atfork.h"
42#include "thread_private.h" 41#include "thread_private.h"
43#include "tib.h"
44
45typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
46
47struct thread_atexit_fn {
48 void (*func)(void *);
49 void *arg;
50 struct thread_atexit_fn *next;
51};
52 42
53struct atexit *__atexit; 43struct atexit *__atexit;
54static int restartloop; 44static int restartloop;
@@ -133,29 +123,6 @@ atexit(void (*fn)(void))
133} 123}
134DEF_STRONG(atexit); 124DEF_STRONG(atexit);
135 125
136__weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl);
137
138int
139__cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso)
140{
141 struct thread_atexit_fn *fnp;
142 struct tib *tib = TIB_GET();
143
144 fnp = calloc(1, sizeof(struct thread_atexit_fn));
145 if (fnp == NULL)
146 return -1;
147
148 if (_DYNAMIC)
149 dlctl(NULL, DL_REFERENCE, dso);
150
151 fnp->func = func;
152 fnp->arg = arg;
153 fnp->next = tib->tib_atexit;
154 tib->tib_atexit = fnp;
155
156 return 0;
157}
158
159void 126void
160_thread_finalize(void) 127_thread_finalize(void)
161{ 128{
diff --git a/src/lib/libc/stdlib/atexit.h b/src/lib/libc/stdlib/atexit.h
index d9bfed852f..f2fa7bd83f 100644
--- a/src/lib/libc/stdlib/atexit.h
+++ b/src/lib/libc/stdlib/atexit.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: atexit.h,v 1.11 2017/12/05 13:45:31 kettenis Exp $ */ 1/* $OpenBSD: atexit.h,v 1.12 2017/12/16 20:06:56 guenther Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2002 Daniel Hartmeier 4 * Copyright (c) 2002 Daniel Hartmeier
@@ -41,6 +41,13 @@ struct atexit {
41 } fns[1]; /* the table itself */ 41 } fns[1]; /* the table itself */
42}; 42};
43 43
44/* a chain of these are hung off each thread's TIB's tib_atexit member */
45struct thread_atexit_fn {
46 void (*func)(void *);
47 void *arg;
48 struct thread_atexit_fn *next;
49};
50
44__BEGIN_HIDDEN_DECLS 51__BEGIN_HIDDEN_DECLS
45extern struct atexit *__atexit; /* points to head of LIFO stack */ 52extern struct atexit *__atexit; /* points to head of LIFO stack */
46__END_HIDDEN_DECLS 53__END_HIDDEN_DECLS
diff --git a/src/lib/libc/stdlib/thread_atexit.c b/src/lib/libc/stdlib/thread_atexit.c
new file mode 100644
index 0000000000..2e00428eba
--- /dev/null
+++ b/src/lib/libc/stdlib/thread_atexit.c
@@ -0,0 +1,49 @@
1/* $OpenBSD: thread_atexit.c,v 1.1 2017/12/16 20:06:56 guenther Exp $ */
2/*
3 * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <dlfcn.h>
19#include <elf.h>
20#pragma weak _DYNAMIC
21#include <stdlib.h>
22#include <tib.h>
23
24#include "atexit.h"
25
26typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
27
28__weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl);
29
30int
31__cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso)
32{
33 struct thread_atexit_fn *fnp;
34 struct tib *tib = TIB_GET();
35
36 fnp = calloc(1, sizeof(struct thread_atexit_fn));
37 if (fnp == NULL)
38 return -1;
39
40 if (_DYNAMIC)
41 dlctl(NULL, DL_REFERENCE, dso);
42
43 fnp->func = func;
44 fnp->arg = arg;
45 fnp->next = tib->tib_atexit;
46 tib->tib_atexit = fnp;
47
48 return 0;
49}