# 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.

## 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 on other sites
Have you tried doing a full re-build? AngelScript has been tested with -O2 on the buildbot: http://angelscript.j...O2%29/builds/84

##### 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.

##### 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.

##### 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 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 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 on other sites
Hey, thanks. I can't check this right now, I will test it on Monday and post the results.

##### 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 on other sites
Yes, it's working now. Thank you again.

1. 1
Rutin
43
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633398
• Total Posts
3011659
• ### Who's Online (See full list)

There are no registered users currently online

×