From: Mark Geisert <mark@maxrnd.com>
To: cygwin@cygwin.com
Subject: Re: Clang is using the wrong memory model
Date: Fri, 16 Aug 2019 08:25:00 -0000 [thread overview]
Message-ID: <2c0142ad-9cf8-4ab2-472b-36c1611e3e3e@maxrnd.com> (raw)
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
next prev parent reply other threads:[~2019-08-16 8:25 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 ` Clang is using the wrong memory model Agner Fog
2019-08-16 8:25 ` Mark Geisert [this message]
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=2c0142ad-9cf8-4ab2-472b-36c1611e3e3e@maxrnd.com \
--to=mark@maxrnd.com \
--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).