From owner-freebsd-current@FreeBSD.ORG Thu May 17 22:16:05 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 30A87106566C; Thu, 17 May 2012 22:16:05 +0000 (UTC) (envelope-from seanbru@yahoo-inc.com) Received: from mrout1-b.corp.bf1.yahoo.com (mrout1-b.corp.bf1.yahoo.com [98.139.253.104]) by mx1.freebsd.org (Postfix) with ESMTP id CF9908FC0A; Thu, 17 May 2012 22:16:04 +0000 (UTC) Received: from [IPv6:::1] (rideseveral.corp.yahoo.com [10.73.160.231]) by mrout1-b.corp.bf1.yahoo.com (8.14.4/8.14.4/y.out) with ESMTP id q4HMFXuu053359; Thu, 17 May 2012 15:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yahoo-inc.com; s=cobra; t=1337292935; bh=zcAEacuHtKcOWxwHlIeJdT/p7FrL/1JQcud/F8T8O80=; h=Subject:From:Reply-To:To:Cc:In-Reply-To:References:Content-Type: Date:Message-ID:Mime-Version:Content-Transfer-Encoding; b=FetXTRK+HXFj5vUegVuUXKTcYXt9wnjtZ29TThbxifjxmm2fpcHvrUy6iXrPuk5+W 5agZSKp7pkZEQE89UmV7Gv/o+ZaXieykkP4UA+e1/tPuVhVspLCNlvlg83omvp3we8 Gp8Wb5L2ai7DvCsLK8iIh7MtJZHTdKW+kb/XIo+A= From: Sean Bruno To: "chet.ramey@case.edu" In-Reply-To: <4FABBB1B.4080108@case.edu> References: <1336599447.71431.2.camel@powernoodle-l7> <4FABBB1B.4080108@case.edu> Content-Type: text/plain; charset="UTF-8" Date: Thu, 17 May 2012 15:15:33 -0700 Message-ID: <1337292933.15253.6.camel@powernoodle-l7.corp.yahoo.com> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Milter-Version: master.31+4-gbc07cd5+ X-CLX-ID: 292934000 Cc: Craig Rodrigues , Current FreeBSD Subject: Re: ports/bash4 --enable-static fails X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: sbruno@freebsd.org List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 May 2012 22:16:05 -0000 On Thu, 2012-05-10 at 05:56 -0700, Chet Ramey wrote: > 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 Just to kind of close the loop here, we went ahead and changed our local build of bash to do: ./configure --enable-static-link --without-bash-malloc This matches the ports implementation, so we have moved on here. Sean