From owner-freebsd-current@FreeBSD.ORG Tue Mar 13 12:18:01 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 290B3106566C for ; Tue, 13 Mar 2012 12:18:01 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id AF3EE8FC18 for ; Tue, 13 Mar 2012 12:18:00 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q2DCHrRa083637; Tue, 13 Mar 2012 14:17:53 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q2DCHqV2037178; Tue, 13 Mar 2012 14:17:52 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q2DCHqDv037177; Tue, 13 Mar 2012 14:17:52 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 13 Mar 2012 14:17:52 +0200 From: Konstantin Belousov To: Alexandre Martins Message-ID: <20120313121752.GP75778@deviant.kiev.zoral.com.ua> References: <201203121750.36937.alexandre.martins@netasq.com> <20120312175555.GE75778@deviant.kiev.zoral.com.ua> <201203131108.43815.alexandre.martins@netasq.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Rf8/v0qwcLLbLc6B" Content-Disposition: inline In-Reply-To: <201203131108.43815.alexandre.martins@netasq.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-current@freebsd.org Subject: Re: Double free() in libc or gdb ? 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: Tue, 13 Mar 2012 12:18:01 -0000 --Rf8/v0qwcLLbLc6B Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 13, 2012 at 11:08:40AM +0100, Alexandre Martins wrote: > On Monday 12 March 2012 18:55:55 Konstantin Belousov wrote: > > On Mon, Mar 12, 2012 at 05:50:33PM +0100, Alexandre Martins wrote: > > > Dear all, > > >=20 > > > I'm currently having some trouble with the dynamic loader. > > >=20 > > > I have the libc compilled with "MALLOC_DEBUG" flag to detect double f= ree. > > > When i run this piece of code (attached file) thought GDB, i have this > > > assertion : > > >=20 > > > Assertion failed: ((run->regs_mask[elm] & (1U << bit)) =3D=3D 0), fun= ction > > > arena_run_reg_dalloc, file /usr/src/lib/libc/stdlib/malloc.c, line 25= 43. > > >=20 > > > But when i run the same binary without GDB, no assert. > > >=20 > > > I'm very confused. Can you help me to debug that ? > >=20 > > There is no attachment. Put the source somewhere on web. >=20 > Sorry, I'll past code here : >=20 > first.c: > ____________________ > #include >=20 > void print_name(void) > { > printf("I'm " __FILE__ " at line %d\n", __LINE__); > } > ____________________ >=20 > second.c > ____________________ > #include >=20 > void second_name(void) > { > printf("I'm " __FILE__ " at line %d\n", __LINE__); > } >=20 > void print_name(void) > { > printf("I'm " __FILE__ " at line %d\n", __LINE__); > } > ____________________ >=20 > main.c > ____________________ > #include > #include >=20 > extern void print_name(void); >=20 > int main(int argc, char *argv[]) > { > void (*second_name)(void); > void *handle; > int count =3D 0; >=20 > while(42) > { > print_name(); > handle =3D dlopen("second.so", RTLD_NOW); > print_name(); > if (handle !=3D NULL) > { > second_name =3D dlsym(handle, "second_name"); > if (second_name !=3D NULL) > { > printf("second : "); > second_name(); > } > dlclose(handle); > } > else > fprintf(stderr, "Error : %s\n", dlerror()); > } > } > ____________________ >=20 > Compilation and execution : >=20 > gcc -shared -O0 -g second.c -o second.so > gcc -shared -O0 -g first.c -o libfirst.so > gcc -O0 -g toto.c -lfirst -L. -o test > export LD_LIBRARY_PATH=3D$PWD > gdb ./test >=20 First, the libc malloc is not used inside rtld, so assertion which you see points to somebody else. This somebody could be the stdio in your example, or it could be gdb. On the HEAD r232862, I indeed get the assertion, that obviously comes from gdb. So this is a bug in gdb. Probably, try devel/gdb from ports, I hardly can help you with gdb bug. --Rf8/v0qwcLLbLc6B Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk9fOvAACgkQC3+MBN1Mb4jmzgCgo006UjpbIM1UG6N+2lx99fsU sZMAoIAFj4Z/tdepK7LALe4BsQe7VJaG =GdWI -----END PGP SIGNATURE----- --Rf8/v0qwcLLbLc6B--