unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* clang fails to compile emacs in Microsoft Windows
@ 2023-05-12 14:11 Biswapriyo Nath
  2023-05-12 15:06 ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Biswapriyo Nath @ 2023-05-12 14:11 UTC (permalink / raw)
  To: help-gnu-emacs

* compiler:
clang version 16.0.2
Target: x86_64-w64-windows-gnu
Thread model: posix

* compiler error:

../../src/sysdep.c:472:13: error: call to undeclared function
'waitpid'; ISO C99 and later do not support implicit function
declarations [-Wimplicit-function-declaration]
../../src/sysdep.c:518:43: error: use of undeclared identifier 'WNOHANG'

* Probable reason:

AC_HEADER_SYS_WAIT fails to check sys/wait.h file. It tests with
wait() function which is undefined in nt/inc/sys/wait.h file. Here is
the error message from config.log

configure:11452: checking for sys/wait.h that is POSIX.1 compatible
configure:11479: x86_64-w64-mingw32-cc -I ../nt/inc -c -g3 -O2
-gdwarf-2 -mtune=generic  -D__USE_MINGW_ANSI_STDIO=1 conftest.c >&5
conftest.c:70:3: error: call to undeclared function 'wait'; ISO C99
and later do not support implicit function declarations
[-Wimplicit-function-declaration]

I can provide further information if required. Thank you.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 14:11 clang fails to compile emacs in Microsoft Windows Biswapriyo Nath
@ 2023-05-12 15:06 ` Eli Zaretskii
  2023-05-12 15:47   ` Óscar Fuentes
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-12 15:06 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Biswapriyo Nath <nathbappai@gmail.com>
> Date: Fri, 12 May 2023 19:41:17 +0530
> 
> * compiler:
> clang version 16.0.2
> Target: x86_64-w64-windows-gnu
> Thread model: posix
> 
> * compiler error:
> 
> ../../src/sysdep.c:472:13: error: call to undeclared function
> 'waitpid'; ISO C99 and later do not support implicit function
> declarations [-Wimplicit-function-declaration]
> ../../src/sysdep.c:518:43: error: use of undeclared identifier 'WNOHANG'
> 
> * Probable reason:
> 
> AC_HEADER_SYS_WAIT fails to check sys/wait.h file. It tests with
> wait() function which is undefined in nt/inc/sys/wait.h file. Here is
> the error message from config.log
> 
> configure:11452: checking for sys/wait.h that is POSIX.1 compatible
> configure:11479: x86_64-w64-mingw32-cc -I ../nt/inc -c -g3 -O2
> -gdwarf-2 -mtune=generic  -D__USE_MINGW_ANSI_STDIO=1 conftest.c >&5
> conftest.c:70:3: error: call to undeclared function 'wait'; ISO C99
> and later do not support implicit function declarations
> [-Wimplicit-function-declaration]
> 
> I can provide further information if required. Thank you.

Thanks, but Clang is not supported for building Emacs on MS-Windows.
We only support MinGW GCC.  Unless someone steps up and takes upon
themselves the job of supporting the Clang build, this will remain so.
Supporting the MS-Windows build is hard and thankless job as it is;
adding another compiler on top of that is just too much.

Sorry.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 15:06 ` Eli Zaretskii
@ 2023-05-12 15:47   ` Óscar Fuentes
  2023-05-12 15:59     ` Biswapriyo Nath
  2023-05-12 16:10     ` Eli Zaretskii
  0 siblings, 2 replies; 14+ messages in thread
From: Óscar Fuentes @ 2023-05-12 15:47 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Biswapriyo Nath <nathbappai@gmail.com>
>> Date: Fri, 12 May 2023 19:41:17 +0530
>> 
>> * compiler:
>> clang version 16.0.2
>> Target: x86_64-w64-windows-gnu
>> Thread model: posix
>> 
>> * compiler error:
>> 
>> ../../src/sysdep.c:472:13: error: call to undeclared function
>> 'waitpid'; ISO C99 and later do not support implicit function
>> declarations [-Wimplicit-function-declaration]
>> ../../src/sysdep.c:518:43: error: use of undeclared identifier 'WNOHANG'
>> 
>> * Probable reason:
>> 
>> AC_HEADER_SYS_WAIT fails to check sys/wait.h file. It tests with
>> wait() function which is undefined in nt/inc/sys/wait.h file. Here is
>> the error message from config.log
>> 
>> configure:11452: checking for sys/wait.h that is POSIX.1 compatible
>> configure:11479: x86_64-w64-mingw32-cc -I ../nt/inc -c -g3 -O2
>> -gdwarf-2 -mtune=generic  -D__USE_MINGW_ANSI_STDIO=1 conftest.c >&5
>> conftest.c:70:3: error: call to undeclared function 'wait'; ISO C99
>> and later do not support implicit function declarations
>> [-Wimplicit-function-declaration]
>> 
>> I can provide further information if required. Thank you.
>
> Thanks, but Clang is not supported for building Emacs on MS-Windows.
> We only support MinGW GCC.  Unless someone steps up and takes upon
> themselves the job of supporting the Clang build, this will remain so.
> Supporting the MS-Windows build is hard and thankless job as it is;
> adding another compiler on top of that is just too much.
>
> Sorry.

