public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66838] New: Calling multiple SYSV AMD64 ABI functions from MS x64 ABI one results in clobbered parameters
@ 2015-07-11  0:59 michal.ruza at gmail dot com
  2015-07-12 15:21 ` [Bug rtl-optimization/66838] " ubizjak at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: michal.ruza at gmail dot com @ 2015-07-11  0:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66838

            Bug ID: 66838
           Summary: Calling multiple SYSV AMD64 ABI functions from MS x64
                    ABI one results in clobbered parameters
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michal.ruza at gmail dot com
  Target Milestone: ---

Created attachment 35951
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35951&action=edit
source code demonstrating the problem

This seems to be yet another corner case of bug 57003.

Description:
Calling a sequence of SYSV AMD64 ABI functions from an __attribute__((ms_abi))
function while passing an address of the same global variable to them results
in all but the first one in the sequence receiving clobbered values instead of
the expected address.

In code:
__attribute__((ms_abi, noinline, noclone)) void ms_abi_func() {
        sysv_abi_func("1st call", &global);
        sysv_abi_func("2nd call", &global);
        sysv_abi_func("3rd call", &global);
}
In this example only the first call of the "sysv_abi_func" is passed the
address of the global variable "global". All the other calls of the function
are passed clobbered values.

To see the problem:
- generate assembly for the attached "clobber_repro.c" for the x86_64
architecture as follows:
        gcc -S -O1 -m64 -o clobber_repro.S clobber_repro.c
- inspect the assembly code for the "ms_abi_func" fucntion
- you should see something like this after the function's prologue code:
        movl    $global, %esi
        movl    $.LC2, %edi
        call    sysv_abi_func
        movl    $.LC3, %edi
        call    sysv_abi_func
        movl    $.LC4, %edi
        call    sysv_abi_func

This apparently cannot work if "sysv_abi_func" clobbers %esi - and it is free
to do so as it is a SYSV AMD64 ABI function.

Additional notes:
- this doesn't happen when the "ms_abi_func" is NOT declared as
__attribute__((ms_abi))
- this doesn't happen when the "sysv_abi_func" IS declared as
__attribute__((ms_abi))
- this doesn't happen when the "global" is not a global variable - i.e. it
works when all of the calls are passed an address of the same local variable
- this doesn't happen when optimization is disabled (-O0)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-07-17 14:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-11  0:59 [Bug c/66838] New: Calling multiple SYSV AMD64 ABI functions from MS x64 ABI one results in clobbered parameters michal.ruza at gmail dot com
2015-07-12 15:21 ` [Bug rtl-optimization/66838] " ubizjak at gmail dot com
2015-07-12 16:42 ` ubizjak at gmail dot com
2015-07-15  7:29 ` uros at gcc dot gnu.org
2015-07-16  9:15 ` [Bug rtl-optimization/66838] [5 Regression] " rguenth at gcc dot gnu.org
2015-07-17 13:51 ` uros at gcc dot gnu.org
2015-07-17 14:06 ` ubizjak at gmail dot com

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