Jump to content
  • Advertisement
Sign in to follow this  
gdmark

segmentation fault while calling native functions with -O2

This topic is 2506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!