Building Kaffe v.0.10 with B19 Cygwin32 (long)

Tony Juricic tonko at
Sun Apr 5 15:58:36 PDT 1998

Configure did not recongnize my system ( it used to with
Cygwin32 version b18 and kaffe 0.9.1) so I had to
enter host explictly like:

./configure --prefix=c:/kaffe --host=i386-unknown-win32/cygnus
( you can put your machine or vendor name in place of unknown.)

If you get errors like:

Access denied
No such device
No more files or
Error 54

just restart make process and these errors will go away on
first or second attempt. I have no idea what produces them.

Launching make from bash, the first error I got was:

gcc -g -O2 -I. -I../../../include -I./../../../include -I../../../config -I./../
../../config  -c  Double.c -o Double.o
In file included from Double.c:15:
../../../kaffe/kaffevm/classMethod.h:89: redefinition of `Hjava_lang_Class'
../../../include/native.h:38: `Hjava_lang_Class' previously declared here
make[3]: *** [Double.o] Error 1

What happens here is that inclusion of <math.h> in Double.c
will cause Math.h from current direcory to be included, instead
of intended system header math.h. Header Math.h will, in turn,
include native.h before "classMethod.h".

The easiest fix is to edit Makefile and remove current directory
from the list of include paths. To do so remove first -I$(srcdir) from
INCLUDES=	-I$(srcdir) -I../../../include ....
This means that only files included via "" will be looked up in
current directory. System file included via <> would not be
found except in system include directories.

Same solution applies to the same error in Float.c.

Without this change of Makefile Math.c would shows warnings 
for sin, cos and sqrt functions declarations.

The next error was:

gcc -g -O2 -I. -I../../../include -I./../../../include -I../../../config -I./../
../../config  -c  Runtime.c -o Runtime.o
In file included from Runtime.c:16:
../../../config/config-io.h:21: invalid macro name
make[3]: *** [Runtime.o] Error 1

This is a simple typo in config-io.h which goes like:

#if defined(HAVE_WINSOCK_H)
#define	<winsock.h>

I noted this also in version 0.9.2. Naturally, it must be
#include <winsock.h> instead of #define <winsock.h>

I don't know why configure decided on having both HAVE_WINSOCK_H 
and HAVE_SYS_SOCKET_H but to continue with compilation you must 
actually comment out the line
#include <winsock.h>
because you will get a lot of conflicting declarations and
compiler errors. I did not investigate further.

Next error was:

System.c: In function `java_lang_System_initProperties':
System.c:173: `kaffe_version' undeclared (first use this function)
System.c:173: (Each undeclared identifier is reported only once
System.c:173: for each function it appears in.)
System.c:174: `kaffe_vendor' undeclared (first use this function)
System.c:175: `kaffe_vendor_url' undeclared (first use this function)
System.c:178: `KAFFEHOME' undeclared (first use this function)
System.c:184: `kaffe_class_version' undeclared (first use this function)
System.c:192: `file_seperator' undeclared (first use this function)
System.c:193: `path_seperator' undeclared (first use this function)
System.c:194: `line_seperator' undeclared (first use this function)
System.c: At top level:
System.c:277: conflicting types for `java_lang_System_setIn0'
system.h:18: previous declaration of `java_lang_System_setIn0'
System.c:286: conflicting types for `java_lang_System_setOut0'
system.h:19: previous declaration of `java_lang_System_setOut0'
System.c:295: conflicting types for `java_lang_System_setErr0'
system.h:20: previous declaration of `java_lang_System_setErr0'
make[3]: *** [System.o] Error 1

This error went away by changing 
#include "system.h" 
#include "../../../include/system.h" 
in System.c 
( Note: System.c includes both System.h and system.h" and
preprocessor seems not to be able to distinguish these two
headers which differ only in the case of the first letter. 
Result is that System.h in current native directory will be
included twice ).

Next error was:

gcc -g -O2 -I. -I../../../include -I./../../../include -I../../../config -I./../
../../config  -c  File.c -o File.o
In file included from File.c:22:
system.h:18: warning: `struct Hjava_io_InputStream' declared inside parameter li
system.h:18: warning: its scope is only this definition or declaration,
system.h:18: warning: which is probably not what you want.
system.h:19: warning: `struct Hjava_io_PrintStream' declared inside parameter li
system.h:20: warning: `struct Hjava_io_PrintStream' declared inside parameter li
File.c: In function `java_io_File_isAbsolute':
File.c:289: `file_seperator' undeclared (first use this function)
File.c:289: (Each undeclared identifier is reported only once
File.c:289: for each function it appears in.)
make[3]: *** [File.o] Error 1

The solution was as above: put a full path to system.h.

You should make identical corrections in files:
ObjectInputStream.c(22):#include "system.h"
ObjectOutputStream.c(21):#include "system.h"
ObjectStreamClass.c(22):#include "system.h",
all in libraries/clib/native directory.

Next error was:

