From owner-svn-src-all@FreeBSD.ORG Sat Oct 8 12:39:47 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CED80106564A; Sat, 8 Oct 2011 12:39:47 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A55B58FC08; Sat, 8 Oct 2011 12:39:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p98CdlbA062985; Sat, 8 Oct 2011 12:39:47 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p98Cdlfx062983; Sat, 8 Oct 2011 12:39:47 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201110081239.p98Cdlfx062983@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 8 Oct 2011 12:39:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226155 - head/libexec/rtld-elf X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 12:39:47 -0000 Author: kib Date: Sat Oct 8 12:39:47 2011 New Revision: 226155 URL: http://svn.freebsd.org/changeset/base/226155 Log: Setting up TLS block for the main thread must be done after the relocations are processed, since tls initialization section might be itself subject for relocations. Only set up of the block is postponed, the tls block offsets are allocated before relocation processing, since TLS-related relocations may need offsets ready. Reported by: ale PR: threads/161344 Reviewed by: kan MFC after: 1 week Modified: head/libexec/rtld-elf/rtld.c Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Sat Oct 8 12:33:10 2011 (r226154) +++ head/libexec/rtld-elf/rtld.c Sat Oct 8 12:39:47 2011 (r226155) @@ -495,8 +495,12 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_ exit (0); } - /* setup TLS for main thread */ - dbg("initializing initial thread local storage"); + /* + * Processing tls relocations requires having the tls offsets + * initialized. Prepare offsets before starting initial + * relocation processing. + */ + dbg("initializing initial thread local storage offsets"); STAILQ_FOREACH(entry, &list_main, link) { /* * Allocate all the initial objects out of the static TLS @@ -504,7 +508,6 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_ */ allocate_tls_offset(entry->obj); } - allocate_initial_tls(obj_list); if (relocate_objects(obj_main, ld_bind_now != NULL && *ld_bind_now != '\0', &obj_rtld, NULL) == -1) @@ -519,6 +522,14 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_ exit (0); } + /* + * Setup TLS for main thread. This must be done after the + * relocations are processed, since tls initialization section + * might be the subject for relocations. + */ + dbg("initializing initial thread local storage"); + allocate_initial_tls(obj_list); + dbg("initializing key program variables"); set_program_var("__progname", argv[0] != NULL ? basename(argv[0]) : ""); set_program_var("environ", env);