public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40898]  New: STDCALL mangling problem for strings @8 instead of @4
@ 2009-07-29  6:18 burnus at gcc dot gnu dot org
  2009-07-29  7:04 ` [Bug fortran/40898] " burnus at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-07-29  6:18 UTC (permalink / raw)
  To: gcc-bugs

There seems to be a problem with mangling, STDCALL and BIND(C), see
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/eb7ca487876d9420


-- 
           Summary: STDCALL mangling problem for strings @8 instead of @4
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

* [Bug fortran/40898] STDCALL mangling problem for strings @8 instead of @4
  2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
@ 2009-07-29  7:04 ` burnus at gcc dot gnu dot org
  2009-07-29  7:27 ` burnus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-07-29  7:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2009-07-29 07:04 -------
Function declaration

       function LoadLibrary(lpFileName) bind(C,name='LoadLibraryA')
!gcc$ ATTRIBUTES STDCALL :: LoadLibrary
         use ISO_C_BINDING

... and use

hmodule = LoadLibrary('fun.dll'//achar(0))

... and dump

hmodule = loadlibrary (&"fun.dll"[1]{lb: 1 sz: 1});

Reported error:

  undefined reference to `LoadLibraryA@8'

For a 32bit system, one expects a single 4-bye pointer and thus @4. However, I
do not see any reason why it should be 64bit instead of 32bits. It also cannot
be a 64bit Windows as one there does not use STDCALL.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

* [Bug fortran/40898] STDCALL mangling problem for strings @8 instead of @4
  2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
  2009-07-29  7:04 ` [Bug fortran/40898] " burnus at gcc dot gnu dot org
@ 2009-07-29  7:27 ` burnus at gcc dot gnu dot org
  2009-07-29  7:32 ` fxcoudert at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-07-29  7:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from burnus at gcc dot gnu dot org  2009-07-29 07:27 -------
>From the thread at c.l.f:

"A little testing revealed that the assembly code is correct, only the mangled 
 name is wrong when there is a character argument.  Perhaps the mangled name
 takes into account a spurious hidden LEN parameter while the code
 generator knows there is no such thing."


The issue is: While I corrected the procedure call and the creation of the
procedure itself for BIND(C) [i.e. no hidden-length argument; probably also
returning a "char" instead of a "char, char_len" as return argument], I forgot
to update the declaration of external functions, namely: gfc_get_function_type

That should also help with -fwhole-file issues.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |burnus at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-07-29 07:27:13
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

* [Bug fortran/40898] STDCALL mangling problem for strings @8 instead of @4
  2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
  2009-07-29  7:04 ` [Bug fortran/40898] " burnus at gcc dot gnu dot org
  2009-07-29  7:27 ` burnus at gcc dot gnu dot org
@ 2009-07-29  7:32 ` fxcoudert at gcc dot gnu dot org
  2009-07-29 10:21 ` burnus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-07-29  7:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2009-07-29 07:32 -------
By using my cross-compiler and setting a breakpoint in
i386_pe_mangle_decl_assembler_name(), I can confirm the analysis (that it's a
question of hidden length parameter).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

* [Bug fortran/40898] STDCALL mangling problem for strings @8 instead of @4
  2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2009-07-29  7:32 ` fxcoudert at gcc dot gnu dot org
@ 2009-07-29 10:21 ` burnus at gcc dot gnu dot org
  2009-07-29 10:28 ` fxcoudert at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-07-29 10:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2009-07-29 10:20 -------
FX: As you seemingly have a working cross compiler: Can you check the patch
below?

(One does not need to consider the return value as gfc_return_by_reference
deals with that. Only the last change is relevant, the others are just
optimizations for performance. As all the hidden arguments are of the same type
and as we do not care about the dummy name nor have an actual name, we just add
(nstr) arguments of the char-len type.)

