From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9003 invoked by alias); 16 Aug 2019 08:26:29 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 8995 invoked by uid 89); 16 Aug 2019 08:26:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-104.2 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=80000000, 7000, 0001, HX-Languages-Length:1972 X-HELO: mout.kundenserver.de Received: from mout.kundenserver.de (HELO mout.kundenserver.de) (212.227.17.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Aug 2019 08:26:19 +0000 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MlO9r-1ii0nJ2ZTh-00lkdz; Fri, 16 Aug 2019 10:26:04 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id 7CE43A80786; Fri, 16 Aug 2019 10:26:03 +0200 (CEST) Date: Fri, 16 Aug 2019 08:26:00 -0000 From: Corinna Vinschen To: Agner Fog Cc: cygwin@cygwin.com Subject: Re: Clang is using the wrong memory model Message-ID: <20190816082603.GR11632@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: Agner Fog , cygwin@cygwin.com References: <732305300.268416262.1565603129541.JavaMail.root@zimbra54-e10.priv.proxad.net> <024ce5b5-6024-b371-e382-5eef5d1d4a90@agner.org> <075477ca-e031-39ea-3dfe-bc8bc2fc8fa6@agner.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mLgg01LDEvurRz8s" Content-Disposition: inline In-Reply-To: <075477ca-e031-39ea-3dfe-bc8bc2fc8fa6@agner.org> User-Agent: Mutt/1.11.3 (2019-02-01) X-SW-Source: 2019-08/txt/msg00211.txt.bz2 --mLgg01LDEvurRz8s Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1969 On Aug 16 08:06, Agner Fog wrote: > Cygwin Clang is using -mcmodel=3Dmedium as default for Win64, according t= o my > tests, while the right model is -mcmodel=3Dsmall -mcmodel=3Dsmall is *only* the right model if the target is native Windows. If the target is a Cygwin application it *must* at least be compiled with -mcmodel=3Dmedium. The reason is the standarized memory layout of Cygwin application and DLLs. > Linux Clang with --target=3Dx86_64-pc-cygwin gives the small memory model. Which is wrong. > I took this to the LLVM Bugzilla as you asked me to: > https://bugs.llvm.org/show_bug.cgi?id=3D42983 >=20 > This gave the following conclusion: >=20 > -mcmodel=3Dsmall does something different when the target is Windows. This > difference appears to be undocumented. The small memory model with a Linux > target puts everything below the 2GB limit so that 32-bit absolute addres= ses > can be used. The small memory model with a Windows target is using 32-bit > relative addresses instead, which is the correct thing to do in Windows. Yes, but not for Cygwin applications and DLLs. The reason is that Cygwin apps and DLLs reside in the memory beyond the first 2 Gigs in a standarized way so as not to collide with Windows code and datastructures. And that in turn was necessary to make fork() more reliable on 64 bit. Here's the memory layout: 0000:00000000 Windows 0000:80000000 Thread stacks 0001:00400000 Executable 0001:80000000 *The* Cygwin DLL 0002:00000000 Rebased Cygwin DLLs 0004:00000000 Unrebased Cygwin DLLs(*) 0006:00000000 Heap (up to Cygwin 3.0) 0008:00000000 Heap (starting with Cygwin 3.1) 0700:00000000 Top-down start address for mmaps up to Windows 8 or up to Cygwin 3.0 7000:00000000 Top-down start address for mmaps starting with Windows 8.1 and Cygwin 3.1 So there's a difference between non-Cygwin (-mcmodel=3Dsmall as default) and Cygwin (at least -mcmodel=3Dmedium). Corinna --=20 Corinna Vinschen Cygwin Maintainer --mLgg01LDEvurRz8s Content-Type: application/pgp-signature; name="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl1WaJsACgkQ9TYGna5E T6DlYw//USTrH/9Z2nRH+BSQIREUhDL/bQcrZcGG5UbrpTrk8Va8hPTD7pccfv7c hJk3G39CbiTYKHnYDC8/E0sTz/Ho6NogezTI0RyPNMfehVVyeIZC5At9W7KeNfTp cESJrDkxoG1na2USEDOGIpS0u4nB9OZ9JZrEdANkZAB0GQJdMfVHJoJO6XeGTKW5 ZK9U8w3bfZ1yGpt5KHYrFYXd1W+A7oIZY1LSXc/DI6ZbPWQ5xZyT6Oi70HUOE5V/ BRaCPbhha2nlWnupmyw4nx8r9stVEDomy9iVRdZuA+Z/QjotKl1+wcGVN5QUhKIn Ufjc9FSAXIL8RDp5xZqDfuqSx3DVXhbLJliuP3SYtXtmZIxLo3HDhLkHwPPnzuAs rNtcSvBN8BAYeLFOSd+1l3dG5mysMIAqojtz54T8y90kF1fsA8JOGdncaLi/XaHl XuSa9olsvODLoF7h5EIxWD67xr8WcT3j2x1jks3rnYGGhsZ/EHGwwHpjvf7tfMgi txjfgYpETtBlkHSPyJkmhNHqVJbZcJhM7aela7l931DLcF+wPZ2CGfIhpEVhq+B3 AY3uFMNzyiz1WyoFDBE6wRlZEzyeyGZwVPomNtERHiJpcPv07jDS2OVZhOZMpmjt m1ltWE2pLGWg7LWoz7w7GbSLh+Te7c+ZnnN3au5VlczF1VzTMRY= =MHnR -----END PGP SIGNATURE----- --mLgg01LDEvurRz8s--