unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@protonmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Andrea Corallo <acorallo@gnu.org>,
	eggert@cs.ucla.edu, emacs-devel@gnu.org, stefankangas@gmail.com
Subject: Re: master 8c81818673a 6/7: Tune volatile in read_char
Date: Mon, 19 Aug 2024 15:32:40 +0000	[thread overview]
Message-ID: <87plq4cyuj.fsf@protonmail.com> (raw)
In-Reply-To: <8634n0y2th.fsf@gnu.org>

"Eli Zaretskii" <eliz@gnu.org> writes:

>> From: Andrea Corallo <acorallo@gnu.org>
>> Cc: emacs-devel@gnu.org, eliz@gnu.org, Stefan Kangas <stefankangas@gmail.com>
>> Date: Mon, 19 Aug 2024 10:43:00 -0400
>>
>> Paul Eggert <eggert@cs.ucla.edu> writes:
>>
>> > On 2024-08-18 00:39, Andrea Corallo wrote:
>> >> Has this optimization any measurable effect?
>> >
>> > On my platform (Ubuntu 24.04 LTS, x86-64, gcc -O2) it shrinks the size
>> > of read_char's machine code by 5%.
>>
>> Don't know what the other maintainers think about this but FWIW I don't
>> like this change (and similar ones).  Our codebase is already
>> sufficiently tricky and convoluted, complexifying code for no observable
>> improvements should be IMO out of our goals.
>
> I tend to agree.  Especially given that the rationale for this
> juggling and why exactly we assign and re-assign these two variables
> in those particular places is nowhere to be found, neither in the
> source code nor in the commit log message.

Could we measure the performance impact of making all stack variables in
functions that call setjmp() volatile?

As I pointed out in the bug thread, gcc's -Wclobbered warning doesn't
actually complain about all violations of the C standard, it only
complains about registers that will definitely be clobbered in a
specific build.  As it's unpredictable which build options distributors
will use (in the case of this bug, the combination was "-flto=auto 
-fexceptions".  I don't even know whether -flto=auto results in
reproducible builds!), I think we should do one of these things:

1. make all automatic variables in setjmp()-calling functions volatile,
perhaps with one or two well-documented exceptions
2. default to -Werror=clobbered, which will break distributors' builds
rather than letting them ship broken Emacs versions (as Arch is doing).
3. adapt the GCC analyzer (-fanalyzer, find a machine with enough RAM to
run it on Emacs...) to report ALL instances of potentially clobbered
variables, as it has enough information to do so.

(3) is an "interesting" project, meaning that I looked at the analyzer
code today and have no clue where to even start doing it. (2) is
problematic because distributors will simply remove the -Werror.  So (1)
is our best choice, I'm afraid.

We can add a comment deploring how C pretends setjmp() is an ordinary
function; GCC and clang on POSIX systems don't (and can't) treat it that
way, and on Windows systems things are even more complicated.

Maybe we can even add -Wsetjmp-with-any-nonvolatiles to GCC...

Pip




  reply	other threads:[~2024-08-19 15:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <172386820621.30556.15409337288904485218@vcs2.savannah.gnu.org>
     [not found] ` <20240817041648.A6687C2BC66@vcs2.savannah.gnu.org>
2024-08-17 15:04   ` master 8c81818673a 6/7: Tune volatile in read_char Andrea Corallo
2024-08-17 17:03     ` Pip Cet
2024-08-17 18:16       ` Paul Eggert
2024-08-17 18:17     ` Paul Eggert
2024-08-18  7:39       ` Andrea Corallo
2024-08-18 21:39         ` Paul Eggert
2024-08-18 21:57           ` Sam James
2024-08-18 22:03             ` Paul Eggert
2024-08-19 14:43           ` Andrea Corallo
2024-08-19 15:01             ` Eli Zaretskii
2024-08-19 15:32               ` Pip Cet [this message]
2024-08-19 15:44                 ` Eli Zaretskii
2024-08-19 16:01                   ` Pip Cet
2024-08-19 16:15                     ` Eli Zaretskii
2024-08-19 18:59                       ` Paul Eggert
2024-08-19 19:27                         ` Eli Zaretskii
2024-08-19 19:05                       ` Pip Cet
2024-08-19 19:29                         ` Eli Zaretskii
2024-08-19 19:43                           ` Paul Eggert
2024-08-19 20:08                             ` Pip Cet
2024-08-19 22:20                               ` Paul Eggert
2024-08-19 23:40                                 ` Pip Cet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87plq4cyuj.fsf@protonmail.com \
    --to=pipcet@protonmail.com \
    --cc=acorallo@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).