-I../../config -I../../include -I./../../include -DTRANSLATOR -I./jit -DKVER=\"0
.100\"  -c  external.c
In file included from external.c:27:
slib.h:101: warning: `LIBRARYLOAD' redefined
slib.h:29: warning: this is the location of the previous definition
slib.h:111: warning: `LIBRARYFUNCTION' redefined
slib.h:39: warning: this is the location of the previous definition
slib.h:113: warning: `LIBRARYERROR' redefined
slib.h:42: warning: this is the location of the previous definition
external.c:32: ../../packages/external_native.h: No such file or directory
make[2]: *** [external.o] Error 1

To remove warnings, I added #if !defined(NO_SHARED_LIBRARIES)
at the top of slib.h and corresponding #endif before 
#if defined(NO_SHARED_LIBRARIES) is encountered in this file.

There was one additional warning that I did not handle:

-I../../config -I../../include -I./../../include -DTRANSLATOR -I./jit -DKVER=\"0
.100\"  -c  exception.c
exception.c: In function `dispatchException':
exception.c:212: warning: `noreturn' function does return

Regarding compilation error, it happens because there is no packages 
directory any more. 

To fix it, external.c file in kaffevm directory must be edited:

#include "../../libraries/clib/external_native.h"

instead of:

#include "../../packages/external_native.h"

nativelib.a should be successfully built now.

Last before last error that I got was:

gcc -g -O2  -I. -I./../kaffevm -I../../config -I./../../config -I../../include -
I./../../include   -o kaffe.exe main.o ../kaffevm/libkaffevm.a  ../../libraries/
clib/native/libnative.a ../../libraries/clib/net/libnet.a ../../libraries/clib/z
ip/libzip.a ../../libraries/clib/math/libmath.a  -lm    -lX11
/CYGNUS/B19/H-I386~1/i386-cygwin32/bin/ld.exe: cannot open -lX11: No such file o
r directory
make[2]: *** [kaffe.exe] Error 1

I don't know why this happened since my config did not find X
libraries ( I renamed my X lib directory to force exclusion of X
by config, expecting that there is no Peter's AWT and X support)
To fix this I explicitly deleted -lX11 from Makefile in kaffe directory.

Finally, when linking kaffe.exe I got a lot of undefined
externals related to native functions. Looked like compiler
did not like declaration in support.h:

typedef struct _nativeFunction {
	char*			name;
	void*  		        func;
} nativeFunction;

and treated function pointers like variable pointers.

I tried giving a hint to compiler with following declaration:

typedef struct _nativeFunction {
	char*			name;
	void	  		(*func)();
} nativeFunction;

but this did not work either.

Turned out functions are really missing from libraries.
For math library statement in BigInteger.c includes all
the code if HAVE_LIBGMP is defined like:

#if defined(HAVE_LIBGMP)

#include <gmp.h>

... code


There is no libgmp among Cygwin32 GNU libraries nor 
is there gmp.h header. HAVE_LIBGMP is not defined in

For undefined externals in zip library the cause was

#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H)

#include <zlib.h>

... code


I found Zlib version 1.1.2 at:
and GMP version 2.0.2 can be found at any GNU site.

I had to use Kaffe's version of config.guess and config.sub
for building GMP library. Versions of these files that come
with gmp-2.0.2 distribution didn't recognize Win32 Cygnus system.

Both libraries built fine. Then I manually edited config.h 
to contain definitions:

/* Do we have the compression library */
#define	HAVE_LIBZ
#define  HAVE_ZLIB_H

/* Do we have the GNU MP library */
#define	HAVE_LIBGMP */

and added zlib.a and libgmp.a to library list
in Makefile in /keffe/kaffe directory.

I was left with following undefined functions:

gcc -g -O2  -I. -I./../kaffevm -I../../config -I./../../config -I../../include -
I./../../include   -o kaffe.exe main.o ../kaffevm/libkaffevm.a  ../../libraries/
clib/native/libnative.a ../../libraries/clib/net/libnet.a ../../libraries/clib/z
ip/libzip.a ../../libraries/clib/zip/Zlib/libz.a ../../libraries/clib/math/libma
th.a ../../libraries/clib/math/gmp-2.0.2/libgmp.a -lm
../kaffevm/libkaffevm.a(support.o): In function `callMethodA':
/Projects/kaffe/kaffe-0.10.0/kaffe/kaffevm/support.c:273: undefined reference to
../kaffevm/libkaffevm.a(support.o): In function `callMethodV':
/Projects/kaffe/kaffe-0.10.0/kaffe/kaffevm/support.c:428: undefined reference to
make: *** [kaffe.exe] Error 1

I fixed this by changing i386/win32/cygnus/md.h where
I added common.h that contains definition of sysdepCallMethod.

/* Thread handling */
#include "i386/threads.h"

#if defined(TRANSLATOR)
#include "i386/common.h"
#include "jit-md.h"

Voila! Kaffe.exe was finally built with only a dozen
or so warnings (that I would like to get rid of later).

As I expected, problems present with Kaffe-0.9.2 thread
initialization are not gone. createDaemon(&finaliserMan...)
in thread.c causes segment violation when 
(*Kaffe_ThreadInterface.create)(tid,func) is called.

I traced it further to internal.c:reschedule()
when longjmp(TCTX(currentThread)->env,1) is invoked.
currentThread data.PrivateInfo contains too large value.
This large value is already present in threadQhead[11]
from where lastThread is obtained at the time when
reschedule() is invoked.

At this point GDB comes back with the message:

Program received signal SYGSEGV, Segmentation faut.
0x9 in ??()

Already with version 0.9.2 I found that setjmp/longjmp seem to
cause the problem by putting junk data in thread PrivateInfo
but SP_OFFSET 2 instead of 4 did not work for Cygwin32.
At this point I see no other solution but to download
B19 sources and look how are setjmp/longjmp implemented.
If anybody here has this knowledge already, or a better idea,
please let me (us) know.



More information about the kaffe mailing list