Subject: Bug in gcc for __stdcall calling convention
From: [email-masked] (Teun Burgers)

25 Mar 1998 01:10:22 -0800
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="------------6190546E39811AC53A0016F8"
Content-Transfer-Encoding: 7BIT
To: [email-masked]
Cc: Richard Stanton <[email-masked]>,
        Ton van Overbeek <[email-masked]>

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             ([email-masked])
Ton van Overbeek    ([email-masked])

--------------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
"[email-masked]" with one line of text: "help".