[ccall16] support added

https://github.com/bbcb/freenix https://blackbox.obertone.ru/

[ccall16] support added

Postby Ivan Denisov » Fri Aug 11, 2017 5:05 pm

Thanks for luowy for the compiler improvement. He introduced new flag [ccall16] for the procedures. This flag give sign to the compiler that such procedure stack should be aligned with 16-byte boundary. It is useful for some libraries compiled by GCC (https://en.wikipedia.org/wiki/X86_calli ... ions#cdecl). Especially SDL2 libraries in my case.

New feature is available in the OberTone/Freenix version of BlackBox:
https://blackbox.obertone.ru/download
User avatar
Ivan Denisov
 
Posts: 205
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: [ccall16] support added

Postby Josef Templ » Sat Aug 12, 2017 3:46 am

Ivan, are the functions in the SDL2 library specially marked as requiring 16 byte stack alignment?
Or in other words, how do you know if you need ccall or ccall16?

- Josef
Josef Templ
 
Posts: 131
Joined: Tue Sep 17, 2013 6:50 am

Re: [ccall16] support added

Postby Ivan Denisov » Sat Aug 12, 2017 6:50 am

Josef Templ wrote:Ivan, are the functions in the SDL2 library specially marked as requiring 16 byte stack alignment?
Or in other words, how do you know if you need ccall or ccall16?

Definitely need if use libraries made with GCC version > 4.5.
Without stack alignment applications crashes. We discussed this problem in the Russian board.
Artur Efimov (kekc_leader) first described the problem here: https://forum.oberoncore.ru/viewtopic.p ... 664#p95483
For the long time I used the hack suggested by Alexander Shiryaev with SYSTEM.GETREG & SYSTEM.PUTREG.
It was the nightmare to introduce new functions of SDL2 in my code, because for each function there should be wrapper and some integer which need to find experimentally.

This is rare problem for windows applications, because not much libraries made with GCC for Windows. So you can ignore this for Center version until somebody not complain...
Ivan Kuzmitskiy (akastargazer) reported that he had problems in Windows OS with SDL2. He can not explain occasional crashes and this force him to stop the development for SDL2.
I think that this crashes can be related with alignment problems.
User avatar
Ivan Denisov
 
Posts: 205
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: [ccall16] support added

Postby Josef Templ » Sat Aug 12, 2017 11:52 am

Ivan, it is hard to say but if only a single SDL call fails and the others work well, it may be related to that specific call,
not to the overall calling conventions. 16 byte alignment on i386 is only required for SSE instructions, as far as I know.
Is the failed call related to SSE instructions? Are there any SSE vectors used as parameters or struct members?
Have you checked the data types of the call parameters carefully? Check the size of structs and the size of members
and check the alignment of all struct members. Look at the disassembly and compare with disassembled C code (use gcc -S test.c to get the assembler file).
CP by default aligns to 4 byte but there are sysflags for tweaking the alignment of records.

- Josef
Josef Templ
 
Posts: 131
Joined: Tue Sep 17, 2013 6:50 am

Re: [ccall16] support added

Postby Ivan Denisov » Sat Aug 12, 2017 6:01 pm

I have spent many time for experiments. I am sure that the problem is about alignment of stack.
Anyway I am happy that my software now works smooth without stack alignment "hacks".
That is the main prove that the reason was in the wrong stack position.
User avatar
Ivan Denisov
 
Posts: 205
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia


Return to BlackBox for Windows / Linux / OpenBSD / FreeBSD

Who is online

Users browsing this forum: No registered users and 1 guest

cron