English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 08 March 2020, 21:17   #1
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
Compiling zLib with gcc 6.5

I grabbed zlib from here: https://github.com/madler/zlib and compiled it. Compilation runs fine, no errors. But when I try to use i.e. crc32 the functions takes extremly long and frequently crashes. I compared it to the official sources, and they are the same.

According to zlib.h comments I just should initialize the crc first and then I can calculate it. When I try the below code, I get two different CRCs. It takes almost 30 seconds until the first call completes and the second takes also as long or randomly crashes (guru). So this looks either like there needs to be some initialization done or there is something else wrong.
Do I need some special defines when compiling it?

Code:
int main(int argc, char *argv[])
{
    printf("Testing zLib %s compression library\r\n", zlibVersion());

    uLong uCRC = crc32(0L, Z_NULL, 0);
    printf("Init1 CRC: $%08lX\r\n", uCRC);
    uCRC = crc32(0L, Z_NULL, 0);
    printf("Init2 CRC: $%08lX\r\n", uCRC);
}
sparhawk is offline  
Old 08 March 2020, 22:04   #2
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
I found now the source of the problem, but I don't know how to resolve it, so some help may be appreciated.

When I compile the zLib library, the sources are *.c so they are compiled appropriately. In my sample project I call it from a cpp file. The problem is now, that the C compiled code expects parameters only on the stack, but the cpp call uses D0/D1 and A0 for parameter passing. I put a stub between which pushes the parameters on the stack to test this, and with this it works.
I tried to use
Code:
#define __cdecl __attribute__((__cdecl__))
but then I get a warning that the attribute is ignored and I still have the same calling convention as before. So how do I need to compile the library to get the proper calling convention?

Edit: Just found it: I have to use "__stdargs".
http://cahirwpz.users.sourceforge.ne...m.html#stkparm
sparhawk is offline  
Old 25 March 2020, 13:11   #3
bebbo
botcher

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 456
Quote:
Originally Posted by sparhawk View Post
I grabbed zlib from here: https://github.com/madler/zlib and compiled it. Compilation runs fine, no errors. But when I try to use i.e. crc32 the functions takes extremly long and frequently crashes. I compared it to the official sources, and they are the same.

According to zlib.h comments I just should initialize the crc first and then I can calculate it. When I try the below code, I get two different CRCs. It takes almost 30 seconds until the first call completes and the second takes also as long or randomly crashes (guru). So this looks either like there needs to be some initialization done or there is something else wrong.
Do I need some special defines when compiling it?

Code:
int main(int argc, char *argv[])
{
    printf("Testing zLib %s compression library\r\n", zlibVersion());

    uLong uCRC = crc32(0L, Z_NULL, 0);
    printf("Init1 CRC: $%08lX\r\n", uCRC);
    uCRC = crc32(0L, Z_NULL, 0);
    printf("Init2 CRC: $%08lX\r\n", uCRC);
}

Code:
Testing zLib 1.2.11 compression library
Init1 CRC: $00000000
Init2 CRC: $00000000
bebbo is offline  
Old 26 March 2020, 07:14   #4
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
I already fixed the problem. It was again a matter of using __stdardgs in the appropriate places.
sparhawk is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
GCC: compiling ASM with comments ? thellier Coders. Asm / Hardware 8 14 March 2018 10:02
Compiling GCC 3.x for WarpOS grelbfarlk Coders. C/C++ 2 28 November 2017 04:03
Help with gcc cross-compiling MartinW Coders. C/C++ 7 21 April 2017 13:22
Compiling WinUAE 2.1.0 rotacak support.WinUAE 8 06 May 2010 17:09
Compiling 1.3.4 rotacak support.WinUAE 70 22 January 2007 08:13

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:32.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.10440 seconds with 15 queries