Advertisement

segmentation fault while calling native functions with -O2

Started by December 20, 2011 01:39 PM
9 comments, last by WitchLord 12 years, 10 months ago
I'm using gcc 4.6.1 under linux.
I've tried both the sdk from angelcode.com (2.22.0) and the latest revision (1080).

Without optimizations everything runs fine.

With optimizations (O1,2,3 doesn't matter) I recieve a segmentation fault from
CallCDeclFunction() in as_callfunc_x86.cpp
and this specific line :
"movl 12(%ebp), %eax \n"
(looking up the registers, both ebp and eax are 0)

The only solution I have (besides no optimization at all) is to build every file with -O2
and build as_callfunc_x86.cpp without optimizations, then link.

This way everything seems to work fine.

Other suggestions ?
Have you tried doing a full re-build? AngelScript has been tested with -O2 on the buildbot: http://angelscript.j...O2%29/builds/84
Advertisement
I'm able to re-produce this problem on my machine using GCC 4.6.1. This bug is created by some change in GCC's optimization since v4.4.1 since that works with optimizations.

I'm able to re-produce this problem on my machine using GCC 4.6.1. This bug is created by some change in GCC's optimization since v4.4.1 since that works with optimizations.


So, this is one of the very rare cases that we should blame the compiler?
I feel so lucky... :)

By the way, i've tried some workarounds found on fourms around the web but nothing worked.
Like, changing the asm ("...") statement to asm volatile ("...") or asm __volatile__ ("...") did nothing.

Anyway, thanks for the reply.
I'm going to set up a buildslave running GCC v4.6.1 with O2 optimizations, this should help Andreas track down the issue, and make sure it doesn't pop up again (at least with this version of gcc).
Thanks for the bug report.
I believe this has to do with the inline assembly in as_callfunc_x86.cpp not having the clobber lists. GNUC must have changed something in the way they optimized the code which probably makes it use some of the registers that is also used in the inline assembly.

I'll have the inline assembler updated to properly use clobber lists. Thanks Jeremy for setting up the buildbot.

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,

I've changed the inline assembler code in as_callfunc_x86.cpp to properly use clobber lists. Hopefully this has fixed the problem on gnuc 4.6.1. Do you mind giving it a try to confirm the fix? You can find the fix in revision 1094.

Unfortunately I couldn't confirm it with the buildbot that Jeremy set up yet. It seems it is not linking the test app correctly.

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

Hey, thanks. I can't check this right now, I will test it on Monday and post the results.
No problem. Actually, Jeremy gave me access to his machine and the previous changes didn't work as I had hoped. It seems to be a bug in gnuc after all, though it might just be me who don't know how the inline assembler works well enough.

Anyway, it wasn't too hard to figure out what gnuc was doing wrong and I've now changed the code to work around it. The final fix is in revision 1104.

Code has been confirmed to be working by Jeremy's buildbot.

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

Yes, it's working now. Thank you again.

This topic is closed to new replies.

Advertisement