Advertisement

Marmalade: Angelscript runs fine on x86, crashes on ARM

Started by September 24, 2012 04:45 PM
34 comments, last by WitchLord 11 years, 11 months ago
Hi Andreas,

Thanks very much for all your help, as well as IobuWu, Papirosnik, and Martins Mozeiko. However, even after trying everything, I am still unable to get anything but the generic calling convention working on an ARM processor. I've asked a question to Marmalade like you suggested.

I would love to help solve this as it'd make my life a whole lot easier, having chosen AngelScript as the scripting language for the game project I'm working on. The generic calling conventions are also a problem when using things like the "ref" type extension, which I need to let my game objects communicate, but I'll have to modify to use generic calling conventions if I can't solve the cdecl problem.

It appears that some of the suggestions in this thread may have been coded into the newest version of AngelScript (2.25.2) which I am now using. I still have made sure that MARMALADE and _ARM_ are getting defined by putting them into the project manually. Defining AS_NO_THREADS doesn't seem to be necessary anymore (though I have tried with and without). I tried using the *.S files instead of *.asm with scons as suggested (had to delete the comments as I couldn't figure out the correct syntax to change it to), unfortunately I still get the same runtime error when running the scons builds.

It doesn't seem that Marmalade defines _MSC_VER when compiling for ARM from within MSVC. It doesn't seem to define that either when compiling with scons. Perhaps this is the problem, as it gets into the other two just fine when I force that one to true. However, I can't simply do this to make it work as it seems to cause a domino-chain of other compiler errors that I can't fix without intimate knowledge of AngelScript's inner workings.

In an effort to make the problem as clear as possible I've put together a complete "Hello World" Angelscript/Marmalade project that should be runnable on any system with even the free trial of Marmalade installed (and MSVC). It's attached to this message. If this project worked without crashing on ARM it would be like gold to me (I've spent days trying to troubleshoot this). As it is now, here are instructions on how to reproduce the crash:

MSVC way:
1.) Double-click AngelScript_HelloWorld.mkb to open the project in MSVC.
2.) If you'd like, compile the debug or release version for x86 and run it. This is what's supposed to happen (a "Hello World" dialog)
3.) Compile the debug version using GCC(ARM). This should compile successfully.
4.) Hit F5 and this will start the special ARM simulator and debugger.
5.) To see the exact point of the problem, navigate to as_scriptengine.cpp and put a breakpoint on line 2473.
6.) Click "continue" and the program will hit the breakpoint (which means the error has occurred)

(note that _ARM_ isn't actually defined for the MSVC build as I haven't figured out how to do this for only one build with Marmalade. However, even if you explicitly declare _ARM_ in the project settings, the same error occurs because _MSC_VER isn't defined for the ARM compiler)

Scons way:
1.) Double-click the scons.bat file that I put in the same directory as the project files, this should compile to ARM files with scons.
2.) Navigate to the build_angelscript_helloworld_scons_scons_arm directory.
3.) Choose either debug or release directory.
4.) Copy the *.s3e file in that directory to the "data" directory under the project's folder. You can double-click it to run it from there (ignore the Marmalade warning message).
5.) You should get the same result as if you ran the ARM simulator from MSVC.
6.) If you want to debug, you should be able to click the *.s3e file and click "debug." Then you can point the ARM simulator to the generated *.elf file in the directory where the build came from.

That is the situation as best as I've been able to understand it. I hope that this leads to a solution. I've been very happy with AngelScript so far, it's just this calling convention problem that's been driving me up a wall.

Thank you very much,
Sebastian
From what we've learned earlier from papirosnik and loboWu, when compiling for ARM scons must be used, so I suggest you concentrate your efforts on that and leave trying to get it to work with MSVC for later.

Do you expect this to run on iOS or Android? I don't think Marmalade defines either when compiling for arm, which will leave the configuration in AngelScript only partly defined.

Try including ANDROID or __APPLE__ and TARGET_OS_IPHONE, i.e.


defines
{
MARMALADE
_ARM_
ANDROID
}


or


defines
{
MARMALADE
_ARM_
__APPLE__
TARGET_OS_IPHONE
}


In loboWu's makefile I see he defined AS_ARM directly to enable the as_callfunc_arm.cpp. But this would bypass all other configuration in as_config.h so this is not recommended. However, if none of the above works, you might try that as well.

