diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2001-05-28 21:38:15 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2001-05-28 21:38:15 +0000 |
commit | 0f4ee19637361b907ef00b9b8e60ac559bb95989 (patch) | |
tree | 2cb117b60d3ded48c4ddf4123c480da421af771b /libexec | |
parent | ef3eb9521d508777e6f29b4faad924d844922b58 (diff) |
Commonize csu code for elf systems, powerpc now no longer has it's own
versions of these files.
Fixed a bug in ld.so in this, instead of scheduling the fini of each of
the shared libraries with atexit. schedule a function of ld.so itself
and it will walk all of the open libraries when the program exits.
otherwise a shared library could be dl_open()ed and then dl_close()d
and then it would not be mapped for the atexit processing.
TODO:
What if atexit is not found (process did not link against libc?)
Do shared libraries that are dl_closed have their global destructors run?
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/loader.c | 41 | ||||
-rw-r--r-- | libexec/ld.so/test/Makefile | 10 |
2 files changed, 48 insertions, 3 deletions
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index 5c85b1d7e4b..1267ff23070 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.9 2001/05/14 22:18:19 niklas Exp $ */ +/* $OpenBSD: loader.c,v 1.10 2001/05/28 21:38:14 drahn Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -123,6 +123,31 @@ putc(char c) #endif /* + * Routine to walk thru all of the objects except the first (main executable). + */ + +void +_dl_run_dtors(elf_object_t *object) +{ + if(_dl_debug) + _dl_printf("doing dtors: [%s]\n", object->load_name); + if(object->dyn.fini) { + (*object->dyn.fini)(); + } + if (object->next) { + _dl_run_dtors(object->next); + } +} +void +_dl_dtors() +{ + if(_dl_debug) + _dl_printf("doing dtors\n"); + if (_dl_objects->next) { + _dl_run_dtors(_dl_objects->next); + } +} +/* * This is the dynamic loader entrypoint. When entering here, depending * on architecture type, the stack and registers are set up according * to the architectures ABI specification. The first thing required @@ -244,7 +269,7 @@ _dl_printf("%p %p 0x%lx %p %p\n", argv, envp, loff, dynp, dl_data); _dl_rtld(_dl_objects); /* the first object is the executable itself, - * it is responsible for running it's ctors/dtors + * it is responsible for running it's own ctors/dtors * thus do NOT run the ctors for the executable, all of * the shared libraries which follow. */ @@ -252,6 +277,18 @@ _dl_printf("%p %p 0x%lx %p %p\n", argv, envp, loff, dynp, dl_data); _dl_call_init(_dl_objects->next); } + /* schedule a routine to be run at shutdown, by using atexit. + * cannot call atexit directly from ld.so ?? + */ + { + const Elf_Sym *sym; + Elf_Addr ooff; + + ooff = _dl_find_symbol("atexit", _dl_objects, &sym, 0, 0); + (*(void (*)(Elf_Addr))(sym->st_value + ooff))((Elf_Addr)_dl_dtors); + } + + /* * Finally make something to help gdb when poking around in the code. */ diff --git a/libexec/ld.so/test/Makefile b/libexec/ld.so/test/Makefile index d5dbc4c2e57..2266ad0c2fb 100644 --- a/libexec/ld.so/test/Makefile +++ b/libexec/ld.so/test/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.4 2001/05/14 22:18:23 niklas Exp $ +# $OpenBSD: Makefile,v 1.5 2001/05/28 21:38:14 drahn Exp $ DIR=/usr/src/libexec/ld.so/obj/ld.so .if (${MACHINE_ARCH} != "mips") @@ -46,5 +46,13 @@ libB.so: B.o CCtest: libA.so libB.so tst.o g++ ${LDFLAGS} -o $@ tst.o libB.so libA.so +run: + @echo running CCtest + LD_LIBRARY_PATH=. CCtest + @echo running dltest -l bar -f bar + LD_LIBRARY_PATH=. dltest -l bar -f bar + @echo running dltest -l foo -f foo + LD_LIBRARY_PATH=. dltest -l foo -f foo + .include <bsd.prog.mk> .include <bsd.subdir.mk> |