From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?Nicolas_B=C3=A9rtolo?= Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] [WIP] Port feature/native-comp to Windows. Date: Sun, 10 May 2020 13:36:18 -0300 Message-ID: References: <5eb5b953.1c69fb81.a67ce.a764@mx.google.com> <83lfm1hc91.fsf@gnu.org> <83wo5lds87.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0000000000002914b205a54dd5a1" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="31369"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, Andrea Corallo To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 10 18:37:21 2020 Return-path: Envelope-to: ged-emacs-devel@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 1jXox6-00085L-D4 for ged-emacs-devel@m.gmane-mx.org; Sun, 10 May 2020 18:37:20 +0200 Original-Received: from localhost ([::1]:50176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jXox4-0003hZ-VD for ged-emacs-devel@m.gmane-mx.org; Sun, 10 May 2020 12:37:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXowM-00039T-97 for emacs-devel@gnu.org; Sun, 10 May 2020 12:36:34 -0400 Original-Received: from mail-oo1-xc2c.google.com ([2607:f8b0:4864:20::c2c]:35509) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jXowL-0001C5-8f; Sun, 10 May 2020 12:36:33 -0400 Original-Received: by mail-oo1-xc2c.google.com with SMTP id c187so49447ooc.2; Sun, 10 May 2020 09:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5tv6EPyYiW78redogaRYbN6Rq/El1d2WF/xzDCNMhmo=; b=tKFmotNNYtZle0hlpQmZ3WTOJA1+JiuwDRgPBK7I0zP6sOevl6JYG8eHHa6whYaW4u R+mBWX/dAoCkK6Fc/YFEJbn1dCCT9aSAYkKRflm+8Qc+EJ4JgpBFeNFYMIcTingVNecu +IbrKaJY/KVznpNlpiPiWAXjBFg5SVUAWWH1y9NDXGZQqxjv3Zp4Gu3ah3YCt4qbjN5y SNi1Jow6ZT7PteHE2kjSBfoJBOI9gAlfDYHWdQ6C3/oKm/B18QBTsymJiMPcXBpmvgFI bpO9vlE9RHi8BI6IhaLvINHC3DrwEeaWIaF0tpgJVo+hZd3fn+y/W0PwuFlFs989Cr2G 2r/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5tv6EPyYiW78redogaRYbN6Rq/El1d2WF/xzDCNMhmo=; b=p4i5Yg6pW43dp1YhE8WHeSkjD30MXXjtqYkTSmt/B+Z3bD8bdHMaaEbdQZ0Xvb/RqC ydx9rcy8w8rLlW1Z6L6GzxafnzrBuxeGGxLXhviUTEmR/8XdeC/urSj9oj1IiuTw6wy8 hYA1eew2GLQROBEmi8m9xq+dkNfFSB+IWBY3IJ4hUfZENB9A/+f4nVMVc6u6YVcNPZPJ 0i0fImR7imlVY89BSJ+rmBZjUZnb49Z5gWDKabck7MZTRG7X7onNEYhkoEgIf1tS/kYH OhNk4lpvT8KRkFOSUyjpOIvUStjPyo9xWdkZ0bVuDyMafLiwHDx7OylkhgMG9dBTuWIf EdXQ== X-Gm-Message-State: AGi0Pua6zPQngDOC+36+26zzY+cUaWpsE5YPyzCCsAaoYpuvUy61ks9z VMfji15N7WLHiKyhqcf9KFTnz8DbCHmS3033+QGetvnECAmMXw== X-Google-Smtp-Source: APiQypLUDMkCQUyQrW+U3EJkCiRThOUlO3bfp15wgGvYQnzx3T4KkliQqToz9Ym02yucuJmjKkrW/+f1HWu4e96zDQo= X-Received: by 2002:a4a:ad0d:: with SMTP id r13mr10634198oon.22.1589128590848; Sun, 10 May 2020 09:36:30 -0700 (PDT) In-Reply-To: <83wo5lds87.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::c2c; envelope-from=nicolasbertolo@gmail.com; helo=mail-oo1-xc2c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:249672 Archived-At: --0000000000002914b205a54dd5a1 Content-Type: text/plain; charset="UTF-8" > This could have issues with setjmp, I think. Exactly. >> There are many ways to call setjmp() in Windows. It depends on the architecture, >> whether the Universal CRT is used, whether SEH is enabled, the compiler version, >> etc. > Yes, I know. But we need to support only the way we compile Emacs, > right? Yes, but how do we get that information at build time? An automatic solution would be to call `gcc -E` with something like this: #include jmp_buf buf; void func() { setjmp(buf); } And then parse the results to see what the setjmp() gets translated into by the preprocessor. It is a lot of work, that why I suggested doing it with autoconf somehow. > And similarly with ld.exe and any other program that GCC needs to > invoke as party of the compilation. Can we use that instead of adding > directories to PATH? In fact, I wonder how does the > native-compilation branch solve this for GNU/Linux systems, if not > like that? gccjit lets us add options to the command line it feeds its internal copy of GCC. The option "-B path" can be used to define the path where a gcc installation lives. In GNU/Linux the branch relies on the gcc installation being in the standard path. That is: libgccjit uses the same logic as gcc to find its binaries and support libraries (this is why the "-B" switch works). > Sounds like something is broken in the MinGW libgccjit port? It seems > not to pass the correct -L switch to the compiler, or something along > those lines? Does libgccjit has the equivalent of the -v switch, > which would show the complete commands used to compile? It can be fixed with the "-B" switch. > You are right when you say that they are native Windows programs. They don't > need a "pseudo-unix" environment like I said previously. But they need some > support files from the MSYS installation. I haven't figured out which ones yet. > Well, please try to figure that out, and let us know if we can help > you in that task. Once we understand the issues, we could think about > solving them. I think I found a solution. We can setup a "stub gcc installation" in the directory where Emacs is installed. It should be like this: configure --prefix: - bin/ - emacs.exe - etc - lib/gcc/x86_64-w64-mingw32/10.0.0: - as.exe - collect2.exe - ld.exe - crtbegin.o - crtend.o - dllcrt2.o - libgcc.a - libkernel32.a - libmingw32.a - libmingwex.a - libmsvcrt.a The actual name of the directories could be obtained through autoconf and the files can be copied from the GCC used to build Emacs. This is the minimal set of files required to build an eln file. They are necessary to initialize the CRT in the DLL. Given that the generated code does not use the CRT, I think we can further reduce the set of libraries used. This would require adding a function called `DllMainCRTStartup` to the generated code. It would do nothing, instead of setting up the CRT. There is an issue with this approach: this function would need to be generated with the __stdcall calling convention and there is no way in libgccjit to specify that. It could be solved using a small object file compiled during the Emacs build process and then put in the "stub GCC installation". What do you think? The attached patch sets up libgccjit to find libraries and binaries in the "stub GCC installation". Nicolas --0000000000002914b205a54dd5a1 Content-Type: application/octet-stream; name="0007-Set-the-libraries-linked-against-native-lisp-modules.patch" Content-Disposition: attachment; filename="0007-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