Observe, iOS and Android uses slightly different calling conventions and I have no idea which Marmalade uses (or even if it isn't using a completely different calling convention) so you may need to try both to see which works best.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Hi Andreas, thanks for the response. I would like to be able to make builds for both iOS and Android. I tried both those suggestions and got compiler errors.

With Android define:
as_callfunc.cpp:476: error: exception handling disabled, use -fexceptions to enable

I figure I am supposed to add that command line flag somehow, but I can't figure it out. Neither:

AngelScript_HelloWorld_scons.mkb --arm --buildenv=scons --compiler=gcc --cppflag=-fexceptions

nor:

AngelScript_HelloWorld_scons.mkb --arm --buildenv=scons --compiler=gcc -fexceptions

seem to work.


With iPhone defines:
as_config.h:583: fatal error: TargetConditionals.h: No such file or directory

My guess is that this is an apple-specific library that I should probably be able to include as a subproject with Marmalade, but I don't know what subproject to use. Should I ask another question to Marmalade?


The way the Marmalade SDK works, it seems to compile a single ARM binary, and be able to "package" it up for use with either iOS or Android without the need for a recompile. So if the systems are slightly different, you may be right be right that Marmalade has a favorite, though it's not clear yet which one that might be.
From loboWu's makefile I see that exceptions are enabled like this:


#!/usr/bin/env mkb


options
{
enable-exceptions=1
lib
module_path="../../source"
}


Did you try defining AS_ARM directly? Like loboWu does in his makefile? What was the result of that?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I played around with AS_ARM and it didn't seem to help. However, using the following defines/options:

defines
{
MARMALADE
_ARM_
ANDROID
}

options
{
enable-exceptions=1
}

It seems that, when compiling with SCons, the ARM versions are finally working properly! Since Marmalade's ARM binaries are theoretically platform independent, I may be able to "package" the binary up for iOS as well.

Thanks a ton for all your help. It seems my troubles may finally be over, though I need to verify everything works on device. Once I can confirm everything's working I'll try and clean up the Hello World program and post it for anyone who might need it in the future. Will post again with results.

---Sebastian
Great to hear it is finally working.

Do let me know if you encounter other problems.

I'll probably have to include a Marmalade makefile for the AngelScript library, especially since it is not so straightforward to figure out how to configure it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Yep, it's working, and I'm finally able to run AngelScript on device using CDECL calling conventions. :]

Thanks a ton for all your help. Attached is a complete Marmalade project that implements "Hello World" by calling a print function from AngelScript, and runs just fine on devices without the asCALL_GENERIC workaround. Should save some time if anyone else needs to get AngelScript/Marmalade working in the future. You're welcome to reference it if you wanna put Marmalade makefiles in the AngelScript library.
Hi everyone,

I want to say a big thank you to all of you for your hard work in getting AngelScript to work on Marmalade. Unaware of UltimateWalrus's latest posts, I spent some time last week integrating AngelScript into Marmalade, and have put together yet another integration of AngelScript and Marmalade: angelscript-marmalade project on GitHub.

It seems to be working well on MSVC/x86, VS/GCC-ARM, XCode/Clang/x86, XCode/GCC/x86, XCode/ARM, and Scons/ARM. I've included portable binaries in the distribution so that it can be used right away. If one does want to [re-]compile it, it should compile easily and run with native calling conventions on Marmalade Windows, Marmalade Mac, or Marmalade ARM. (Although due to the presence of the ".S" files, one line of the MKB must be commented out before it will compile with Visual Studio). I made sure that the AngelScript code is completely unmodified; in fact, if you use the MKB to build the project, it will download the unmodified source upstream code as part of the build process.

I'm just getting started with AngelScript, but everything looks very promising so far. Just wanted share my code and to say thanks smile.png
Hi Braden,

thanks for sharing your work and for letting us know that it works on all these different platforms.

There are now quite a few projects using AngelScript with Marmalade. smile.png

I see that you use a couple of predefines to determine the target platform, i.e. I3D_ARCH_X86 and I3D_ARCH_ARM. How did you find out about these? It looks like something I can use directly within the as_config.h so it wouldn't be necessary to define anything other than MARMALADE from the project files.

Actually perhaps I can even use the existance of I3D_ARCH_X86 or I3D_ARCH_ARM to identify that the library is being compiled for Marmalade, in which case it wouldn't be necessary to define anything at all from the Marmalde makefile.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

That is an excellent idea: You could use (I3D_ARCH_X86 || I3D_ARCH_ARM) as a test for the Marmalade platform. It would be nice to remove the predefines from the MKB makefile if possible. I found out about these defines from the Marmalade forum; they are not in the documentation, although they have been around for a long time. (Unfortunately there are quite a few of these little Marmalade "tricks" that are completely undocumented except for the occasional insightful forum post from Marmalade staff.)

Edit: It's worth mentioning that Marmalade also supports other platforms (although they're not nearly as popular as x86 and ARM); their preprocessor definitions are: I3D_ARCH_AMD64, I3D_ARCH_MIPS, I3D_ARCH_PS3, I3D_ARCH_X360, and I3D_ARCH_PSP. I've never worked with any of those other platforms. The full list of symbols can be seen in the "temp_defines_debug.h" file that Marmalade's makefile_builder creates during the build process.

Edit 2: Upon looking at that file further, I see that you could also detect the Marmalade platform by looking for "IW_SDK", "__S3E__", or any number of other definitions. Check out this copy of an example temp_defines_debug.h file to see.

This topic is closed to new replies.

Advertisement