Index: trans-types.c
===================================================================
--- trans-types.c       (revision 150203)
+++ trans-types.c       (working copy)
@@ -2249,7 +2310,7 @@ gfc_get_function_type (gfc_symbol * sym)
             Contained procedures could pass by value as these are never
             used without an explicit interface, and cannot be passed as
             actual parameters for a dummy procedure.  */
-         if (arg->ts.type == BT_CHARACTER)
+         if (arg->ts.type == BT_CHARACTER && !sym->attr.is_bind_c)
             nstr++;
          typelist = gfc_chainon_list (typelist, type);
        }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

* [Bug fortran/40898] STDCALL mangling problem for strings @8 instead of @4
  2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2009-07-29 10:21 ` burnus at gcc dot gnu dot org
@ 2009-07-29 10:28 ` fxcoudert at gcc dot gnu dot org
  2009-07-29 14:45 ` burnus at gcc dot gnu dot org
  2009-07-29 14:47 ` burnus at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-07-29 10:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fxcoudert at gcc dot gnu dot org  2009-07-29 10:28 -------
The patch seems to work:

$ cat a.f90 
subroutine foo
   use ISO_C_BINDING 
   implicit none 
   interface 
      function LoadLibrary(lpFileName) bind(C,name='LoadLibraryA') 
         use ISO_C_BINDING 
         implicit none 
         !gcc$ ATTRIBUTES STDCALL :: LoadLibrary 
         integer(C_INTPTR_T) LoadLibrary 
         character(kind=C_CHAR) lpFileName(*) 
      end function LoadLibrary 
   end interface

   integer(c_intptr_t) :: i
   i = LoadLibrary ("file" // achar(0))
end subroutine
$ i586-pc-mingw32-gfortran -c a.f90       
$ i586-pc-mingw32-nm a.o|grep LoadLibraryA
         U _LoadLibraryA@4


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

* [Bug fortran/40898] STDCALL mangling problem for strings @8 instead of @4
  2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2009-07-29 10:28 ` fxcoudert at gcc dot gnu dot org
@ 2009-07-29 14:45 ` burnus at gcc dot gnu dot org
  2009-07-29 14:47 ` burnus at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-07-29 14:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2009-07-29 14:45 -------
Subject: Bug 40898

Author: burnus
Date: Wed Jul 29 14:44:51 2009
New Revision: 150216

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150216
Log:
2009-07-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/40898
        * trans-types.c (gfc_get_function_type): Do not add hidden
        string-length argument for BIND(C) procedures.
        * trans-decl.c (create_function_arglist): Skip over nonexisting
        string-length arguments for BIND(C) procedures.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-types.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

* [Bug fortran/40898] STDCALL mangling problem for strings @8 instead of @4
  2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2009-07-29 14:45 ` burnus at gcc dot gnu dot org
@ 2009-07-29 14:47 ` burnus at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-07-29 14:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from burnus at gcc dot gnu dot org  2009-07-29 14:47 -------
FIXED on the trunk (4.5) - does not affect any branch.

(In reply to comment #5)
> The patch seems to work:

It caused a regression when I tried to regtest it as I missed another
(follow-up) place, cf. http://gcc.gnu.org/ml/fortran/2009-07/msg00256.html


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40898


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

end of thread, other threads:[~2009-07-29 14:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-29  6:18 [Bug fortran/40898] New: STDCALL mangling problem for strings @8 instead of @4 burnus at gcc dot gnu dot org
2009-07-29  7:04 ` [Bug fortran/40898] " burnus at gcc dot gnu dot org
2009-07-29  7:27 ` burnus at gcc dot gnu dot org
2009-07-29  7:32 ` fxcoudert at gcc dot gnu dot org
2009-07-29 10:21 ` burnus at gcc dot gnu dot org
2009-07-29 10:28 ` fxcoudert at gcc dot gnu dot org
2009-07-29 14:45 ` burnus at gcc dot gnu dot org
2009-07-29 14:47 ` burnus at gcc dot gnu dot org

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