From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#75322: SAFE_ALLOCA assumed to root Lisp_Objects/SSDATA(string) Date: Sun, 05 Jan 2025 11:32:12 +0200 Message-ID: <86ttad8v37.fsf@gnu.org> References: <87jzbbke6u.fsf@protonmail.com> <87a5c6j0qn.fsf@protonmail.com> <86jzbad735.fsf@gnu.org> <877c7aha9n.fsf@protonmail.com> <86y0zqbgot.fsf@gnu.org> <87ttaee5qp.fsf@protonmail.com> <86a5c6b9sb.fsf@gnu.org> <87ikque0xp.fsf@protonmail.com> <864j2dacuz.fsf@gnu.org> <877c79eipq.fsf@protonmail.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21806"; mail-complaints-to="usenet@ciao.gmane.io" Cc: gerd.moellmann@gmail.com, 75322@debbugs.gnu.org To: Pip Cet Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 05 10:33:25 2025 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tUN0e-0005Rl-4l for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Jan 2025 10:33:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUN0K-0000jK-0B; Sun, 05 Jan 2025 04:33:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tUN0I-0000j4-81 for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 04:33:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tUN0H-00052i-VV for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 04:33:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=jVfjYHXm67BasJDRopj0TK9tpYHiM/VXhjsR2qgFKuY=; b=v3xwzETFoA3cd4nh975SWC3f9gHH5QF00MJFWvOtlZw9R2itzDxhXUzhbpYn5hUOlh5pP0vlLQLXb/u6vagSJUUD/we4QpDwDMoUfL9tY6+Jk56ZK+zTjAAew7K6Zpg+7YEmwfCBaLwBFMLmAtSNcf8fU69xt3/kaHGFYAJbi8RjIzJ8RuX3icHEyhDgD2w9InRm8ad8AEgMnmEv7HXTRGz4lsWlOXhh7GRIdUm60t29d8yf2l+2rTp6w2iiwzbJGeJbzgNEGGfI1Ft9ku5IIb52B6HVO4zkisEQZ+ZGYxdpQUmXqZBrzo7tBzDX4F/TPJ1nOiAJrDzP6+s0aFbydA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tUN0H-0007Oh-M7 for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 04:33:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Jan 2025 09:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75322 X-GNU-PR-Package: emacs Original-Received: via spool by 75322-submit@debbugs.gnu.org id=B75322.173606954428365 (code B ref 75322); Sun, 05 Jan 2025 09:33:01 +0000 Original-Received: (at 75322) by debbugs.gnu.org; 5 Jan 2025 09:32:24 +0000 Original-Received: from localhost ([127.0.0.1]:59871 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tUMzf-0007NQ-EK for submit@debbugs.gnu.org; Sun, 05 Jan 2025 04:32:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58422) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tUMzc-0007N6-Qe for 75322@debbugs.gnu.org; Sun, 05 Jan 2025 04:32:22 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tUMzW-000505-L7; Sun, 05 Jan 2025 04:32:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=jVfjYHXm67BasJDRopj0TK9tpYHiM/VXhjsR2qgFKuY=; b=oirDfHi712VD 1u6qRscldyjlAFcIDtBIaKxG9gtDgJSbfnz4/gz1eOOIHgXhyNUnKexQwOekT6q77unzqVx+2Qc9E 7rc32iQUC5hH6vx+IhYagvy5ICQFnZhDj3lQ16nPtRWMO4jT0+vMlCSjf1XG2n/RbiLLk0Y6UG6Db LlNmU2M9tquvP29gAXZ+y5qzaBJ0yIeRmAx+DPefvt6zY7greQ5zG8njn5S5DfH2z7fETfC2BjeTv xsZWGi5NCw2XU8cOwcDgSBRAGjcTz8gz9Z8oByB8hO/WrcOLoYRKTY1Kp+L0ZqXs83IrX6u/ekEPO TQsVPMeutW/AdZqMVIBHqg==; In-Reply-To: <877c79eipq.fsf@protonmail.com> (message from Pip Cet on Sun, 05 Jan 2025 09:04:06 +0000) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:298524 Archived-At: > Date: Sun, 05 Jan 2025 09:04:06 +0000 > From: Pip Cet > Cc: gerd.moellmann@gmail.com, 75322@debbugs.gnu.org > > "Eli Zaretskii" writes: > > we should be able to use without restrictions static variables whose > > values are Lisp strings. > > Without staticpro? That makes no sense whatsoever to me. It's not true > for either garbage collector. Do you expect MPS to scan the entire > data/bss segment ambiguously? That's not relevant to the issue at hand, which was about the following snippet: static Lisp_Object unmarked; ^^^^^^ unmarked = string; ... trigger GC here ... puts (SDATA (unmarked); That 'unmarked' is a static variable is not relevant, because the issue is the pointer to the text data of 'string', which value we put int 'unmarked'. > >> Which might be in a register and not survive until GC is triggered. > > > > A Lisp_Object variable will survive. Its pointer will be updated if > > needed to point to the new location of the data. Thus, using the > > MPS never changes the value of an automatic variable. Exactly! > > Lisp_Object variable is always safe, but the pointer to its data must > > be updated after a potential GC. > > > >> >> > The below is indeed unsafe: > >> >> > > >> >> > char *p = SDATA (unmarked); > >> >> > ... trigger GC here ... > >> >> > puts (p); > >> >> > >> >> Right now, that's safe for MPS, but not for the old GC, correct? > >> > > >> > If GC moves string data, then it is not safe, period. Does MPS move > >> > string data? > >> > >> MPS does not move string data if there is a stack variable pointing to > >> it. It does in other cases. This is why it's safe for MPS. The old > >> GC, IIUC, is less forgiving. > > > > The conclusion is that the above is NOT safe, because in some cases > > the data could move. Which was what I said from the get-go. > > The conclusion is incorrect. The code is safe if MPS is in use, and we > rely on that. No, we do NOT, and should NOT, rely on that! Because you yourself say above that MPS will move the string data in some cases. > The idea behind MPS is that you write code as above, which is safe when > MPS is in use, rather than attempting to avoid GC, which is fragile at > best (see call_process) and impossible in multi-threaded systems. I don't suggest to avoid GC. I suggest that where GC _can_ happen, we must reinitialize the pointer to string data after GC. Otherwise, what was all that discussion about what call_process does with the strings in the args[] array? If GC cannot change the data pointer to SDATA, then why should we care about GC in that function? > You seem to fundamentally disagree with me about how MPS works. We need > to resolve that difference one way or another before we can continue any > GC-related discussions. I have a much larger issue here: this discussion produces an enormous number of long messages without actually leading anywhere. Maybe I'm too stupid to discuss this, but I cannot keep it going like that, it eats up all my free time (of which I don't have too much to be gin with).