X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:cc:subject:message-id:reply-to
	:references:mime-version:content-type:in-reply-to; q=dns; s=
	default; b=xTdTtQeCv5CPcQjipgC1NayaV+8NKs20bueweuLkLkoW65U+/aeY4
	XDN7yrNMCgjiTf3b4efxbvoRv7Ho44gA9CQFJJr5WfgpDc7tcKKWu4MLe+TXlARy
	tAjH3cDaSNJ7/Bts/WoJXk6gF8/GhxV5MFKoekarWoWgSHKI81zyyI=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:cc:subject:message-id:reply-to
	:references:mime-version:content-type:in-reply-to; s=default;
	 bh=i6Z2ZGdjavUxWA+ot8F0d2sCA0o=; b=YPJDBYPeKJ4eOnVjb1FJkFpuJb1d
	h/Jh70uZjL8Zi+YqYOkk5LdTUxCr9MzdLnauU3TORG4s5yxERX7ijBQG4w6EMeza
	MCn1b2//GILzsPmNb83F3WrKd9yJ+VaykgmV2M8Q69S1emj6oD+DwTyMkCzVVFCm
	IQbIfP7VO1RuyKI=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
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
Date: Fri, 16 Aug 2019 10:26:03 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: Agner Fog <agner@agner.org>
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 <agner@agner.org>, 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)

--mLgg01LDEvurRz8s
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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"

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