[comp.lang.lisp] Trouble Compiling KCL on Sun3/SunOS4

m1rcd00@arccs1 (Bob Drzyzgula) (04/01/89)

In trying to compile KCL version 1.25 on a Sun 3/60 running SunOS 4.0,
I get the following error: 

	(...)
	
	Initializing cmptop...  
	Initializing cmpvar...  
	Initializing cmpvs...  
	Initializing cmpwt...  
	Loading ../cmpnew/cmpmain.lsp
	sh: 11220 Memory fault - core dumped
	*** Error code 139
	make: Fatal error: Command failed for target `saved_kcl'
	Current working directory /tmp_mnt/auto9a08975/kcl/unixport
	*** Error code 1
	make: Fatal error: Command failed for target `all'

The Sun 3 has 8 MB memory & 57MB paging space. Stack size limit is set
at 10MB. Paging space use during the compile hit a maximum of 7.8MB.
The machine exhibits no other abnormal behavior. Nothing was done with
o/makefile or unixport/makefile other than to make sure that
MACHINE = SUN3 was set. The only other errors in the make were of the
"loop not entered at top", "illegal pointer combination", and 
"statement not reached" sort. The header to cmpmain.lsp says specifically
that that file is machine/os dependant.

Anyone know what to do here?

Thanks,

Bob Drzyzgula
rcd@fed.frb.gov, uunet!fed!rcd
Federal Reserve Board, Washington, DC  20551

m1rcd00@arccs1.FRB.GOV (Bob Drzyzgula) (04/05/89)