I think that the problem reported by the OP was introduced recently
(and, by the looks of it, it is problematic not just because of Clang,
but as a C construct, because it seems to rely on an implicit function
declaration. Yes, I've seen the thread on gcc-devel, so no need to
explain things further).

Emacs 28.2 compiles with Clang on Windows with this simple patch:

diff -aur emacs-28.2-orig/configure.ac emacs-28.2/configure.ac
--- emacs-28.2-orig/configure.ac	2022-09-07 06:24:51.000000000 +0800
+++ emacs-28.2/configure.ac	2022-10-09 20:40:07.436552500 +0800
@@ -147,7 +147,7 @@
       fi
       cc_target=`$cc -v 2>&1 | sed -n 's/Target: //p'`
       case "$cc_target" in
-          *-*) host=$cc_target
+          *-*) host=$target_alias
 	      ;;
           "") AC_MSG_ERROR([Impossible to obtain $cc compiler target.
 Please explicitly provide --host.])
@@ -5765,8 +5765,8 @@
   mingw32)
    ## Is it any better under MinGW64 to relocate emacs into higher addresses?
    case "$canonical" in
-     x86_64-*-*) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x400000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
-     *) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x01000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
+     x86_64-*-*) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-image-base,0x400000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
+     *) LD_SWITCH_SYSTEM_TEMACS="-Wl,-stack,0x00800000 -Wl,-image-base,0x01000000 -Wl,-entry,__start -Wl,-Map,./temacs.map" ;;
    esac
    ## If they want unexec, disable Windows ASLR for the Emacs binary
    if test "$with_dumping" = "unexec"; then



and this one for UCRT in general:



--- emacs-28.1/nt/cmdproxy.c.orig	2022-06-23 19:24:10.845481100 +0200
+++ emacs-28.1/nt/cmdproxy.c	2022-06-23 19:24:19.271132900 +0200
@@ -35,6 +35,10 @@
 #include <string.h>  /* strlen */
 #include <ctype.h>   /* isspace, isalpha */
 
+#ifdef _UCRT
+#define _snprintf snprintf
+#endif
+
 /* We don't want to include stdio.h because we are already duplicating
    lots of it here */
 extern int _snprintf (char *buffer, size_t count, const char *format, ...);
