public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: cpp /usr/include/threads.h fails; modfl segfaults
Date: Mon, 31 Aug 2020 13:24:13 -0600	[thread overview]
Message-ID: <140d7709-7db0-6935-15c1-786d392d0f53@SystematicSw.ab.ca> (raw)
In-Reply-To: <20200831184517.GF3272@calimero.vinschen.de>

[-- Attachment #1: Type: text/plain, Size: 4031 bytes --]

On 2020-08-31 12:45, Corinna Vinschen wrote:
> On Aug 31 09:37, Brian Inglis wrote:
>> On 2020-08-31 01:35, Corinna Vinschen wrote:
>>> On Aug 30 14:39, Brian Inglis wrote:
>>>> On 2020-08-30 07:00, Corinna Vinschen wrote:
>>>>> On Aug 29 08:52, airplanemath via Cygwin wrote:
>>>>>> I have two reports.  A brief description of the system:
>>>>>> $ uname -a | sed "s/${HOSTNAME}/\${HOSTNAME}/g"
>>>>>> CYGWIN_NT-10.0 ${HOSTNAME} 3.1.7(0.340/5/3) 2020-08-22 17:48 x86_64 Cygwin
>>>> ...
>>>>>> $ cat test.c
>>>>>> #include <math.h>
>>>>>> #include <stdio.h>
>>>>>> #include <stdlib.h>
>>>>>>
>>>>>> int main(int argc, char *argv[]) {
>>>>>>   long double a, b, c;
>>>>>>   char *num_end = NULL;
>>>>>>   a = b = c = 0.0L;
>>>>>>   if (argc != 2) {
>>>>>>     fprintf(stderr, "Usage: %s NUMBER\n", argv[0]);
>>>>>>     exit(1);
>>>>>>   }
>>>>>>   a = strtold(argv[1], &num_end);
>>>>>>   b = modfl(a, &c);
>>>>>>   printf("%Lf %Lf %Lf\n", a, b, c);
>>>>>>   return 0;
>>>>>> }
>>>>>
>>>>> This is a bug in the assembler code taken from Mingw-w64.  The bug has
>>>>> been fixed upstream, so I just pulled in the upstream fixes.
>>>>
>>>> The 64 bit fix doesn't pop eax but *now* flags eax as clobbered, whereas the 32
>>>> bit fix both pops and *now* flags eax as clobbered, which it really doesn't need
>>>> to do. Is this inconsistent treatment correct?
>>>
>>> You may be right that this is not necessary on i686, but it doesn't
>>> hurt either and I'd like to stick to the upstream code if possible.
>>
>> The upstream patch changed only amd64/x86_64 code sequences for multiple modules
>> including modfl, and left i386/x86 untouched for those modules.

Just pointing out that they only modify their amd64/x86_64 code which doesn't
push/pop rax/eax:

diff -ru mingw-w64-v4.0.2/mingw-w64-crt/math/modfl.c
mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modfl.c
--- mingw-w64-v4.0.2/mingw-w64-crt/math/modfl.c	2015-04-11 11:37:30.000000000 -0400
+++ mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modfl.c	2015-05-07
11:05:57.000000000 -0400
@@ -21,7 +21,7 @@
     "fldcw (%%rsp)\n"
     "frndint\n"
     "fldcw 4(%%rsp)\n"
-    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value)); /* round */
+    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
 #elif defined(_X86_) || defined(__i386__)
   asm ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"

and their other patches do exactly the same for modf.c and modff.c, and not
their i386/x86 code which pushes/pops eax; where you do (adding lines back for
context) mark eax as clobbered after a pop in x86 patch:

