delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/03/25/01:10:22

From: burgers AT ecn DOT nl (Teun Burgers)
Subject: Bug in gcc for __stdcall calling convention
25 Mar 1998 01:10:22 -0800 :
Message-ID: <35142E08.1F8C62D5.cygnus.gnu-win32@ecn.nl>
Mime-Version: 1.0
To: gnu-win32 AT cygnus DOT com
Cc: Richard Stanton <stanton AT haas DOT berkeley DOT edu>,
Ton van Overbeek <tvoverbe AT wk DOT estec DOT esa DOT nl>

This is a multi-part message in MIME format.
--------------6190546E39811AC53A0016F8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

DESCRIPTION
    gcc versions 2.8.0 and 2.8.1 on both the mingw32 platform and
    the Cygnus port generate wrong assembly code for functions
    returning a double or a float when these functions have
    the __attribute__((stdcall)). The caller gets NaN from
    these functions.
    This problem is mainly relevant in DLL building for other
    win32 applications. Functions in the WINAPI often use the
    __attribute__((stdcall)) convention.

REPRODUCTION OF THE PROBLEM
    The problem can be reproduced in a small code segment that
    is attached. When compiled with the following command line
    the problem is demonstrated:

    gcc -DPASCAL -o bug.exe bug.c

ANALYSIS
    When one compares the assembly from the standard c-calling sequence
    and the code with the __attribute__((stdcall)), the latter has an
    extra fstp instruction, that scrambles the stack.

WORKAROUND
    A workaround is available. Compile the C-code with the -S
    option. Remove the line with the fstp %st(0) instruction
    from the assembly and compile the edited assembly.

PARTIAL WORKAROUND
    A partial workaround (due to Colin Peters) is to compile with the
    -mno-fp-ret-in-387 option. In this case calling the function in gcc
    will give the correct result. This does not work however in a DLL
    that is used by other packages, for instance MS-Excel of the Java
    Development Kit from Sun.

Teun Burgers             (burgers AT ecn DOT nl)
Ton van Overbeek    (tvoverbe AT wk DOT estec DOT esa DOT nl)



--------------6190546E39811AC53A0016F8
Content-Type: application/x-unknown-content-type-C_auto_file; name="bug.c"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="bug.c"

I2luY2x1ZGUgPHN0ZGlvLmg+DQoNCiNpZmRlZiBQQVNDQUwNCiNkZWZpbmUgQ0FMTENPTlYg
X19hdHRyaWJ1dGVfXygoc3RkY2FsbCkpDQojZWxzZQ0KI2RlZmluZSBDQUxMQ09OVg0KI2Vu
ZGlmIFBBU0NBTA0KDQpkb3VibGUgQ0FMTENPTlYgaGVsbG9kZCAoZG91YmxlIHgpDQp7DQoJ
cHJpbnRmKCJoZWxsb2RkOiB4IGJlZm9yZSBleGl0ICVnXG4iLHgpOw0KCXJldHVybiB4Ow0K
fQ0KDQppbnQgbWFpbiAoKSB7DQoJZG91YmxlIHggPSAxMCwgejsNCgl6ID0gaGVsbG9kZCh4
KTsNCglwcmludGYoInogYWZ0ZXIgY2FsbCBvZiBoZWxsb2RkOiAlZ1xuIix6KTsNCglyZXR1
cm4gMDsNCn0NCg==
--------------6190546E39811AC53A0016F8--

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019