Thank you all very much for your responses. There were four basic
suggestions:

	1. Use the gcc compiler. (Moises Lejter)
	2. Use -Bstatic on the Sun C compiler. (Mark Lerner)
	   (to Mark: You suggest that there is a step in the beginning
	   where the makefiles get rewritten. I have looked again
	   through all of the distribution, and I cannot find
	   any such configuration process. I got my copy from uunet.
	   Am I missing something?)
	3. Patch the source (Taizo Kojima's patches are included here).
	4. Buy IBCL. (a solicitation from the purveyor)

So, I first tried using the gcc comiler. To do this, I wound up having
to make two changes: I put -w in the gcc commands, since it got *real*
upset about one of the header files (external.h) not meeting gnu's
specs. I also had to patch the dpp preprocessor to make it generate
gnu-standard #line directives. (gnu uses # linenum filename, and the
filename has to be in double quotes in the general case. Sun's cc uses
#line linenum filename, and doesn't need the quotes. This is real easy
to find... search for #line in dpp.c). This got past loading cmpmain.lsp,
but choked on another memory error soon after loading setdoc.lsp
(transcript later).

Second, I tried putting -Bstatic on Sun's cc (yes, including the
one at the bottom of unixport/makefile that doesn't use CFLAGS). This
made no discernable difference in the outcome.

This was when Taizo Kojima's mail came in. I applied that patch, and
the Sun cc version ran through the cmpmain.lsp, but *failed in exactly
the same place as gcc*. So although I have achieved syncronization
between the two compilers, I have not gotten a running kcl. You've done
great so far, any more ideas? (Yes, I have run memory diagnostics on
my Sun and even tried a seperate compile on a different machine
[a 3/180])

Again, thanks. Transcript of failure follows, followed by Taizo
Kojima's patches:

	Initializing cmpvar...  
	Initializing cmpvs...  
	Initializing cmpwt...  
	Loading ../cmpnew/cmpmain.lsp
	Finished loading ../cmpnew/cmpmain.lsp
	Loading ../cmpnew/lfun_list.lsp
	Finished loading ../cmpnew/lfun_list.lsp
	Loading ../cmpnew/cmpopt.lsp
	Finished loading ../cmpnew/cmpopt.lsp
	Warning: COMPILE-FILE is being redefined.
	Warning: COMPILE is being redefined.
	Warning: DISASSEMBLE is being redefined.
	Loading ../lsp/setdoc.lsp
	Finished loading ../lsp/setdoc.lsp
	Warning: LISP-IMPLEMENTATION-VERSION is being redefined.sh: 954 Memory
	fault - core dumped
	*** Error code 139
	make: Fatal error: Command failed for target `saved_kcl'
	Current working directory /src/kcl/unixport
	*** Error code 1
	make: Fatal error: Command failed for target `all'



>Hello Mr.Drzyzgula
>
> The reason of a memory fault is the implicit return value of
>new Sun C compiler.
> To avoid this, you must add 2 lines at bottom of the functions
>using asm() statement, get_mark_bit() and get_set_mark_bit() in
>c/bitop.c:
>
>======= in bitop.c
>get_mark_bit(x)
>int *x;
>{
>	asm("	movl	a6@(8),d0");
>	asm("	lsrl	#2,d0");
>	asm("	movl	d0,d1");
>	asm("	lsrl	#3,d1");
>	asm("	movl	_mark_table,a0");
>	asm("	btst	d0,a0@(0,d1:L)");
>	asm("	sne	d0");
>	asm("	andl	#1,d0");
>
>	asm("   unlk    a6");	/* for SunOS4.0 */
>	asm("   rts");		/* for SunOS4.0 */
>
>}
>
>get_set_mark_bit(x)
>int *x;
>{
>	asm("	movl	a6@(8),d0");
>	asm("	lsrl	#2,d0");
>	asm("	movl	d0,d1");
>	asm("	lsrl	#3,d1");
>	asm("	movl	_mark_table,a0");
>	asm("	bset	d0,a0@(0,d1:L)");
>	asm("	sne	d0");
>	asm("	andl	#1,d0");
>
>	asm("   unlk    a6");	/* for SunOS4.0 */
>	asm("   rts");		/* for SunOS4.0 */
>}
>
>
>Next, CFLAGS in unixport/makefile, add '-Bstatic' option for static binding,
>and add '-Bstatic' option where '/bin/ld' is called in file c/unixfasl.c
>
>- - Bye.
>PS:
> Sorry of my poor English X-<.
>				Mitsubishi Electric, Amagasaki, Japan
>				Taizo Kojima
Bob Drzyzgula
rcd@fed.frb.gov, uunet!fed!rcd
Federal Reserve Board, Washington, DC  20551

mlm@cs.brown.edu (Moises Lejter) (04/05/89)

	I went through my copy of the KCL code, and there is one more
	change I made that could have something to do with it -
	I don't remember what the symptoms were that made me realize
	it was a problem.  KCL was originally written for 4.2 BSD
	systems, and then the kernel allocated a fixed-size table of
	FILE structures.  KCL knew about that table, and used that
	knowledge to close all open files, when needed.
	Unfortunately, 4.3 BSD and SunOS 4.0 systems allocate new FILE 
	structures dynamically (only the initial stdin, stdout, stderr
	are in a preallocated table), so the trick KCL uses does not work
	anymore (I believe it causes seg faults, when KCL tries to
	access and close the fourth file).

	If you look at the code in unixsave.c, function Lsave(),
	you will see it loops over the (nonexistent) file table,
	closing any open files it finds.  At Brown, I added the following
	three functions to unixfsys.c, and then replaced all
	calls everywhere to fopen() and fclose() to calls to these
	functions. I also had Lsave() call the function closeAllOpenFiles(),
	instead of looping as it does.

	At the end of this message you will find context diffs of
	unixfsys.c, unixsave.c, unixfasl.c, main.c, and file.d to
	achieve this.  Note that to have these changes actually
	manifest themselves, you have to #define BRUNIX.  I hadn't
	intended then to make these changes public...

							Moises

-----------------------------------------------------------------------------
Internet/CSnet:   mlm@cs.brown.edu		BITNET:  mlm@browncs.BITNET
UUCP:    ...!uunet!brunix!mlm			Phone:	 (401)863-7664
USmail:  Moises Lejter, Box 1910 Brown University, Providence RI 02912


-----context diffs follow-----


*** unixfsys.c.orig	Tue Jan 26 17:10:36 1988
--- unixfsys.c	Thu Oct 13 14:31:16 1988
***************
*** 4,9 ****
--- 4,20 ----
  proper "License Agreement for Kyoto Common LISP" with SIGLISP.
  */
  
+ /*
+  * Modification History:
+  *   88.02      - File access routines
+  *     Author: Moises Lejter
+  *     Description:
+  *	 KCL as supplied assumes BSD4.2 implementation of internal file table.
+  *       Calls to "fopen()" and "fclose()" were replaced with calls to
+  *       "openFile()" and "closeFile()", which guarantee assumption will
+  *       hold even though internal opsys implementation may change.
+  */
+ 
  #include "include.h"
  #include <sys/types.h>
  #include <sys/stat.h>
***************
*** 10,15 ****
--- 21,33 ----
  #include <pwd.h>
  
  
+ #ifdef BRUNIX
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
+ #endif
+ 
+ 
  #define	MAXPATHLEN	1024
  
  object Kwild;
***************
*** 641,643 ****
--- 659,710 ----
  
  	make_si_function("CHDIR", siLchdir);
  }
+ 
+ 
+ #ifdef BRUNIX
+ 
+ #undef fopen
+ #undef fclose
+ 
+ FILE **filesAlreadyOpened = NULL;
+ 
+ FILE *openFile( file, mode )
+     char *file, *mode;
+     {
+ 	FILE *newFile = fopen( file, mode );
+ 
+ 	if (! newFile) return( newFile );
+ 
+ 	if (! filesAlreadyOpened)
+ 	    filesAlreadyOpened =
+ 		(FILE **) calloc( getdtablesize(), sizeof( FILE * ));
+ 
+ 	return( filesAlreadyOpened[ fileno( newFile ) ] = newFile );
+     }
+ 
+ 
+ int closeFile( someFile )
+     FILE *someFile;
+     {
+ 	int result = fclose( someFile );
+ 
+ 	if (filesAlreadyOpened)
+ 	    filesAlreadyOpened[ fileno( someFile ) ] = NULL;
+ 
+ 	return( result );
+     }
+ 
+ 
+ void closeAllOpenFiles()
+     {
+ 	if (filesAlreadyOpened)
+ 	    {
+ 		FILE **ptr, **end = filesAlreadyOpened + getdtablesize();
+ 		
+ 		for (ptr = filesAlreadyOpened; ptr < end; ptr++ )
+ 		    if (*ptr) fclose( *ptr );
+ 	    }
+     }
+ 
+ #endif
+ 
*** unixsave.c.orig	Tue Jan 26 17:10:33 1988
--- unixsave.c	Thu Oct 13 14:31:35 1988
***************
*** 8,15 ****
--- 8,34 ----
  	unixsave.c
  */
  
