From: Eli Zaretskii <eliz@gnu.org>
To: martin rudalics <rudalics@gmx.at>
Cc: eggert@cs.ucla.edu, angelo.g0@libero.it, emacs-devel@gnu.org
Subject: Re: Emacs build fails [MSYS2/MINGW64]
Date: Mon, 29 Apr 2019 17:53:27 +0300 [thread overview]
Message-ID: <83imuwual4.fsf@gnu.org> (raw)
In-Reply-To: <d791a219-76ff-d0ac-3ef4-db40c25b6101@gmx.at> (message from martin rudalics on Mon, 29 Apr 2019 14:49:42 +0200)
> From: martin rudalics <rudalics@gmx.at>
> Date: Mon, 29 Apr 2019 14:49:42 +0200
> Cc: emacs-devel@gnu.org
>
> > It seems that it is the optimization flag which causes the issue. Using "-O0" on place of "-O2" or "-O3" in my script fixes the issue...
>
> Same here. See also Bug#35410 for different behaviors of O3 and O0
> builds with gcc 7.3.0 32-bit builds using MSYS2.
So GCC 7.x might also have problems with 'cold'...
I can confirm that building with MinGW GCC 8.2.0 and -O2 causes
crashes in several places during the bootstrap. The crashes that I
saw are different from what Angelo reported, and are also different
from the report in bug#35409, but I guess this is a kind of Heisenbug,
so I'm not surprised to see it pop in different places on different
systems. In one case the cause of the crash was a wrong-type-argument
error where the offending object was a pseudo-vector of the type
PVEC_FREE, i.e. it was already put on the free list; this caused a
print.c function to barf trying to display the object. Clearly, some
bad code was involved, and I suspect that bad code came from GCC, not
from us.
Just applying the simple patch below allows the build to run
flawlessly to completion:
--- src/conf_post.h~0 2019-04-28 09:39:12.000000000 +0300
+++ src/conf_post.h 2019-04-29 08:08:30.619991000 +0300
@@ -225,7 +225,7 @@
extern char *emacs_getenv_TZ (void);
extern int emacs_setenv_TZ (char const *);
-#if __has_attribute (cold)
+#if __has_attribute_cold && !defined(__MINGW32__)
# define ATTRIBUTE_COLD __attribute__ ((cold))
#else
# define ATTRIBUTE_COLD
This could be a MinGW-specific bug, but then again, it could be that
other platforms are just lucky, or maybe not enough people tried to
build the master branch with optimizations lately.
Stepping back a little, I'm not sure we want this ATTRIBUTE_COLD
business in Emacs, on any platform. At the very least, it causes
unintended consequences, see, for example, the comments by Florian
Weimer in this GCC bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88793
Also, the GCC manual indicates that marking a function as 'cold'
causes that function to be optimized for size, and we already know
that GCC 8.x has at least one bug with -Os used together with -O2,
which seems to be exactly what happens when 'cold' is being used in an
otherwise -O2 build.
Moreover, I think we have way too many functions marked with this
attribute. Functions like wrong_type_argument or Fthrow or
Fabort_recursive_edit or Fsignal or error or Ftop_level -- do they
really fit the below description?
The 'cold' attribute on functions is used to inform the compiler
that the function is unlikely to be executed. The function is
optimized for size rather than speed and on many targets it is
placed into a special subsection of the text section so all cold
functions appear close together, improving code locality of
non-cold parts of program. The paths leading to calls of cold
functions within code are marked as unlikely by the branch
prediction mechanism. It is thus useful to mark functions used to
handle unlikely conditions, such as 'perror', as cold to improve
optimization of hot functions that do call marked functions in rare
occasions.
I don't think the above functions are called "rarely" enough in Emacs
to justify marking them as 'cold'. Stuff like emacs_abort or
memory_full, maybe; but functions that jump to top-level are not in
that class, IMO, not in Emacs Lisp.
The problem I see with marking too many functions 'cold' is that then
any path leading to those functions is also considered "unlikely", and
who knows what that does to our code? "nm -A" on an Emacs executable
compiled with ATTRIBUTE_COLD shows no less than 2400(!) local symbols
with the ".cold" suffix, whereas a "normal" executable has just 7 of
them. And what are the benefits we get for all this risky business?
IMO, we should simply avoid this feature. But if we leave it in the
sources, we should disable it for MinGW, it seems.
next prev parent reply other threads:[~2019-04-29 14:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-28 15:37 Emacs build fails [MSYS2/MINGW64] Angelo Graziosi
2019-04-28 16:10 ` Paul Eggert
2019-04-28 16:43 ` Angelo Graziosi
2019-04-29 11:53 ` Angelo Graziosi
2019-04-29 12:49 ` martin rudalics
2019-04-29 14:53 ` Eli Zaretskii [this message]
2019-04-29 19:38 ` Paul Eggert
2019-04-30 15:45 ` Eli Zaretskii
2019-04-30 16:49 ` Paul Eggert
2019-04-30 16:53 ` Eli Zaretskii
2019-05-01 8:28 ` martin rudalics
2019-04-28 16:21 ` Eli Zaretskii
2019-04-28 16:41 ` Angelo Graziosi
2019-04-28 17:30 ` Eli Zaretskii
2019-04-28 21:22 ` Angelo Graziosi
2019-04-28 21:24 ` Angelo Graziosi
2019-04-29 2:29 ` Eli Zaretskii
2019-04-29 14:54 ` Eli Zaretskii
2019-04-28 17:46 ` Stephen Leake
2019-04-29 14:56 ` Eli Zaretskii
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=83imuwual4.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=angelo.g0@libero.it \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=rudalics@gmx.at \
/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).