• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
WitchLord

mingw + asOBJ_IS_COMPLEX: portability issues

5 posts in this topic

Branching from my other thread on the offsetof() macro: http://www.gamedev.net/community/forums/topic.asp?topic_id=260145 I have the following class:
class CComplexClass
{
public:
	CComplexClass() { a = 0xDEADC0DE; }
	
	unsigned long a;
};

Since the class has a constructor MSVC will return objects of this type by reference by having the caller allocate memory for it and pass the pointer to the memory in a hidden address. MSVC will do this for all classes that have either a constructor, a destructor or an assignment operator. My problem is that this is not true for MinGW. For this example it seems that MinGW returns the object normally in the register EAX. I write in AngelScript's manual that you should use the flag asOBJ_IS_COMPLEX when registering a class that has a constructor, destructor, or assignment operator. AngelScript is supposed to use this flag to identify the correct method that the host application uses to return objects with that type. I need help in defining how MinGW returns objects on the x86 processor. If you don't know exactly how it is done already, then perhaps you can tell me how I can debug the MinGW code or disassemble it.
0

Share this post


Link to post
Share on other sites
I did not ever need to deal with things like that, but I believe this document: GNU Compiler Collection Internals will help you. It describes the behaviour of all GCC compilers, so MinGW falls under this category too. Chapters 10.10.8 and 10.10.9 will be the most relevant, probably.

Hope that helps.

[EDIT]

Hm, just found that there are flags in GCC to take care of returning structs and classes. They -fpcc-struct-return and -freg-struct-return. The second should objects that fit in registers throguh the registers and the big ones through memory. The first one forces all struct returns to be done through memory. The default setting for MinGW is -freg, for Cygwin: -fpcc, I don't know about the others GCC versions. You can just say the user that if he has set the -fpcc flag, he should register all objects as asOBJECT_IS_COMPLEX.

Constructors, destructors and assignment operators have no part in that: it's just the size of the object that matters.

That is the result of some research done through Google, you should probably check if it's all 100% right...

[Edited by - krajzega on July 28, 2004 3:11:45 PM]
0

Share this post


Link to post
Share on other sites
That document didn't really tell me much. It is more about what options there are in configuring the compiler, it doesn't tell me how it works on x86.

I found another document here: http://www.ictp.trieste.it/texi/gpp/gpp_53.html

This one says how it is supposed to work. Though I'm not so sure it really does work like that. I'll have to do some more tests.

0

Share this post


Link to post
Share on other sites
Quote:

Hm, just found that there are flags in GCC to take care of returning structs and classes. They -fpcc-struct-return and -freg-struct-return. The second should objects that fit in registers throguh the registers and the big ones through memory. The first one forces all struct returns to be done through memory. The default setting for MinGW is -freg, for Cygwin: -fpcc, I don't know about the others GCC versions. You can just say the user that if he has set the -fpcc flag, he should register all objects as asOBJECT_IS_COMPLEX.

Constructors, destructors and assignment operators have no part in that: it's just the size of the object that matters.


I'll do some more investigations.

I think you are correct in what you said. My tests seems to support that. Though it also seems that MinGW doesn't use EAX:EDX like MSVC6 does. When I tried returning an 8 bytes object I only received half of it. When trying to return a 12 bytes object the program crashed with a memory access violation, which would suggest that MinGW doesn't work the same way as MSVC6 when returning objects in memory either. Perhaps it passes the hidden address as the last parameter, or in a register.

I need to somehow discover these things so that I can make AngelScript portable.

The programmer shouldn't have to change the way he writes his application depending on how the compiler is configured. All this should be hidden inside the library code, where the as_config.h file would have to be set up correctly to take care of the calling convention differences.

Note, AngelScript is not quite there yet, but I'm slowly moving all compiler differences into the as_config.h file.

Does anyone know of a visual debugger with disassembler that works with MinGW? In MSVC6 I can easily verify how it compiles function calls, but I'm not sure how I should go about verifying this with MinGW.
0

Share this post


Link to post
Share on other sites
About MinGW debuggers/disassemblers, I know of two. One, GDB, is the standard gnu debugger and is shipped with your MinGW in the bin directory. There are tutorials on the net on how to use GDB, it can be a pain if you want to do something more than a simple run and a backtrace... And you certainly do. It has disassemble features and everything a debugger needs, but the command line interface needs a lot of getting-used-to.

There is also "Dr. MinGW", this is a JIT (Just-In-Time) Windows debugger. I haven't had many experiences with it, but I have heard only good about it. It has visual interface, but I'm not sure if it does everything you need. Just Google for it and check if it has the needed features on its website.
0

Share this post


Link to post
Share on other sites
Thanks for the help, krajzega. GDB was good enough for me. With the manual open it was quite easy to use.

Firstly there was a bug that made the AngelScript library misshandle objects with 2 DWORDs in size. To fix this the line 963 in as_scriptengine.cpp has to be changed to:


{
systemFunctions[n]->hostReturnMethod = asCALL_RETURNBYVAL;
systemFunctions[n]->hostReturnSize = systemFunctions[n]->returnType.GetSizeOnStackDWords();
}


The second problem is when the object is larger than 2 DWORDs and returned in memory. MinGW and MSVC treats these situations slightly differently. Both pass a hidden pointer as the first parameter, but with MinGW the callee pops this pointer before returning while MSVC leaves it for the caller.

The third problem is that MinGW doesn't treat classes that have constructors or destructors differently than any other. I was actually prepared for this one already, although I didn't know what the difference was.

The first problem have been fixed with the above code change. The other two I'll fix in the next few days (I hope).

I'm pretty sure that MinGW work the same way as any other g++ based compiler so these changes will probably work for g++ on Linux and DJGPP on Windows as well.

I think I'll write an article on differences in calling conventions. It would be interesting if I could collect information about all types of calling conventions in one place.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0