Commit Graph

20 Commits

Author SHA1 Message Date
Konstantin Belousov
760e34772c Fix order of destructors between main binary and libraries.
Since inits for the main binary are run from rtld (for some time), the
rtld_exit atexit(3) handler, which is passed from rtld to the program
entry and installed by csu, is installed after any atexit(3) handlers
installed by main binary constructors.  This means that rtld_exit() is
fired before main binary handlers.

Typical C++ static constructors are executed from init (either binary
or libs) but use atexit(3) to ensure that destructors are called in
the right order, independent of the linking order.  Also, C++
libraries finalizers call __cxa_finalize(3) to flush library'
atexit(3) entries.  Since atexit(3) entry is cleared after being run,
this would be mostly innocent, except that, atexit(rtld_exit) done
after main binary constructors, makes destructors from libraries
executed before destructors for main.

Fix by reordering atexit(rtld_exit) before inits for main binary, same
as it happened when inits were called by csu.  Do it using new private
libc symbol with pre-defined ABI.

Reported. tested, and reviewed by:	kan
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2019-04-15 13:03:09 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Craig Rodrigues
48d59c2270 Remove names from prototypes 2015-09-20 20:15:44 +00:00
Craig Rodrigues
8d3aa83d8b Add declarations to eliminate -Wmissing-prototypes warnings. 2015-09-20 03:53:08 +00:00
David Chisnall
c8aeb6b447 Silence a warning with GCC that was breaking the build with Juniper's GCC.
Reviewed by:	marcel
2014-04-05 08:17:48 +00:00
David Chisnall
46cdc14062 Add support for some block functions that come from OS X. These are
intended to build with any C compiler.

Reviewed by:	pfg
MFC after:	3 weeks
2014-04-02 16:07:48 +00:00
Konstantin Belousov
a7afea4382 Do not force to run atexit handlers, which text comes from a dso
owning the handle passed to __cxa_finalize() but which are registered
by other dso, when the process is inside exit(3).

Running them makes the destruction order wrong, and there is hope that
such destructors would not call dlclose(3), since it is pointless at
this stage of the process existence.

The change effectively disables the r211706 after the exit(3) is
called.

Reported and tested by:	Michael Gmelin <freebsd@grem.de>
Analyzed by:	dim
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2013-12-06 21:26:57 +00:00
Ed Maste
3fb3b97c4d Renumber clauses to reduce diffs to other versions
NetBSD, OpenBSD, and Android's Bionic number the clauses 1 through 3,
so follow suit to make comparison easier.
2013-05-28 20:57:40 +00:00
Konstantin Belousov
3eaca8526c Do not call __pthread_cxa_finalize with invalid struct dl_phdr_info.
Reported and tested by:	Fabian Keil <freebsd-listen fabiankeil de>
MFC after:	17 days
2010-08-27 19:57:17 +00:00
Konstantin Belousov
ea246b6369 On shared object unload, in __cxa_finalize, call and clear all installed
atexit and __cxa_atexit handlers that are either installed by unloaded
dso, or points to the functions provided by the dso.

Use _rtld_addr_phdr to locate segment information from the address of
private variable belonging to the dso, supplied by crtstuff.c. Provide
utility function __elf_phdr_match_addr to do the match of address against
dso executable segment.

Call back into libthr from __cxa_finalize using weak
__pthread_cxa_finalize symbol to remove any atfork handler which
function points into unloaded object.

The rtld needs private __pthread_cxa_finalize symbol to not require
resolution of the weak undefined symbol at initialization time. This
cannot work, since rtld is relocated before sym_zero is set up.

Idea by:	kan
Reviewed by:	kan (previous version)
MFC after:	3 weeks
2010-08-23 15:38:02 +00:00
Konstantin Belousov
aeaffd647e Style.
MFC after:	3 days
2010-08-23 15:18:35 +00:00
Colin Percival
ff847ecb82 In threaded processes, destroy the mutex atexit_mutex when we've
finished using it.  This allows the mutex's allocated memory to be
freed.

This is one sense a rather silly change, since at this point we're
less than a microsecond away from calling _exit; but fixing this
memory leak is likely to make life easier for anyone trying to
track down other memory leaks.
2010-06-13 01:13:36 +00:00
Warner Losh
c879ae3536 Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.
2007-01-09 00:28:16 +00:00
Alexander Kabaev
61cf73b3eb Implement __cxa_atexit/__cxa_finalize as specified by the cross-vendor
C++ ABI document at http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor

The ABI was initially defined for ia64, but GCC3 and Intel compilers
have adopted it on other platforms.

This is the patch from PR bin/59552 with a number of changes by
me.

PR:		bin/59552
Submitted by:	Bradley T Hughes (bhughes at trolltech dot com)
2003-12-19 17:11:20 +00:00
David E. O'Brien
333fc21e3c Fix the style of the SCM ID's.
I believe have made all of libc .c's as consistent as possible.
2002-03-22 21:53:29 +00:00
David E. O'Brien
8fb3f3f682 Remove 'register' keyword. 2002-03-21 18:49:23 +00:00
Tor Egge
df140f7277 When multiple threads call atexit at the same time, some operations must
be serialized.  A mutex is used to protect the critical regions.

sbrk() and brk() are not thread safe.  Replace use of sbrk() with
a call to malloc to avoid race when one thread calls atexit
while another thread calls malloc.

Reviewed by:	deischen
2002-03-05 17:34:37 +00:00
Peter Wemm
4381233dc5 Merge Lite2 changes 1997-03-11 11:39:58 +00:00
Poul-Henning Kamp
fab94ac15b Don't use malloc, pessimize to use sbrk.
fix sbrk manpage while we're at it.
1996-09-27 15:34:19 +00:00
Rodney W. Grimes
58f0484fa2 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00