From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5944 invoked by alias); 16 Aug 2019 08:25:40 -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 5935 invoked by uid 89); 16 Aug 2019 08:25:40 -0000 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 Received: from m0.truegem.net (HELO m0.truegem.net) (69.55.228.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Aug 2019 08:25:29 +0000 Received: (from daemon@localhost) by m0.truegem.net (8.12.11/8.12.11) id x7G8PRcb015640 for ; Fri, 16 Aug 2019 01:25:27 -0700 (PDT) (envelope-from mark@maxrnd.com) Received: from 162-235-43-67.lightspeed.irvnca.sbcglobal.net(162.235.43.67), claiming to be "[192.168.1.100]" via SMTP by m0.truegem.net, id smtpdhlO4WO; Fri Aug 16 01:25:23 2019 Subject: Re: Clang is using the wrong memory model To: 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> From: Mark Geisert Message-ID: <2c0142ad-9cf8-4ab2-472b-36c1611e3e3e@maxrnd.com> Date: Fri, 16 Aug 2019 08:25:00 -0000 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> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2019-08/txt/msg00210.txt.bz2 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