From owner-freebsd-current@FreeBSD.ORG Thu May 10 04:20:13 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 434D1106564A; Thu, 10 May 2012 04:20:13 +0000 (UTC) (envelope-from crodr001@gmail.com) Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id EEDF68FC15; Thu, 10 May 2012 04:20:12 +0000 (UTC) Received: by obcni5 with SMTP id ni5so1638549obc.13 for ; Wed, 09 May 2012 21:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=ekxMBYN6w+MY2/54PPu0T2FuuIUHYWAbPzMrw8qH4cE=; b=Mv1++2C1Q7Myd1lMnwMmOGZN020XPkjui1Hhi9yzdPBaAvJZgX2TLGqS17vRAorr96 xGaikcxbpM9MNIL8+cz/sbnXGUxb7GxKm5Rxq1NlCvYYy0OqYUZSHqSwvvtqMWXu9gHk ++/cfYO2/ld/qb4/83EHj1KVLP6mEzFzElrbcRAN2ndEqJqBH90hGie6xww89we2k8lM RVsLQxD7IGFN6imSUe9ppGmLSOdxbB6t6eUj0JJapnqfVeuC/MctUYiOrcFfB0k7DGXy j8XrMaKFj5PXvsxMZnl+bt0ai046IrXWjAUNSEHGPdE20yasdM/itdSbOfT+Kjwkh6/U 8NhQ== MIME-Version: 1.0 Received: by 10.182.136.4 with SMTP id pw4mr3876851obb.28.1336623610587; Wed, 09 May 2012 21:20:10 -0700 (PDT) Sender: crodr001@gmail.com Received: by 10.182.52.104 with HTTP; Wed, 9 May 2012 21:20:10 -0700 (PDT) In-Reply-To: <1336599447.71431.2.camel@powernoodle-l7> References: <1336599447.71431.2.camel@powernoodle-l7> Date: Wed, 9 May 2012 21:20:10 -0700 X-Google-Sender-Auth: 8oCFOt42Vg-mwVsElNpD_A8x7tU Message-ID: From: Craig Rodrigues To: sbruno@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Cc: Current FreeBSD Subject: Re: ports/bash4 --enable-static fails X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list 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 04:20:13 -0000 On Wed, May 9, 2012 at 2:37 PM, Sean Bruno wrote: > I'm assuming that the recent jemalloc updates have broken something > subtly that is now causing static symbol compilation to fail. > > ports/bash4 isn't the simplest case, but its the most obvious one that > is in my face. > > > http://people.freebsd.org/~sbruno/bash4_jemalloc.txt > Hi, The problem is here: ============================================================================================== ./lib/malloc/libmalloc.a(malloc.o):/usr/ports/shells/bash/work/bash-4.2/lib/malloc/malloc.c:1269: first defined here /usr/lib/libc.a(jemalloc_jemalloc.o): In function `realloc': jemalloc_jemalloc.c:(.text+0x2350): multiple definition of `realloc' ./lib/malloc/libmalloc.a(malloc.o):/usr/ports/shells/bash/work/bash-4.2/lib/malloc/malloc.c:1262: first defined here /usr/lib/libc.a(jemalloc_jemalloc.o): In function `calloc': jemalloc_jemalloc.c:(.text+0x24d0): multiple definition of `calloc' ./lib/malloc/libmalloc.a(malloc.o):/usr/ports/shells/bash/work/bash-4.2/lib/malloc/malloc.c:1294: first defined here /usr/lib/libc.a(jemalloc_jemalloc.o): In function `malloc': jemalloc_jemalloc.c:(.text+0x27a0): multiple definition of `malloc' ./lib/malloc/libmalloc.a(malloc.o):/usr/ports/shells/bash/work/bash-4.2/lib/malloc/malloc.c:1254: first defined here ============================================================================================== 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. 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 -- Craig Rodrigues rodrigc@crodrigues.org