Can anyone using mingw compile this?
Hi,
in another post titled "Intel to AT&T Assembly" vVv replied to a problem I had with compiling the AT&T inline Assembly code translated from the Intel Assembly code that Fordy posted in response to another post.
Yeah,
I've been asking a lot of questions lately... ;)
He fixed the problem which would give gcc a hard time, but ...
Since vVv is using FreeBSD, he's not getting the errors that I'm getting when trying to use mingw's port of GNU compiler tools (gcc, g++, etc.) with DevCPP (4, 4.9.7.8 beta 5, etc.) All of the correct commandline options are being passed, with and without optimization options.
I'm still getting :
Quote:
undefined reference to `Hello1'
undefined reference to `Hello2'
A copy of the source is attached. This source has been modified from an Intel Syntax version, which is included at the bottom of the code in a comment block. Perhaps you'll spot something amiss...
* A point I'd like to make: The original code which Fordy posted, using Intel Inline Assembly, cleanly compiles and works exactly as it should.
Thanks for any help and/or viewing this post. I'm hoping to get my hands on a copy of cygwin to test it on that. If someone has good luck with that, please let me know.
* Note: problem fixed. Download updated copy of source for details.
Works with ZipSlack 3.9's gcc
One thing I haven't mentioned in this thread, which I did in another, is that this code will cleanly compile using g++ 2.7.3.2 under Slackware 3.9.
As far as portability, I see your point... but ...
Mingw is a windows port of gcc, so I was thinking that since we're not making any *NIX specific calls, commands, anything, it should work. Even with the gcc being mingw and not a *NIX version, it still uses the AT&T syntax, and seems to require a few different syntax changes, but should a large program ever need to be written for both OS's, a programmer could use
Code:
#ifdef WIN32
#define INLINE_ATT
#else
#ifdef INTEL
#define INLINE_INTEL
or something like that. It would just require more code. At least I hope so! :confused: I'm not an expert by far, but I hope that sort of design would prevail, as I hope to learn enough to design for both "worlds".
As far as this working for mingw or cygwin ...
It's very close... I just can't figure out what the defining point of difference is...
It will now compile with newer mingw ports
But...
We're still getting a warning, and this time it looks like a C++ mangling problem.
It still doesn't really see hello2, even when you call it with
Code:
asm
( // using AT&T Assembly syntax here.
"pushl szBuff;" // ;push the param onto the stack
"call _hello1;" // ;call the function
"addl $4, %esp;" // ;restore the stack to previous state
"pushl szBuff;" // ;push the param onto the stack
"call _hello2;" // ;call the function
// ;dont restore stack as hello2 will do that
);
instead of
Code:
asm
( // using AT&T Assembly syntax here.
"pushl szBuff;" // ;push the param onto the stack
"call hello1;" // ;call the function
"addl $4, %esp;" // ;restore the stack to previous state
"pushl szBuff;" // ;push the param onto the stack
"call hello2;" // ;call the function
// ;dont restore stack as hello2 will do that
);
The functions are declared as:
Code:
extern "C" void __cdecl hello1 (const char* szBuff)
//force C calling convention
{
std::cout << szBuff << std::endl;
}
and
Code:
extern "C" void __stdcall hello2 (const char* szBuff)
//force STDCALL calling convention
{
std::cout << szBuff << std::endl;
}
In case you're wondering ... using the form below
Code:
extern "C" void __stdcall hello2 (const char* szBuff)
//force STDCALL calling convention
{
std::cout << szBuff << std::endl;
}
vs. this
Code:
extern "C" void __attribute__ ((stdcall)) hello2 (const char* szBuff)
//force STDCALL calling convention
{
std::cout << szBuff << std::endl;
}
is the same thing.
The code once modified will compile on newer versions of mingw, specifically:
mingw32 gcc 2.95.3-6
mingw32 gcc 3.2
with the warning:
Warning: resolving _hello2 by linking to _hello2@4
This version would not compile at all:
mingw32 gcc 2.95.2
Any ideas? It seems to be directly related to using stdcall for hello2, because when you take that calling convention "declaration" away, it compiles cleanly.
Clifford Slocombe pointed out the need for prefixing the function names to be called in the assembly code. His post can be found at:
http://sourceforge.net/forum/forum.p...forum_id=48211
Thanks for everyone's help!
Note: Problem fixed. For full details, view the source code or the above SourceForge DevCPP Forum link for full details.
Basically, here is how it's supposed to be called:
Code:
asm
( // using AT&T Assembly syntax here.
"pushl szBuff;" // ;push the param onto the stack
"call _hello1;" // ;call the function
"addl $4, %esp;" // ;restore the stack to previous state
"pushl szBuff;" // ;push the param onto the stack
"call _hello2@4;" // ;call the function
// ;dont restore stack as hello2 will do that
);
Once again, thanks for everyone's help!