From owner-freebsd-current@FreeBSD.ORG Thu May 10 12:57:04 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE75E106566C; Thu, 10 May 2012 12:57:04 +0000 (UTC) (envelope-from chet.ramey@case.edu) Received: from mpv2.tis.cwru.edu (mpv2.tis.cwru.edu [129.22.105.37]) by mx1.freebsd.org (Postfix) with ESMTP id 645668FC15; Thu, 10 May 2012 12:57:04 +0000 (UTC) Received: from mpv5.cwru.edu (mpv5.tis.CWRU.Edu [129.22.105.51]) by mpv2.tis.cwru.edu (MOS 4.3.3-GA) with ESMTP id BKP42132; Thu, 10 May 2012 08:57:00 -0400 Received: from caleb.INS.CWRU.Edu (EHLO caleb.ins.cwru.edu) ([129.22.8.211]) by mpv5.cwru.edu (MOS 4.3.3-GA FastPath queued) with ESMTP id AXB40090 (AUTH cpr); Thu, 10 May 2012 08:57:00 -0400 (EDT) Message-ID: <4FABBB1B.4080108@case.edu> Date: Thu, 10 May 2012 08:56:59 -0400 From: Chet Ramey User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: Craig Rodrigues , sbruno@freebsd.org References: <1336599447.71431.2.camel@powernoodle-l7> In-Reply-To: X-Enigmail-Version: 1.4.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Junkmail-Whitelist: YES (by domain whitelist at mpv2.tis.cwru.edu) X-Mailman-Approved-At: Thu, 10 May 2012 13:16:47 +0000 Cc: Current FreeBSD , chet.ramey@case.edu Subject: Re: ports/bash4 --enable-static fails X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: chet.ramey@case.edu List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 May 2012 12:57:04 -0000 On 5/10/12 12:20 AM, Craig Rodrigues wrote: > Bash is trying to override the malloc() functions in libc with its own > implementation in lib/malloc/malloc.c . > I have seen this type of trick before 3rd party code that tries to > override the libc implementation of malloc() / free() with its own. > > kan@ explained this to me before, but I don't know if I can explain it > as well as him, because it has to do > with how static linking works. :) > > Basically, the malloc.o object from bash, *must* have implementations of > *all* the relevant functions in jemalloc_jemalloc.o in order for > malloc.o to properly override jemalloc_jemalloc.o. > > If you have something like: > jemalloc_jemalloc.o (libc) malloc.o (Bash) > =============== ============= > malloc() malloc() > free() free() > calloc() > realloc() > > > the static linker will not be able to replace jemalloc_jemalloc.o from > libc with malloc.o from Bash, > because calloc() and realloc() symbols in jemalloc_jemalloc.o (libc) > do not exist malloc.o (Bash). > > Since the linker can only deal with whole objects (.o files), it will > try to pull in both > jemalloc_jemalloc.o and malloc.o when doing static linking. > > I may have got some of the details/explanation wrong, but I have fixed > something similar > to this in 3rd party code, when the layout of malloc() functions in > libc changed between FreeBSD 4 and FreeBSD 6. This explanation is substantially correct. > > What you need to do is: > (1) run nm or readelf on jemalloc_jemalloc.o, then run nm or > readelf on malloc.o > (2) Look at the symbols in both > (3) Add the missing symbols to malloc.c in Bash The bash malloc includes definitions for malloc/free/realloc/calloc/cfree/ valloc/memalign. I'd be interested in knowing what other global symbols jemalloc exports. I'd also be interested in seeing how someone managed to compile the bash malloc and leave out realloc. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/