--- emacs-28.1/src/sysdep.c.orig	2022-06-23 20:59:02.252891700 +0200
+++ emacs-28.1/src/sysdep.c	2022-06-23 21:05:31.998322600 +0200
@@ -2693,7 +2693,9 @@
   if (close_stream (stdout) != 0)
     {
+#ifndef _UCRT // XXX: close_stream(stdout) fails for some reason
       emacs_perror ("Write error to standard output");
       _exit (EXIT_FAILURE);
+#endif
     }
 
   /* Do not close stderr if addresses are being sanitized, as the
@@ -2702,7 +2704,11 @@
   if (err | (ADDRESS_SANITIZER
 	     ? fflush (stderr) != 0 || ferror (stderr)
 	     : close_stream (stderr) != 0))
+#ifndef _UCRT // XXX: close_stream(stderr) fails for some reason
     _exit (EXIT_FAILURE);
+#else
+    ;
+#endif
 }
 \f
 #ifndef DOS_NT


Those patches are kept in the MSYS2/Mingw-packages repository and we
provide clang-built Emacs 28.x binary packages.

I think that the OP was not requesting support from the Emacs
maintainers specifically, that's why he posted under -help and not under
-devel or -bugs.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 15:47   ` Óscar Fuentes
@ 2023-05-12 15:59     ` Biswapriyo Nath
  2023-05-12 16:03       ` Biswapriyo Nath
  2023-05-12 16:13       ` Eli Zaretskii
  2023-05-12 16:10     ` Eli Zaretskii
  1 sibling, 2 replies; 14+ messages in thread
From: Biswapriyo Nath @ 2023-05-12 15:59 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: ofv, eliz

It does not look like clang only issue. The check with
AC_HEADER_SYS_WAIT also fails in gcc but with a compiler warning as
following.

configure:11452: checking for sys/wait.h that is POSIX.1 compatible
configure:11479: x86_64-w64-mingw32-gcc -I ../nt/inc -c -g3 -O2
-gdwarf-2 -mtune=generic  -D__USE_MINGW_ANSI_STDIO=1 conftest.c >&5
conftest.c: In function 'main':
conftest.c:67:3: warning: implicit declaration of function 'wait'
[-Wimplicit-function-declaration]



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 15:59     ` Biswapriyo Nath
@ 2023-05-12 16:03       ` Biswapriyo Nath
  2023-05-12 16:13       ` Eli Zaretskii
  1 sibling, 0 replies; 14+ messages in thread
From: Biswapriyo Nath @ 2023-05-12 16:03 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: ofv, eliz

On Fri, May 12, 2023 at 9:29 PM Biswapriyo Nath <nathbappai@gmail.com> wrote:
>
> It does not look like clang only issue. The check with
> AC_HEADER_SYS_WAIT also fails in gcc but with a compiler warning as
> following.

Mistake. I meant that the check succeed using gcc but with a compiler warning.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 15:47   ` Óscar Fuentes
  2023-05-12 15:59     ` Biswapriyo Nath
@ 2023-05-12 16:10     ` Eli Zaretskii
  2023-05-12 20:07       ` Óscar Fuentes
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-12 16:10 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Óscar Fuentes <ofv@wanadoo.es>
> Date: Fri, 12 May 2023 17:47:25 +0200
> 
> Those patches are kept in the MSYS2/Mingw-packages repository and we
> provide clang-built Emacs 28.x binary packages.
> 
> I think that the OP was not requesting support from the Emacs
> maintainers specifically, that's why he posted under -help and not under
> -devel or -bugs.

If the MSYS2 project wants to maintain Clang patches, that's fine with
me.  But then these issues are best posted to the MSYS2 forum, not
here.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 15:59     ` Biswapriyo Nath
  2023-05-12 16:03       ` Biswapriyo Nath
@ 2023-05-12 16:13       ` Eli Zaretskii
  1 sibling, 0 replies; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-12 16:13 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Biswapriyo Nath <nathbappai@gmail.com>
> Date: Fri, 12 May 2023 21:29:38 +0530
> Cc: ofv@wanadoo.es, eliz@gnu.org
> 
> It does not look like clang only issue. The check with
> AC_HEADER_SYS_WAIT also fails in gcc but with a compiler warning as
> following.
> 
> configure:11452: checking for sys/wait.h that is POSIX.1 compatible
> configure:11479: x86_64-w64-mingw32-gcc -I ../nt/inc -c -g3 -O2
> -gdwarf-2 -mtune=generic  -D__USE_MINGW_ANSI_STDIO=1 conftest.c >&5
> conftest.c: In function 'main':
> conftest.c:67:3: warning: implicit declaration of function 'wait'
> [-Wimplicit-function-declaration]

It doesn't matter, since the Windows build of Emacs doesn't call
'wait'.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 16:10     ` Eli Zaretskii
@ 2023-05-12 20:07       ` Óscar Fuentes
  2023-05-12 20:10         ` Biswapriyo Nath
  2023-05-13  5:53         ` Eli Zaretskii
  0 siblings, 2 replies; 14+ messages in thread
From: Óscar Fuentes @ 2023-05-12 20:07 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> Those patches are kept in the MSYS2/Mingw-packages repository and we
>> provide clang-built Emacs 28.x binary packages.
>> 
>> I think that the OP was not requesting support from the Emacs
>> maintainers specifically, that's why he posted under -help and not under
>> -devel or -bugs.
>
> If the MSYS2 project wants to maintain Clang patches, that's fine with
> me.  But then these issues are best posted to the MSYS2 forum, not
> here.

Why? Here is the people that hack and build Emacs on a regular basis,
right?

Please note that the problem on the OP is not related to the patches.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 20:07       ` Óscar Fuentes
@ 2023-05-12 20:10         ` Biswapriyo Nath
  2023-05-13  6:00           ` Eli Zaretskii
  2023-05-13  5:53         ` Eli Zaretskii
  1 sibling, 1 reply; 14+ messages in thread
From: Biswapriyo Nath @ 2023-05-12 20:10 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Óscar Fuentes, eliz

Adding the wait() declaration in nt/inc/sys/wait.h fixes the issue.
May I send the patch here or in other mailing list?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 20:07       ` Óscar Fuentes
  2023-05-12 20:10         ` Biswapriyo Nath
@ 2023-05-13  5:53         ` Eli Zaretskii
  2023-05-13 12:39           ` Óscar Fuentes
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-13  5:53 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Óscar Fuentes <ofv@wanadoo.es>
> Date: Fri, 12 May 2023 22:07:23 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > If the MSYS2 project wants to maintain Clang patches, that's fine with
> > me.  But then these issues are best posted to the MSYS2 forum, not
> > here.
> 
> Why? Here is the people that hack and build Emacs on a regular basis,
> right?
> 
> Please note that the problem on the OP is not related to the patches.

It is related to a configuration that isn't officially supported.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-12 20:10         ` Biswapriyo Nath
@ 2023-05-13  6:00           ` Eli Zaretskii
  2023-05-13  7:21             ` Biswapriyo Nath
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-13  6:00 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Biswapriyo Nath <nathbappai@gmail.com>
> Date: Sat, 13 May 2023 01:40:11 +0530
> Cc: Óscar Fuentes <ofv@wanadoo.es>, eliz@gnu.org
> 
> Adding the wait() declaration in nt/inc/sys/wait.h fixes the issue.

That's not the right solution for this issue, though, IMO.  Adding
that declaration is only TRT if you also add some implementation of
'wait' to one of the w32*.c files.

The problem here is that the configure script rejects the sys/wait.h
header we provide for MS-Windows because it deduces it isn't
Posix-compliant enough.  That is the problem to fix: convince the
configure script that our sys/wait.h is fine (which it is, since it
does everything the MS-Windows build needs from it).  The right means
for doing so is the nt/mingw-cfg.site file, where you need to add

  ac_cv_header_sys_wait_h=yes

This will cause this test to succeed unconditionally, which is what we
need.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-13  6:00           ` Eli Zaretskii
@ 2023-05-13  7:21             ` Biswapriyo Nath
  0 siblings, 0 replies; 14+ messages in thread
From: Biswapriyo Nath @ 2023-05-13  7:21 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Eli Zaretskii, Óscar Fuentes

Thank you for the suggestion. I should keep that patch in downstream
repository then.

Just for the record.
* The actual issue was reported here
https://github.com/msys2/MINGW-packages/issues/17117
* The patch may be added here
https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-emacs



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-13  5:53         ` Eli Zaretskii
@ 2023-05-13 12:39           ` Óscar Fuentes
  2023-05-13 12:46             ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Óscar Fuentes @ 2023-05-13 12:39 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> > If the MSYS2 project wants to maintain Clang patches, that's fine with
>> > me.  But then these issues are best posted to the MSYS2 forum, not
>> > here.
>> 
>> Why? Here is the people that hack and build Emacs on a regular basis,
>> right?
>> 
>> Please note that the problem on the OP is not related to the patches.
>
> It is related to a configuration that isn't officially supported.

Last time I looked the configure script had references to ancient
propietary compilers and systems that are not in use for decades. But
adding a trivial fix for a Free toolset on a Free software distribution
for the most widely used OS that *also improves support for gcc by
eliminating a warning* is not acceptable.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: clang fails to compile emacs in Microsoft Windows
  2023-05-13 12:39           ` Óscar Fuentes
@ 2023-05-13 12:46             ` Eli Zaretskii
  0 siblings, 0 replies; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-13 12:46 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Óscar Fuentes <ofv@wanadoo.es>
> Date: Sat, 13 May 2023 14:39:16 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> > If the MSYS2 project wants to maintain Clang patches, that's fine with
> >> > me.  But then these issues are best posted to the MSYS2 forum, not
> >> > here.
> >> 
> >> Why? Here is the people that hack and build Emacs on a regular basis,
> >> right?
> >> 
> >> Please note that the problem on the OP is not related to the patches.
> >
> > It is related to a configuration that isn't officially supported.
> 
> Last time I looked the configure script had references to ancient
> propietary compilers and systems that are not in use for decades.

Which ones?

> But adding a trivial fix for a Free toolset on a Free software
> distribution for the most widely used OS that *also improves support
> for gcc by eliminating a warning* is not acceptable.

You have completely misunderstood and misinterpreted what I wrote.



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-05-13 12:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-12 14:11 clang fails to compile emacs in Microsoft Windows Biswapriyo Nath
2023-05-12 15:06 ` Eli Zaretskii
2023-05-12 15:47   ` Óscar Fuentes
2023-05-12 15:59     ` Biswapriyo Nath
2023-05-12 16:03       ` Biswapriyo Nath
2023-05-12 16:13       ` Eli Zaretskii
2023-05-12 16:10     ` Eli Zaretskii
2023-05-12 20:07       ` Óscar Fuentes
2023-05-12 20:10         ` Biswapriyo Nath
2023-05-13  6:00           ` Eli Zaretskii
2023-05-13  7:21             ` Biswapriyo Nath
2023-05-13  5:53         ` Eli Zaretskii
2023-05-13 12:39           ` Óscar Fuentes
2023-05-13 12:46             ` Eli Zaretskii

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).