From owner-svn-src-head@FreeBSD.ORG Fri Dec 6 21:26:58 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9B12D85A; Fri, 6 Dec 2013 21:26:58 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6F67D11F0; Fri, 6 Dec 2013 21:26:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rB6LQw3O035251; Fri, 6 Dec 2013 21:26:58 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rB6LQw7v035250; Fri, 6 Dec 2013 21:26:58 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201312062126.rB6LQw7v035250@svn.freebsd.org> From: Konstantin Belousov Date: Fri, 6 Dec 2013 21:26:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r259042 - head/lib/libc/stdlib X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Dec 2013 21:26:58 -0000 Author: kib Date: Fri Dec 6 21:26:57 2013 New Revision: 259042 URL: http://svnweb.freebsd.org/changeset/base/259042 Log: 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 Analyzed by: dim Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/lib/libc/stdlib/atexit.c Modified: head/lib/libc/stdlib/atexit.c ============================================================================== --- head/lib/libc/stdlib/atexit.c Fri Dec 6 21:22:33 2013 (r259041) +++ head/lib/libc/stdlib/atexit.c Fri Dec 6 21:26:57 2013 (r259042) @@ -151,6 +151,8 @@ __cxa_atexit(void (*func)(void *), void #pragma weak __pthread_cxa_finalize void __pthread_cxa_finalize(const struct dl_phdr_info *); +static int global_exit; + /* * Call all handlers registered with __cxa_atexit for the shared * object owning 'dso'. Note: if 'dso' is NULL, then all remaining @@ -164,10 +166,12 @@ __cxa_finalize(void *dso) struct atexit_fn fn; int n, has_phdr; - if (dso != NULL) + if (dso != NULL) { has_phdr = _rtld_addr_phdr(dso, &phdr_info); - else + } else { has_phdr = 0; + global_exit = 1; + } _MUTEX_LOCK(&atexit_mutex); for (p = __atexit; p; p = p->next) { @@ -177,8 +181,9 @@ __cxa_finalize(void *dso) fn = p->fns[n]; if (dso != NULL && dso != fn.fn_dso) { /* wrong DSO ? */ - if (!has_phdr || !__elf_phdr_match_addr( - &phdr_info, fn.fn_ptr.cxa_func)) + if (!has_phdr || global_exit || + !__elf_phdr_match_addr(&phdr_info, + fn.fn_ptr.cxa_func)) continue; } /* @@ -200,6 +205,6 @@ __cxa_finalize(void *dso) if (dso == NULL) _MUTEX_DESTROY(&atexit_mutex); - if (has_phdr && &__pthread_cxa_finalize != NULL) + if (has_phdr && !global_exit && &__pthread_cxa_finalize != NULL) __pthread_cxa_finalize(&phdr_info); }