+ /*
+  * Modification History:
+  *   88.02      - File access routines
+  *     Author: Moises Lejter
+  *     Description:
+  *	 KCL as supplied assumes BSD4.2 implementation of internal file table.
+  *       Calls to "fopen()" and "fclose()" were replaced with calls to
+  *       "openFile()" and "closeFile()", which guarantee assumption will
+  *       hold even though internal opsys implementation may change.
+  */
+ 
  #include "include.h"
  
+ 
+ #ifdef BRUNIX
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
+ #endif
+ 
+ 
  /* When MACHINE is S3000, use fcntl.h */
  #ifdef S3000
  #include <fcntl.h>
***************
*** 318,323 ****
--- 337,345 ----
  /*
  	_cleanup();
  */
+ #ifdef BRUNIX
+ 	closeAllOpenFiles();
+ #else	
  	{
  		FILE *p;
  		int nfile;
***************
*** 330,335 ****
--- 352,358 ----
  		for (p = &_iob[3];  p < &_iob[nfile];  p++)
  			fclose(p);
  	}
+ #endif
  	memory_save(kcl_self, filename);
  /*
  	_exit(0);
*** unixfasl.c.orig	Tue Jan 26 17:10:28 1988
--- unixfasl.c	Thu Oct 13 14:32:49 1988
***************
*** 4,10 ****
--- 4,28 ----
  proper "License Agreement for Kyoto Common LISP" with SIGLISP.
  */
  
+ /*
+  * Modification History:
+  *   88.02      - File access routines
+  *     Author: Moises Lejter
+  *     Description:
+  *	 KCL as supplied assumes BSD4.2 implementation of internal file table.
+  *       Calls to "fopen()" and "fclose()" were replaced with calls to
+  *       "openFile()" and "closeFile()", which guarantee assumption will
+  *       hold even though internal opsys implementation may change.
+  */
+ 
  #include "include.h"
+ 
+ 
+ #ifdef BRUNIX
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
+ #endif
  
  
  #ifdef BSD
*** main.c.orig	Tue Jan 26 17:10:21 1988
--- main.c	Thu Oct 13 14:32:10 1988
***************
*** 9,15 ****
--- 9,34 ----
  	IMPLEMENTATION-DEPENDENT
  */
  
+ /*
+  * Modification History:
+  *   88.02      - File access routines
+  *     Author: Moises Lejter
+  *     Description:
+  *	 KCL as supplied assumes BSD4.2 implementation of internal file table.
+  *       Calls to "fopen()" and "fclose()" were replaced with calls to
+  *       "openFile()" and "closeFile()", which guarantee assumption will
+  *       hold even though internal opsys implementation may change.
+  */
+ 
  #include "include.h"
+ 
+ 
+ #ifdef BRUNIX
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
+ #endif
+ 
  
  bool saving_system = FALSE;
  
*** file.d.orig	Tue Jan 26 17:10:28 1988
--- file.d	Fri Mar 25 23:23:23 1988
***************
*** 15,21 ****
--- 15,42 ----
  	It also contains read_fasl_data.
  */
  
+ /*
+  * Modification History:
+  *   88.02      - File access routines
+  *     Author: Moises Lejter
+  *     Description:
+  *	 KCL as supplied assumes BSD4.2 implementation of internal file table.
+  *       Calls to "fopen()" and "fclose()" were replaced with calls to
+  *       "openFile()" and "closeFile()", which guarantee assumption will
+  *       hold even though internal opsys implementation may change.
+  */
+ 
  #include "include.h"
+ 
+ 
+ #ifdef VAX
+ #ifdef BRUNIX
+ #define fopen( file, mode )	openFile( file, mode )
+ #define fclose( file )		closeFile( file )
+ extern FILE *openFile();
+ #endif
+ #endif
+ 
  
  #define	kclgetc(FP)		getc(FP)
  #define	kclungetc(C, FP)	ungetc(C, FP)

-----------------------------------------------------------------------------
Internet/CSnet:   mlm@cs.brown.edu		BITNET:  mlm@browncs.BITNET
UUCP:    ...!uunet!brunix!mlm			Phone:	 (401)863-7664
USmail:  Moises Lejter, Box 1910 Brown University, Providence RI 02912