From owner-svn-src-head@FreeBSD.ORG Tue May 18 08:55:24 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 47051106564A; Tue, 18 May 2010 08:55:24 +0000 (UTC) (envelope-from rdivacky@FreeBSD.org) Received: from svn.freebsd.org (unknown [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 33D9F8FC0A; Tue, 18 May 2010 08:55:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o4I8tO9o097840; Tue, 18 May 2010 08:55:24 GMT (envelope-from rdivacky@svn.freebsd.org) Received: (from rdivacky@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o4I8tOcm097836; Tue, 18 May 2010 08:55:24 GMT (envelope-from rdivacky@svn.freebsd.org) Message-Id: <201005180855.o4I8tOcm097836@svn.freebsd.org> From: Roman Divacky Date: Tue, 18 May 2010 08:55:23 +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: r208256 - in head/libexec/rtld-elf: . amd64 arm i386 powerpc sparc64 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 18 May 2010 08:55:24 -0000 Author: rdivacky Date: Tue May 18 08:55:23 2010 New Revision: 208256 URL: http://svn.freebsd.org/changeset/base/208256 Log: Only use the cache after the early stage of loading. This is because calling mmap() etc. may use GOT which is not set up yet. Use calloc() instead of mmap() in cases where this was the case before (sparc64, powerpc, arm). Submitted by: Dimitry Andric (dimitry andric com) Reviewed by: kan Approved by: ed (mentor) Modified: head/libexec/rtld-elf/amd64/reloc.c head/libexec/rtld-elf/arm/reloc.c head/libexec/rtld-elf/i386/reloc.c head/libexec/rtld-elf/powerpc/reloc.c head/libexec/rtld-elf/rtld.c head/libexec/rtld-elf/sparc64/reloc.c Modified: head/libexec/rtld-elf/amd64/reloc.c ============================================================================== --- head/libexec/rtld-elf/amd64/reloc.c Tue May 18 07:45:27 2010 (r208255) +++ head/libexec/rtld-elf/amd64/reloc.c Tue May 18 08:55:23 2010 (r208256) @@ -118,15 +118,16 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry const Elf_Rela *relalim; const Elf_Rela *rela; SymCache *cache; - int bytes = obj->nchains * sizeof(SymCache); int r = -1; /* * The dynamic loader may be called from a thread, we have * limited amounts of stack available so we cannot use alloca(). */ - cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0); - if (cache == MAP_FAILED) + if (obj != obj_rtld) { + cache = calloc(obj->nchains, sizeof(SymCache)); + /* No need to check for NULL here */ + } else cache = NULL; relalim = (const Elf_Rela *) ((caddr_t) obj->rela + obj->relasize); @@ -322,8 +323,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry } r = 0; done: - if (cache) - munmap(cache, bytes); + if (cache != NULL) + free(cache); return(r); } Modified: head/libexec/rtld-elf/arm/reloc.c ============================================================================== --- head/libexec/rtld-elf/arm/reloc.c Tue May 18 07:45:27 2010 (r208255) +++ head/libexec/rtld-elf/arm/reloc.c Tue May 18 08:55:23 2010 (r208256) @@ -245,7 +245,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry const Elf_Rel *rellim; const Elf_Rel *rel; SymCache *cache; - int bytes = obj->nchains * sizeof(SymCache); int r = -1; /* The relocation for the dynamic loader has already been done. */ @@ -255,10 +254,9 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry * The dynamic loader may be called from a thread, we have * limited amounts of stack available so we cannot use alloca(). */ - cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0); - if (cache == MAP_FAILED) - cache = NULL; - + cache = calloc(obj->nchains, sizeof(SymCache)); + /* No need to check for NULL here */ + rellim = (const Elf_Rel *)((caddr_t)obj->rel + obj->relsize); for (rel = obj->rel; rel < rellim; rel++) { if (reloc_nonplt_object(obj, rel, cache) < 0) @@ -266,9 +264,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry } r = 0; done: - if (cache) { - munmap(cache, bytes); - } + if (cache != NULL) + free(cache); return (r); } Modified: head/libexec/rtld-elf/i386/reloc.c ============================================================================== --- head/libexec/rtld-elf/i386/reloc.c Tue May 18 07:45:27 2010 (r208255) +++ head/libexec/rtld-elf/i386/reloc.c Tue May 18 08:55:23 2010 (r208256) @@ -119,15 +119,16 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry const Elf_Rel *rellim; const Elf_Rel *rel; SymCache *cache; - int bytes = obj->nchains * sizeof(SymCache); int r = -1; /* * The dynamic loader may be called from a thread, we have * limited amounts of stack available so we cannot use alloca(). */ - cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0); - if (cache == MAP_FAILED) + if (obj != obj_rtld) { + cache = calloc(obj->nchains, sizeof(SymCache)); + /* No need to check for NULL here */ + } else cache = NULL; rellim = (const Elf_Rel *) ((caddr_t) obj->rel + obj->relsize); @@ -273,8 +274,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry } r = 0; done: - if (cache) - munmap(cache, bytes); + if (cache != NULL) + free(cache); return(r); } Modified: head/libexec/rtld-elf/powerpc/reloc.c ============================================================================== --- head/libexec/rtld-elf/powerpc/reloc.c Tue May 18 07:45:27 2010 (r208255) +++ head/libexec/rtld-elf/powerpc/reloc.c Tue May 18 08:55:23 2010 (r208256) @@ -287,7 +287,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry const Elf_Rela *relalim; const Elf_Rela *rela; SymCache *cache; - int bytes = obj->nchains * sizeof(SymCache); int r = -1; /* @@ -295,10 +294,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry * limited amounts of stack available so we cannot use alloca(). */ if (obj != obj_rtld) { - cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, - -1, 0); - if (cache == MAP_FAILED) - cache = NULL; + cache = calloc(obj->nchains, sizeof(SymCache)); + /* No need to check for NULL here */ } else cache = NULL; @@ -314,9 +311,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry } r = 0; done: - if (cache) { - munmap(cache, bytes); - } + if (cache != NULL) + free(cache); return (r); } Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Tue May 18 07:45:27 2010 (r208255) +++ head/libexec/rtld-elf/rtld.c Tue May 18 08:55:23 2010 (r208256) @@ -3311,6 +3311,10 @@ allocate_module_tls(int index) } p = malloc(obj->tlssize); + if (p == NULL) { + _rtld_error("Cannot allocate TLS block for index %d", index); + die(); + } memcpy(p, obj->tlsinit, obj->tlsinitsize); memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize); Modified: head/libexec/rtld-elf/sparc64/reloc.c ============================================================================== --- head/libexec/rtld-elf/sparc64/reloc.c Tue May 18 07:45:27 2010 (r208255) +++ head/libexec/rtld-elf/sparc64/reloc.c Tue May 18 08:55:23 2010 (r208256) @@ -254,7 +254,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry const Elf_Rela *relalim; const Elf_Rela *rela; SymCache *cache; - int bytes = obj->nchains * sizeof(SymCache); int r = -1; /* @@ -262,10 +261,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry * limited amounts of stack available so we cannot use alloca(). */ if (obj != obj_rtld) { - cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, - -1, 0); - if (cache == MAP_FAILED) - cache = NULL; + cache = calloc(obj->nchains, sizeof(SymCache)); + /* No need to check for NULL here */ } else cache = NULL; @@ -276,8 +273,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry } r = 0; done: - if (cache) - munmap(cache, bytes); + if (cache != NULL) + free(cache); return (r); }