> diff --git a/mingw-w64-crt/math/modfl.c b/mingw-w64-crt/math/modfl.c
> index af75a8b8cf60..ef1ab16ce256 100644
> --- a/mingw-w64-crt/math/modfl.c
> +++ b/mingw-w64-crt/math/modfl.c
#if defined(_AMD64_) || defined(__x86_64__)
     asm volatile ("subq $8, %%rsp\n"
       "fnstcw 4(%%rsp)\n"
       "movzwl 4(%%rsp), %%eax\n"
       "orb $12, %%ah\n"
       "movw %%ax, (%%rsp)\n"
> @@ -21,7 +21,7 @@ modfl (long double value, long double* iptr)
>      "fldcw (%%rsp)\n"
>      "frndint\n"
>      "fldcw 4(%%rsp)\n"
> -    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value)); /* round */
> +    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
>  #elif defined(_X86_) || defined(__i386__)
>    asm ("push %%eax\n\tsubl $8, %%esp\n"
>      "fnstcw 4(%%esp)\n"
       "movzwl 4(%%esp), %%eax\n"
       "orb $12, %%ah\n"
       "movw %%ax, (%%esp)\n"
> @@ -31,7 +31,7 @@ modfl (long double value, long double* iptr)
>      "fldcw (%%esp)\n"
>      "frndint\n"
>      "fldcw 4(%%esp)\n"
> -    "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value)); /* round */
> +    "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in IEC units and prefixes, physical quantities in SI.]

[-- Attachment #2: mingw-w64-v4.0.2.patch --]
[-- Type: text/plain, Size: 1856 bytes --]

diff -ru mingw-w64-v4.0.2/mingw-w64-crt/math/modfl.c mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modfl.c
--- mingw-w64-v4.0.2/mingw-w64-crt/math/modfl.c	2015-04-11 11:37:30.000000000 -0400
+++ mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modfl.c	2015-05-07 11:05:57.000000000 -0400
@@ -21,7 +21,7 @@
     "fldcw (%%rsp)\n"
     "frndint\n"
     "fldcw 4(%%rsp)\n"
-    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value)); /* round */
+    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
 #elif defined(_X86_) || defined(__i386__)
   asm ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"
diff -ru mingw-w64-v4.0.2/mingw-w64-crt/math/modf.c mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modf.c
--- mingw-w64-v4.0.2/mingw-w64-crt/math/modf.c	2015-04-11 11:37:30.000000000 -0400
+++ mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modf.c	2015-05-07 11:05:57.000000000 -0400
@@ -21,7 +21,7 @@
     "fldcw (%%rsp)\n"
     "frndint\n"
     "fldcw 4(%%rsp)\n"
-    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value)); /* round */
+    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
 #elif defined(_X86_) || defined(__i386__)
   asm ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"
diff -ru mingw-w64-v4.0.2/mingw-w64-crt/math/modff.c mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modff.c
--- mingw-w64-v4.0.2/mingw-w64-crt/math/modff.c	2015-04-11 11:37:30.000000000 -0400
+++ mingw-w64-v4.0.2-patched/mingw-w64-crt/math/modff.c	2015-05-07 11:05:57.000000000 -0400
@@ -22,7 +22,7 @@
     "fldcw (%%rsp)\n"
     "frndint\n"
     "fldcw 4(%%rsp)\n"
-    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value)); /* round */
+    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
 #elif defined(_X86_) || defined(__i386__)
   asm ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"

  reply	other threads:[~2020-08-31 19:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <02b16d2e-9d51-de58-807b-3b31b2565b59.ref@aol.com>
2020-08-29 12:52 ` airplanemath
2020-08-29 17:57   ` Ken Brown
2020-08-29 21:41     ` [QUAR] " Eliot Moss
2020-08-30 16:11       ` Ken Brown
2020-08-30 18:21         ` Eliot Moss
2020-08-30  1:21     ` airplanemath
2020-08-30  2:56       ` Ken Brown
2020-08-30  6:23         ` ASSI
2020-08-30 20:07           ` Brian Inglis
2020-08-30 13:00   ` Corinna Vinschen
2020-08-30 19:21     ` airplanemath
2020-08-31  7:33       ` Corinna Vinschen
2020-08-30 20:39     ` Brian Inglis
2020-08-31  7:35       ` Corinna Vinschen
2020-08-31 15:37         ` Brian Inglis
2020-08-31 18:45           ` Corinna Vinschen
2020-08-31 19:24             ` Brian Inglis [this message]
2020-08-31 19:41               ` Corinna Vinschen
2020-09-01 17:28                 ` Brian Inglis
2020-09-02  7:54                   ` 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=140d7709-7db0-6935-15c1-786d392d0f53@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --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).