[ccall16] support added

BlackBox for Windows / Linux / OpenBSD / FreeBSD
https://github.com/bbcb/bbcp https://blackbox.oberon.org/download
Post Reply
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

[ccall16] support added

Post by Ivan Denisov »

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 cross-platform version of BlackBox:
https://blackbox.oberon.org/download
Josef Templ
Posts: 262
Joined: Tue Sep 17, 2013 6:50 am

Re: [ccall16] support added

Post by Josef Templ »

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
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: [ccall16] support added

Post by Ivan Denisov »

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.
Josef Templ
Posts: 262
Joined: Tue Sep 17, 2013 6:50 am

Re: [ccall16] support added

Post by Josef Templ »

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
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: [ccall16] support added

Post by Ivan Denisov »

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.
Post Reply