public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: .def files for stdcall functions (was: linking problems with the minimalist version)
@ 1997-09-17  0:03 Colin Peters
  1997-09-17  2:28 ` .def files for stdcall functions (was: linking problems with Valery Fine
  1997-09-17  5:07 ` .def files for stdcall functions (was: linking problems with the minimalist version) Mikey
  0 siblings, 2 replies; 7+ messages in thread
From: Colin Peters @ 1997-09-17  0:03 UTC (permalink / raw)
  To: 'Gunther Ebert'; +Cc: gnu-win32

Gunther Ebert[SMTP:gunther.ebert@ixos-leipzig.de] wrote:
>Colin Peters wrote:
>> My beef with all this is: why does GCC do it this way at all? What purpose
>> does the @NN serve? After all, GCC knows how to generate the correct
>> function call given a prototype, it *generates* the @NN, so it doesn't
>> need it to know what to do. 
>
[snip]

This (enforcing agreement between caller and callee about the state of the
stack, which would be very painful to debug otherwise) is, indeed, a good
reason and I stand enlightened. What we have here is an inadequacy of tools.

True, pedump can be used to pick the names out of an import library
generated by MSVC (which are mangled in the same way), and in fact I think
the tool I mentioned earlier (dumpexts) is a version of pedump made to
perform exactly this operation.

It remains true, however, that sometimes one does not have a .def or .lib
file, like, for example, when you are generating the DLL yourself. In these
cases we are stuck going back and figuring out by hand (or via repeated
experiences with unresolved externals) the number of bytes on the stack to
add to the name. In this situation it would be nice to be able to either:

  1) Get GCC (or another tool) to generate the .def file (or even better
     the .a file), based on the prototypes (something like the __dll...
     keywords in MSVC). The intelligence is there in the code, more or
     less. Someone just needs to put it together.

  2) Get GCC to not generate the @NN for stdcall function calls, probably
     through a command line switch, in which case we could use dlltool
     and the plain function names in a .def file (which, while still
     painful, is a lot easier than trying to figure out the stack sizes
     by hand).

It would also be nice to get all of these different functions to do with
dynamic linking integrated somehow. Just out of curiosity, how different
is the way shared libraries are done under UNIX?

>1) If there are any problems with wrong or missing prototypes for
>   _stdcall functions the linker would complain with an 'unresolved external' 
>   message. You will never get a program with wrong function calls.
>2) In order to get all Win32 API functions working there must not be any
>   function prototype containing parameters which are less than 4 bytes
>   in size, even if the parameters are actually WORD or CHAR or BYTE or 
>   something else. Please check your windows header files if they
>   contain prototypes with WORD or CHAR parameters. Replace WORD
>   or CHAR parameters by DWORD parameters.

Isn't there an option to force stack alignment? If there is then shouldn't
it be on by default, at least for -mwindows programs? I admit I can't find
it in the docs right now... sounds like a candidate for a function attribute.

>In fact, MSVC mangles _stdcall names in the same manner as Cygnus gcc does.

As pointed out by another, this is another good reason.

I don't really expect much to be done about this, it's just a rant. Still
maybe someone with the appropriate tools at hand will decide to make the
effort. I can always hope...

Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: .def files for stdcall functions (was: linking problems with the minimalist version)
@ 1997-09-12  6:55 Scott Christley
  0 siblings, 0 replies; 7+ messages in thread
From: Scott Christley @ 1997-09-12  6:55 UTC (permalink / raw)
  To: Colin Peters; +Cc: 'GNU-Win32'

At 02:39 PM 9/12/97 +0900, Colin Peters wrote:
>
>My beef with all this is: why does GCC do it this way at all? What purpose
>does the @NN serve? After all, GCC knows how to generate the correct
>function call given a prototype, it *generates* the @NN, so it doesn't
>need it to know what to do. I don't think any other compilers add on @NN
>to the names of WINAPI functions like this. Why doesn't GCC just use the
>plain function name and call it with PASCAL calling convention? Someone
>please enlighten me.

It's a Microsoft thing not GCC; if you look at the Microsoft libraries you
will see that they have the @NN tacked onto the function names.  Special
code had to be added to GCC so that it produced the appropriate functions.
That is why you see these predefinitions when you run GCC with the -v flag

-D__stdcall=__attribute__((__stdcall__))
-D__cdecl=__attribute__((__cdecl__))

Now why Microsoft felt it was necessary to tack on @NN, I don't know.

Scott

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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: .def files for stdcall functions (was: linking problems with the minimalist version)
@ 1997-09-11 23:07 Colin Peters
  1997-09-12  4:40 ` Gunther Ebert
  0 siblings, 1 reply; 7+ messages in thread
From: Colin Peters @ 1997-09-11 23:07 UTC (permalink / raw)
  To: 'Lachlan Roche'; +Cc: 'GNU-Win32'

Lachlan Roche[SMTP:lr-gnu@www.wwi.com.au] wrote:
>I have been trying to use opengl with the minimalist version of gcc-win32.
>
>I am using SGI GL for windows, and Mark Kilgard's glut32.dll
>
>I created my link liraries link:
>impdef opengl.dll > opengl.def
>dlltool --dllname opengl.dll --def opengl.def --output-lib libopengl.a -v
>
>There were no func@NN type symbols in the .def files
>
>when linking a trivial test program, I get many errors of the form:
>gltest.o(.text+0x24):gltest.c: undefined reference to `glBegin@4'
>
>Every function I use from libglut.a libglu.a or libopengl.a gives the same
>link error.
>
>What am I doing wrong? (Something trivial, no doubt)

The problem is not something you are doing wrong, as such, nor is it linked
to Mingw32 really. The problem is that impdef does not generate (and cannot
as far as I can figure out) .def files with that all important @NN suffix
on stdcall (or PASCAL or WINAPI) functions.

If impdef did generate the 'right' function names (e.g. "glBegin@4") then
you could generate your import library using the -k option to dlltool and
everything would work.

Unfortunately there is no way, that I can see, to automatically determine
this information (what number goes after the @) from the contents of a
DLL. You must parse the header file! (Please correct me if I'm wrong...
I'd love to be wrong about this.)

(NOTE for those unfamiliar with the way GNU-Win32 does stdcall functions,
it puts an @ followed by the number of bytes taken up on the stack by the
arguments onto the end of the function name. This has nothing to do with
the syntax used in .def files to define ordinals.)

In short, there is no easy way around this problem except to add all those
@NNs by hand after looking at the header file. Argh! You could, of course,
also write a program which attempted to call all the OpenGL functions, and
then copy the numbers off the "undefined reference" linker errors.

My beef with all this is: why does GCC do it this way at all? What purpose
does the @NN serve? After all, GCC knows how to generate the correct
function call given a prototype, it *generates* the @NN, so it doesn't
need it to know what to do. I don't think any other compilers add on @NN
to the names of WINAPI functions like this. Why doesn't GCC just use the
plain function name and call it with PASCAL calling convention? Someone
please enlighten me.

Sorry about the rant...

Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

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

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

end of thread, other threads:[~1997-09-17 19:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-17  0:03 .def files for stdcall functions (was: linking problems with the minimalist version) Colin Peters
1997-09-17  2:28 ` .def files for stdcall functions (was: linking problems with Valery Fine
1997-09-17 19:39   ` J Russell Smyth
1997-09-17  5:07 ` .def files for stdcall functions (was: linking problems with the minimalist version) Mikey
  -- strict thread matches above, loose matches on Subject: below --
1997-09-12  6:55 Scott Christley
1997-09-11 23:07 Colin Peters
1997-09-12  4:40 ` Gunther Ebert

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