From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 10HWHc5YkGCESwAAWB0awg (envelope-from ) for ; Mon, 03 May 2021 16:10:54 -0400 Received: by simark.ca (Postfix, from userid 112) id 726E11F11C; Mon, 3 May 2021 16:10:54 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9B0B21E813 for ; Mon, 3 May 2021 16:10:53 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E04CA3957420; Mon, 3 May 2021 20:10:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E04CA3957420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620072652; bh=7Y5iVPB7e75xgg46bIaDC8260v021sU55gIWORuw3sc=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Jo9GL+UlW6B5tAWTFvmlI0BbsGDt11TaOMZZ6vgYn6bXb9NS4gyuOPldmGRByfnPE f7GQxCTCBSKHXwBAitQyMSILSWeD4N+8Y20MIjBHaTGmAuNic2ZZjGlPbIle5B1+6+ a4nhJT1Xz68Nne6EVxRFL7i+VLRLGthuXyTHTCM4= Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 9D4F339540F2 for ; Mon, 3 May 2021 20:10:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D4F339540F2 Received: from fencepost.gnu.org ([2001:470:142:3::e]:33326) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldeu1-0004Pm-Cy; Mon, 03 May 2021 16:10:49 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=54478 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ldety-0004Sr-TO; Mon, 03 May 2021 16:10:47 -0400 To: Tom de Vries Subject: Re: [PATCH][gdb/guile] Don't allow libguile to change libgmp mem fns References: <20210503085428.GA20738@delia> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 14 =?utf-8?Q?Flor=C3=A9al?= an 229 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Mon, 03 May 2021 22:10:45 +0200 In-Reply-To: <20210503085428.GA20738@delia> (Tom de Vries's message of "Mon, 3 May 2021 10:54:29 +0200") Message-ID: <87sg33vare.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: =?utf-8?q?Ludovic_Court=C3=A8s_via_Gdb-patches?= Reply-To: =?utf-8?Q?Ludovic_Court=C3=A8s?= Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi Tom, Tom de Vries skribis: > The fact that libguile tries to set the libgmp memory functions is a bug = which > should be fixed starting version v3.0.6. Yes. Building Guile with mini-GMP is recommended in 3.0.6 and later. > +++ b/gdb/guile/guile.c > @@ -662,10 +662,32 @@ gdbscm_initialize (const struct extension_language_= defn *extlang) > { > gdb::block_signals blocker; >=20=20 > + /* There are libguile versions (f.i. v3.0.5) that by default call > + mp_get_memory_functions during initialization to install custom > + libgmp memory functions. This is considered a bug and should be > + fixed starting v3.0.6. > + Before gdb commit 880ae75a2b7 "gdb delay guile initialization unt= il > + gdbscm_finish_initialization", that bug had no effect for gdb, > + because gdb subsequently called mp_get_memory_functions to install > + its own custom functions in _initialize_gmp_utils. However, since > + aforementioned gdb commit the initialization order is reversed, > + allowing libguile to install a custom malloc that is incompatible > + with the custom free as used in gmp-utils.c, resulting in a > + "double free or corruption (out)" error. > + Work around the libguile bug by saving the libgmp memory functions > + before guile initialization, and restoring them afterwards. */ > + void *(*alloc_func) (size_t); > + void *(*realloc_func) (void *, size_t, size_t); > + void (*free_func) (void *, size_t); > + mp_get_memory_functions (&alloc_func, &realloc_func, &free_func); > + > /* scm_with_guile is the most portable way to initialize Guile. Plus > we need to initialize the Guile support while in Guile mode (e.g., > called from within a call to scm_with_guile). */ > scm_with_guile (call_initialize_gdb_module, NULL); > + > + /* Restore libgmp memory functions. */ > + mp_set_memory_functions (alloc_func, realloc_func, free_func); This code would lead to memory leaks because Guile would still think it has its memory functions installed so it would never explicitly free GMP memory. Instead, you can do: scm_install_gmp_memory_functions =3D 0; before the first call to =E2=80=98scm_with_guile=E2=80=99. That works with= 3.0, 2.2, and 2.0. HTH! Ludo=E2=80=99.