Browse Source

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@
OPENBSD_6_3
guenther 6 years ago
parent
commit
ef03f4da40
4 changed files with 64 additions and 39 deletions
  1. +4
    -2
      src/lib/libc/stdlib/Makefile.inc
  2. +3
    -36
      src/lib/libc/stdlib/atexit.c
  3. +8
    -1
      src/lib/libc/stdlib/atexit.h
  4. +49
    -0
      src/lib/libc/stdlib/thread_atexit.c

+ 4
- 2
src/lib/libc/stdlib/Makefile.inc View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile.inc,v 1.63 2017/03/24 16:15:31 otto Exp $
# $OpenBSD: Makefile.inc,v 1.64 2017/12/16 20:06:55 guenther Exp $
# stdlib sources
.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 \
merge.c posix_pty.c qsort.c radixsort.c rand.c random.c \
realpath.c remque.c setenv.c strtoimax.c \
strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \
system.c tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c \
system.c \
tfind.c thread_atexit.c tsearch.c \
_rand48.c drand48.c erand48.c jrand48.c \
lcong48.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c \
_Exit.c icdb.c


+ 3
- 36
src/lib/libc/stdlib/atexit.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: atexit.c,v 1.26 2017/12/05 21:11:10 kettenis Exp $ */
/* $OpenBSD: atexit.c,v 1.27 2017/12/16 20:06:56 guenther Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
* All rights reserved.
@ -31,24 +31,14 @@
#include <sys/types.h>
#include <sys/mman.h>
#include <dlfcn.h>
#include <elf.h>
#pragma weak _DYNAMIC
#include <stdlib.h>
#include <string.h>
#include <tib.h>
#include <unistd.h>
#include "atexit.h"
#include "atfork.h"
#include "thread_private.h"
#include "tib.h"
typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
struct thread_atexit_fn {
void (*func)(void *);
void *arg;
struct thread_atexit_fn *next;
};
struct atexit *__atexit;
static int restartloop;
@ -133,29 +123,6 @@ atexit(void (*fn)(void))
}
DEF_STRONG(atexit);
__weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl);
int
__cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso)
{
struct thread_atexit_fn *fnp;
struct tib *tib = TIB_GET();
fnp = calloc(1, sizeof(struct thread_atexit_fn));
if (fnp == NULL)
return -1;
if (_DYNAMIC)
dlctl(NULL, DL_REFERENCE, dso);
fnp->func = func;
fnp->arg = arg;
fnp->next = tib->tib_atexit;
tib->tib_atexit = fnp;
return 0;
}
void
_thread_finalize(void)
{


+ 8
- 1
src/lib/libc/stdlib/atexit.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: atexit.h,v 1.11 2017/12/05 13:45:31 kettenis Exp $ */
/* $OpenBSD: atexit.h,v 1.12 2017/12/16 20:06:56 guenther Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
@ -41,6 +41,13 @@ struct atexit {
} fns[1]; /* the table itself */
};
/* a chain of these are hung off each thread's TIB's tib_atexit member */
struct thread_atexit_fn {
void (*func)(void *);
void *arg;
struct thread_atexit_fn *next;
};
__BEGIN_HIDDEN_DECLS
extern struct atexit *__atexit; /* points to head of LIFO stack */
__END_HIDDEN_DECLS


+ 49
- 0
src/lib/libc/stdlib/thread_atexit.c View File

@ -0,0 +1,49 @@
/* $OpenBSD: thread_atexit.c,v 1.1 2017/12/16 20:06:56 guenther Exp $ */
/*
* Copyright (c) 2017 Mark Kettenis <kettenis@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.
*/
#include <dlfcn.h>
#include <elf.h>
#pragma weak _DYNAMIC
#include <stdlib.h>
#include <tib.h>
#include "atexit.h"
typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
__weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl);
int
__cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso)
{
struct thread_atexit_fn *fnp;
struct tib *tib = TIB_GET();
fnp = calloc(1, sizeof(struct thread_atexit_fn));
if (fnp == NULL)
return -1;
if (_DYNAMIC)
dlctl(NULL, DL_REFERENCE, dso);
fnp->func = func;
fnp->arg = arg;
fnp->next = tib->tib_atexit;
tib->tib_atexit = fnp;
return 0;
}

Loading…
Cancel
Save