delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/08/16/04:26:35

X-Recipient: archive-cygwin AT delorie DOT 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:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=FMVue8hhR91L1aBT
p/2PgzRxdDJPAwcnV2OKW2KBd2fcpQg4IjOCjnxlVATqeH3DpRivFeMHUoPF2Z3H
zIJteyZPbFhI2saQUL+hSzA7EiIHSna6Ofuiocl0fwM9Ao7U5g9l70/Na2OCdk0N
lQtGKzLuLlzHTSt+RfsgZRxJ9Ec=
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:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=ZSnzkwfka4GvtRs/fy2Pgp
+Y9bA=; b=vsVvpfi0+xjArpGwZhE2AMiQ0JRsClaxhuohF5nlFP+dy9/OqUloVv
NJpGgDHLAD77KhRqb7DOl34x5l/sY1tkbIqQj6mw/eccTVUGZ96Or7CsM3tIeKDN
mcuHQKBL4qVmqMlVOFU9cPXdAKiIeNX3gj+vkgyeo+lMVSp2QfsWE=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.1 spammy=replying, our
X-HELO: m0.truegem.net
Subject: Re: Clang is using the wrong memory model
To: cygwin AT cygwin DOT com
References: <732305300 DOT 268416262 DOT 1565603129541 DOT JavaMail DOT root AT zimbra54-e10 DOT priv DOT proxad DOT net> <024ce5b5-6024-b371-e382-5eef5d1d4a90 AT agner DOT org> <075477ca-e031-39ea-3dfe-bc8bc2fc8fa6 AT agner DOT org>
From: Mark Geisert <mark AT maxrnd DOT com>
Message-ID: <2c0142ad-9cf8-4ab2-472b-36c1611e3e3e@maxrnd.com>
Date: Fri, 16 Aug 2019 01:25:22 -0700
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4
MIME-Version: 1.0
In-Reply-To: <075477ca-e031-39ea-3dfe-bc8bc2fc8fa6@agner.org>

Hi, please don't start a new Subject: by replying on another thread.  It fouls 
up mail threading for folks trying to follow multiple threads.  Just start a new 
thread with your new Subject:.  Thanks.

Agner Fog wrote:
> Cygwin Clang is using -mcmodel=medium as default for Win64, according to my 
> tests, while the right model is -mcmodel=small
> 
> Linux Clang with --target=x86_64-pc-cygwin gives the small memory model.
> 
> I took this to the LLVM Bugzilla as you asked me to: 
> https://bugs.llvm.org/show_bug.cgi?id=42983

Disclaimer: I am not a Cygwin maintainer or the Cygwin Clang maintainer.  This 
is a general Cygwin users' mailing list, not a private support channel.  I'm 
just some guy on the list, albeit somebody interested in solving your issue.

Cygwin is not Windows.  Cygwin's shared libraries are more than 32 bits distant 
from executables you build.  -mcmodel=small won't work.  There may be a better 
-mcmodel setting, TBD, but small isn't it, unfortunately.

The reasons are longstanding and technical.  The quick version is that there are 
thousands of different DLLs that a Cygwin user might want installed on their 
system.  Cygwin is a Posix environment, and to support fork() the address space 
for those DLLs is chosen to avoid Windows interference, so much as possible.

> This gave the following conclusion:
> 
> -mcmodel=small 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 addresses 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.
> 
> I told the LLVM guy that this difference needs to be documented so that you can 
> rely on it, but this request has so far been ignored.
> 
> He says that you must have modified the source code to change the default memory 
> model.

Now that I've downloaded and unpacked the Clang source tree, I can confirm we 
have a patch to set -mcmodel=medium on 64-bit Cygwin; it's left at small for 
32-bit Cygwin.

> The medium memory model gives inefficient code because it uses an extra 
> instruction to load a 64-bit absolute address into a register before every 
> access to static data.

My understanding is that Clang makes an attempt to accept all the same options 
as gcc.  Could you please try your Clang build with option "-mcmodel=small"?  I 
suspect the link phase won't work because the Clang runtime library is more than 
32 bits away from your executable's code.  You might try another -mcmodel 
setting.  I don't know what all of them are.

First step is just getting the thing to link.  Then testing whether it works 
properly.  Then code efficiency :-).

> I cannot blame you Cygwin people for not using the small memory model as long as 
> it is undocumented.

The necessary reason for our patch was explained above.

> I will ask you to please join the discussion at 
> https://bugs.llvm.org/show_bug.cgi?id=42983 so that we can clarify how to solve 
> this problem.

This issue does now appear to be an issue with Cygwin's Clang build, so let's 
keep discussing here.  We can sync up with the LLVM bugtracker later on.

BTW is it a goal to be building for Cygwin?  Or is it that you want 
Windows-native executables built with Cygwin tools?  If the latter, there are 
cross-compilers provided by Cygwin that can do that.  I don't think there's a 
Clang for that situation yet, though.

..mark

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019