public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Agner Fog <agner@agner.org>
To: cygwin@cygwin.com
Subject: Clang is using the wrong memory model
Date: Fri, 16 Aug 2019 06:06:00 -0000	[thread overview]
Message-ID: <075477ca-e031-39ea-3dfe-bc8bc2fc8fa6@agner.org> (raw)
In-Reply-To: <024ce5b5-6024-b371-e382-5eef5d1d4a90@agner.org>

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

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.

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.

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

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.


On 14/08/2019 07.51, Agner Fog wrote:
> It's a difference in memory model.
>
> clang 6.0.0 under ubuntu with --target=x86_64-pc-cygwin gives relative 
> addresses, unless you specify -mcmodel=large.
>
> Cygwin clang with -mcmodel=small does the right thing: use relative 
> addresses.
>
> The -mcmodel=small option appears to work differently for Linux and 
> for Windows targets. I cannot find any documentation of this 
> difference. See:
>
> https://bugs.llvm.org/show_bug.cgi?id=42983
>
>
> On 12/08/2019 11.45, falk.tannhauser@free.fr wrote:
>> References: <578eb489-9391-9009-82ad-676eeb4c1c92@agner.org>
>> In-Reply-To: <578eb489-9391-9009-82ad-676eeb4c1c92@agner.org>
>>
>> Could the different behaviour between Cygwin and Linux simply be due 
>> to different Clang versions?
>> The current version under Cygwin is 5.0.1, while the latest version 
>> available under Linux
>> appears to be 8.0.1 .
>>
>> Falk
>>
>> -- 
>> 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
>>
>>
>
> -- 
> 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
>
>

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

  reply	other threads:[~2019-08-16  6:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1436640898.268382790.1565602671940.JavaMail.root@zimbra54-e10.priv.proxad.net>
2019-08-12  9:45 ` Inefficient use of 64-bit addresses in Clang falk.tannhauser
2019-08-14  5:51   ` Agner Fog
2019-08-16  6:06     ` Agner Fog [this message]
2019-08-16  8:25       ` Clang is using the wrong memory model Mark Geisert
2019-08-16  8:26       ` Corinna Vinschen
2019-08-16  9:27         ` Agner Fog
2019-08-16  9:52           ` Agner Fog
2019-08-16 10:39           ` Corinna Vinschen
2019-08-16 10:50             ` Agner Fog
2019-08-16 11:25               ` Corinna Vinschen
2019-08-16 13:28                 ` Kai Tietz
2019-08-17  6:59                 ` Agner Fog
2019-08-17  9:48                   ` Corinna Vinschen
2019-08-18 11:37                     ` Agner Fog
2019-08-18 11:58                       ` Corinna Vinschen
2019-08-18 18:14                         ` Agner Fog
2019-08-19  8:58                           ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=075477ca-e031-39ea-3dfe-bc8bc2fc8fa6@agner.org \
    --to=agner@agner.org \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).