From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25865 invoked by alias); 16 Aug 2019 09:27:26 -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 25805 invoked by uid 9078); 16 Aug 2019 09:27:25 -0000 Received: (qmail 25785 invoked by uid 89); 16 Aug 2019 09:27:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=unavailable version=3.3.1 spammy= X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (50.116.125.2) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Aug 2019 09:27:23 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 20D5E400CACB4 for ; Fri, 16 Aug 2019 03:52:29 -0500 (CDT) Received: from gator4009.hostgator.com ([192.185.4.20]) by cmsmtp with SMTP id yYW0hitp790onyYW0hXAWY; Fri, 16 Aug 2019 04:27:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=agner.org; s=default; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version :Date:Message-ID:From:References:To:Subject:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SXjMgO8d41obtRgo/6RwAeyhZJmc3UpwgK9rsnj28UQ=; b=EYUSkIlx49IY4lyP36xv9VZ7ec 3JrU0kaM2brkPmkEBTCS41w3NnNSRvZxTPCxHLMl6VEf5CAH+OpUyutfvIX2oDVRyaLJ/7WiPLDKf 8oYsskxDL4RPJC2cONfs+77PlCENUBP0I7hQIfZbcggorpjNDD1Kynu6ObJFIbepyCAuaNBTLEnrf oBpz+3SM/GGkmw9NQzNH6CvqoYessxCgEsfisPILJPcDeQj+O5SWpblnnBZ0V03dsQd4bCnOL7aAP /B5S41R0hCRlx+9uagRVAUIcE/hoV0kZ2txZw3vjXI4G+fceiJPL5X1iYWSxFh0E3hQABV/KO8MY7 COXNOwYw==; Received: from 0190101441.0.fullrate.ninja ([2.110.93.203]:55613 helo=[192.168.1.49]) by gator4009.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1hyYVz-0010GQ-Vu; Fri, 16 Aug 2019 04:27:20 -0500 Subject: Re: Clang is using the wrong memory model To: Corinna Vinschen , "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> <20190816082603.GR11632@calimero.vinschen.de> From: Agner Fog Message-ID: <8d594f4d-17e0-447a-8b18-1ed620815e0f@agner.org> Date: Fri, 16 Aug 2019 09:52:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190816082603.GR11632@calimero.vinschen.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00214.txt.bz2 Message-ID: <20190816095200.R-lVkme0-80_7iXOV1HKVRLCkXJUWbZLN1bHc3unSc8@z> Thanks for your replies. A Cygwin application with -mcmodel=small appears to work fine. As I explained, -mcmodel=small does something else when the target is Windows. It does not require addresses to be below 2GB, it only requires the distance between a code section and it's data section to be below 2GB. Your concern would be right if -mcmodel=small was doing the same thing as it does in Linux, but this is not the case. It does not matter where the application and the Cygwin DLL are placed because Windows allows EXEs and DLLs to be placed at any address. There is no static linking between an application and the Cygwin DLL, so the distance between application and DLL does not matter. I don't see any problem with fork() either, because there is no static link between parent and child process. The OS puts everything in place using virtual addresses. Agner On 16/08/2019 10.26, Corinna Vinschen wrote: > On Aug 16 08:06, Agner Fog wrote: >> Cygwin Clang is using -mcmodel=medium as default for Win64, according to my >> tests, while the right model is -mcmodel=small > -mcmodel=small 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=medium. The reason is the standarized > memory layout of Cygwin application and DLLs. > >> Linux Clang with --target=x86_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=42983 >> >> 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. > 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=small as default) > and Cygwin (at least -mcmodel=medium). > > > Corinna > -- 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