From owner-freebsd-current@freebsd.org Sat Jan 28 09:39:45 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2C536CC50F6 for ; Sat, 28 Jan 2017 09:39:45 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from mailman.ysv.freebsd.org (unknown [127.0.1.3]) by mx1.freebsd.org (Postfix) with ESMTP id 1BF0110B6 for ; Sat, 28 Jan 2017 09:39:45 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: by mailman.ysv.freebsd.org (Postfix) id 1B4D8CC50F5; Sat, 28 Jan 2017 09:39:45 +0000 (UTC) Delivered-To: current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1AF3DCC50F4 for ; Sat, 28 Jan 2017 09:39:45 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from gw.catspoiler.org (unknown [IPv6:2602:304:b010:ef20::f2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gw.catspoiler.org", Issuer "gw.catspoiler.org" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id EF02010B5 for ; Sat, 28 Jan 2017 09:39:44 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.15.2/8.15.2) with ESMTP id v0S9dYeE024158; Sat, 28 Jan 2017 01:39:38 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <201701280939.v0S9dYeE024158@gw.catspoiler.org> Date: Sat, 28 Jan 2017 01:39:34 -0800 (PST) From: Don Lewis Subject: Re: malloc() call somehow calling the rtld malloc() implementaion To: kostikbel@gmail.com cc: kabaev@gmail.com, current@FreeBSD.org In-Reply-To: <20170127182345.GV2349@kib.kiev.ua> MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 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: Sat, 28 Jan 2017 09:39:45 -0000 On 27 Jan, Konstantin Belousov wrote: > On Fri, Jan 27, 2017 at 12:19:16PM -0500, Alexander Kabaev wrote: >> On Fri, 27 Jan 2017 00:31:30 -0800 (PST) >> Don Lewis wrote: >> > If I create a simple test program that calls malloc() and set a >> > breakpoint in malloc(), the breakpoint gets set in the rtld version, >> > but the the libc version of malloc is what gets called. >> > >> > What the heck is going on here, and how can I fix it? >> > >> >> rtld on my system does not have malloc exposed as dynamic symbol, it >> cannot possibly be used for symbol resolution by any outside module. > > Sure. > > Also, the fact that rtld internal malloc is called does not mean that it > is called by the application. There is no backtrace which would describe > the reason for rtld allocating memory in reported cases. Generally, > rtld needs memory for TLS allocation (the program is definitely linked > with libthr, and even libc uses TLS), and, of course, to create data > structures to track dlopen-ed objects. After adding ports gdb as a RUN_DEPENDS so that it gets installed in the poudriere jail that I was using for debugging, I can confirm that this is exactly what is happening. All of the calls to the rtld version of malloc() happened before main() was entered. Starting slightly before the start of main() and continuing until the eventual SIGBUS, all of the malloc() calls were to the version in libc.