Greetings! It appears that solaris ld, at least in conjunction with recent gcc, can place the .data section before the .text section when C optimization is on, exposing an error in our handling of init_address in the loader. Mike, you might want to look into this too. The solaris machine to which I have access just upgraded its gcc, informing me of this issue. Here is an errata patch which fixes the problem, also posted to the GCL website: =============================================================================
Index: o/sfaslelf.c
===================================================================
RCS file: /cvsroot/gcl/gcl/o/sfaslelf.c,v
retrieving revision 1.8.6.6
retrieving revision 1.15
diff -u -w -r1.8.6.6 -r1.15
--- o/sfaslelf.c 8 Mar 2004 22:02:24 -0000 1.8.6.6
+++ o/sfaslelf.c 23 Aug 2004 23:09:23 -0000 1.15
@@ -133,13 +132,12 @@


/* align for power of two n */
-static void *
-round_up(address,n)
- unsigned int address,n;
-{
- return (void *)((address + n -1) & ~(n-1)) ;
-}
-#define ROUND_UP(a,b) round_up(a,b)
+/* static void * */
+/* round_up(unsigned long address,unsigned long n) { */
+/* { */
+/* return (void *)((address + n -1) & ~(n-1)) ; */
+/* } */
+#define ROUND_UP(_addr,_ps) ((void *)(((unsigned long)_addr + (unsigned long)_ps -1) & ~((unsigned long)_ps-1)))

int use_mmap;

@@ -309,46 +307,31 @@
}

{
- int j=0;
- for (j=1 ; j < file_h->e_shnum ; j++)
- {
+ int j;
+
+ for (j=1 ; j < file_h->e_shnum ; j++) {
+
shp = &SECTION_H(j);
if ((shp->sh_type == SHT_RELA || shp->sh_type == SHT_REL) &&
shp->sh_infoe_shnum &&
- (SECTION_H(shp->sh_info).sh_flags & SHF_ALLOC))
- {
- int index_to_relocate = shp->sh_info;
+ (SECTION_H(shp->sh_info).sh_flags & SHF_ALLOC)
+ && (SECTION_H(shp->sh_info).sh_type == SHT_PROGBITS
+ || SECTION_H(shp->sh_info).sh_type == SHT_NOBITS)) {
+
+ int k;
+ char *rel = (char *) base + shp->sh_offset;
+
if (symtab_index != shp->sh_link)
FEerror("unexpected symbol table used",0);
- the_start = start_address + section[index_to_relocate].start;
- }
-/* else if (shp->sh_type == SHT_REL */
-/* && (SECTION_H(shp->sh_info).sh_flags & SHF_ALLOC)) */
-/* { */
-/* int index_to_relocate = shp->sh_info; */
-/* if (symtab_index != shp->sh_link) */
-/* FEerror("unexpected symbol table used"); */
-/* the_start = start_address + section[index_to_relocate].start; */
-/* } */
+ the_start = start_address + section[shp->sh_info].start;

- else if ( (shp->sh_type == SHT_REL) || (shp->sh_type == SHT_RELA) )
- { if (/* get_section_number(".rel.stab") == j || */
- /* Newer gcc uses these section name -- CMM 20040224*/
- !strncmp(section_names+SECTION_H(j).sh_name,".rel.debug",10) ||
- /* old in for backward compatibility */
- !strcmp(section_names+SECTION_H(j).sh_name,".rel.stab"))
- continue;
- FEerror("unknown rel type",0);
- }
- else
- continue;
- {
- int k=0;
- char *rel = (char *) base + shp->sh_offset;
for (k= 0; k< shp->sh_size ; k+= shp->sh_entsize)
relocate(symbol_table,(Elf32_Rela *)(rel + k),shp->sh_type);
+
}
+
}
+
}

#ifdef STAND
@@ -692,7 +675,7 @@
default:
printf("[unknown rel secn %d type=%d]",
sym->st_shndx,
- SECTION_H(sym->st_shndx).sh_type);
+ (int)SECTION_H(sym->st_shndx).sh_type);
}
}
else
@@ -708,7 +691,7 @@
if (sym->st_shndx == text_index &&
bcmp("init_",string_table + sym->st_name,4) == 0)
{
- *init_address_ptr = sym->st_value;
+ *init_address_ptr = sym->st_value+section[sym->st_shndx].start;

}
else
Index: o/sfaslbfd.c
===================================================================
RCS file: /cvsroot/gcl/gcl/o/sfaslbfd.c,v
retrieving revision 1.12.4.1.2.4
retrieving revision 1.18
diff -u -w -r1.12.4.1.2.4 -r1.18
--- o/sfaslbfd.c 20 Mar 2004 01:38:25 -0000 1.12.4.1.2.4
+++ o/sfaslbfd.c 23 Aug 2004 23:09:23 -0000 1.18
@@ -306,7 +299,7 @@
struct bfd_link_hash_entry *h;

if (!strncmp(entry_name_ptr,q[u]->name,5)) {
- init_address=q[u]->value;
+ init_address=q[u]->value+(q[u]->section->output_section->vma-(unsigned long)memory->cfd.cfd_start);
continue;
}

Index: o/sfasli.c
===================================================================
RCS file: /cvsroot/gcl/gcl/o/sfasli.c,v
retrieving revision 1.10.4.2.2.7
retrieving revision 1.20
diff -u -w -r1.10.4.2.2.7 -r1.20
--- o/sfasli.c 6 Mar 2004 01:57:43 -0000 1.10.4.2.2.7
+++ o/sfasli.c 23 Aug 2004 23:10:07 -0000 1.20
@@ -118,7 +118,7 @@

char tmpfile1[80],command[300];

- snprintf(tmpfile1,sizeof(tmpfile1),"rsym%d",getpid());
+ snprintf(tmpfile1,sizeof(tmpfile1),"rsym%d",(int)getpid());
#ifndef STAND
coerce_to_filename(symbol_value(sSAsystem_directoryA),
system_directory);
Index: gcl_cmpmain.lsp
===================================================================
RCS file: /cvsroot/gcl/gcl/cmpnew/gcl_cmpmain.lsp,v
retrieving revision 1.16
diff -u -r1.16 gcl_cmpmain.lsp
--- gcl_cmpmain.lsp 5 Aug 2004 22:00:41 -0000 1.16
+++ gcl_cmpmain.lsp 23 Aug 2004 23:28:49 -0000
@@ -847,7 +847,7 @@
(setq sfiles (concatenate 'string sfiles " " (namestring tem)))))
sfiles)
si::*system-directory*
- #+gnu-ld (format nil "-Wl,-Map ~a" (namestring map))
+ #+gnu-ld (format nil "-Wl,-Map ~a" (namestring map)) #-gnu-ld ""
(let* ((par (namestring (make-pathname :directory '(:parent))))
(i (concatenate 'string " " par))
(j (concatenate 'string " " si::*system-directory* par)))
=============================================================================

On 64bit machines, (+ most-negative-fixnum -1) is not calculated correctly. The patch below fixes this. =============================================================================
Index: h/mp.h
===================================================================
RCS file: /cvsroot/gcl/gcl/h/mp.h,v
retrieving revision 1.6.6.1
diff -u -r1.6.6.1 mp.h
--- h/mp.h 27 Sep 2003 16:09:48 -0000 1.6.6.1
+++ h/mp.h 29 Oct 2004 20:17:42 -0000
@@ -61,8 +61,10 @@
action \
((((CMPt1=(x))+1024)&-2048)==0?small_fixnum(CMPt1):make_fixnum1(CMPt1));}while(0)

+#define ineg(a_) (sizeof(a_)==sizeof(unsigned) ? (unsigned)-(a_) : (unsigned long)-(a_))
+
#define addii mpz_add
-#define addsi(u,a,b) (a >= 0 ? mpz_add_ui(u,b,a) : mpz_sub_ui(u,b,-a))
+#define addsi(u,a,b) (a >= 0 ? mpz_add_ui(u,b,a) : mpz_sub_ui(u,b,ineg(a)))
#define addss(u,a,b) addsi(u,a,SI_TO_MP(b,big_fixnum1))

#define mulii mpz_mul
@@ -71,9 +73,9 @@

#define subii mpz_sub
#define subsi(u,a,b) mpz_sub(u,SI_TO_MP(a,big_fixnum1),b)
-#define subis(u,a,b) (b >= 0 ? mpz_sub_ui(u,a,b) : mpz_add_ui(u,a,-b))
+#define subis(u,a,b) (b >= 0 ? mpz_sub_ui(u,a,b) : mpz_add_ui(u,a,ineg(b)))
#define subss(u,a,b) subis(u,SI_TO_MP(a,big_fixnum1),b)
-#define shifti(u,a,w) (w>=0 ? mpz_mul_2exp(u,a,w) : mpz_fdiv_q_2exp(u,MP(x),-w))
+#define shifti(u,a,w) (w>=0 ? mpz_mul_2exp(u,a,w) : mpz_fdiv_q_2exp(u,MP(x),ineg(w)))



=============================================================================

Older gcc cannot process gmp_wrappers.h. The following fixes this:
=============================================================================
--- gcl-2.6.5/h/gmp_wrappers.h 2004-08-16 17:28:20.000000000 +0000
+++ gclcvs-2.7.0/h/gmp_wrappers.h 2004-09-07 16:20:49.000000000 +0000
@@ -96,8 +96,8 @@

#define MEM_GMP_CALL(n_,rt_,a_,s_,b_...) \
GMP_EXTERN_INLINE Join(RF_,rt_) Join(m,a_)(Join(P,n_)(b_)) { \
- Join(RD_,rt_);\
int j;\
+ Join(RD_,rt_);\
jmp_gmp=0;\
if ((j=setjmp(gmp_jmp)))\
GBC(j);\
=============================================================================

Newer binutils don't define _raw_size in the section structure. Here is a patch which works with old and new versions:
=============================================================================
Index: o/sfaslbfd.c
===================================================================
RCS file: /cvsroot/gcl/gcl/o/sfaslbfd.c,v
retrieving revision 1.18
retrieving revision 1.20
diff -u -r1.18 -r1.20
--- o/sfaslbfd.c 23 Aug 2004 23:09:23 -0000 1.18
+++ o/sfaslbfd.c 25 Nov 2004 18:07:11 -0000 1.20
@@ -256,7 +256,7 @@

current=round_up(current,1<alignment_power);

- current+=s->_raw_size;
+ current+=bfd_section_size(b,s);

}
curr_size=(unsigned long)current;
@@ -281,7 +281,7 @@

m=round_up(m,1<alignment_power);
s->output_section->vma=(unsigned long)m;
- m+=s->_raw_size;
+ m+=bfd_section_size(b,s);

}

@@ -337,6 +337,8 @@

for (s=b->sections;s;s=s->next) {

+ unsigned long ss=bfd_section_size(b,s);
+
if (!(s->flags & SEC_LOAD))
continue;

@@ -346,9 +348,10 @@
v,0,q))
FEerror("Cannot get relocated section contents\n",0);

- memcpy((void *)(unsigned long)s->output_section->vma,v,s->_raw_size);
+ memcpy((void *)(unsigned long)s->output_section->vma,v,ss);

}
+
}

dum.sm.sm_object1=faslfile;
=============================================================================

This patch allows compile-file to process pathnames with white space on Windows.

=============================================================================
Index: cmpnew/gcl_cmpmain.lsp
===================================================================
RCS file: /cvsroot/gcl/gcl/cmpnew/gcl_cmpmain.lsp,v
retrieving revision 1.1.2.12.6.1
diff -u -r1.1.2.12.6.1 gcl_cmpmain.lsp
--- cmpnew/gcl_cmpmain.lsp 5 Aug 2004 22:00:06 -0000 1.1.2.12.6.1
+++ cmpnew/gcl_cmpmain.lsp 13 Jan 2005 22:10:53 -0000
@@ -547,7 +547,7 @@
(setq na (namestring
(make-pathname :name name :type (pathname-type(first args)))))
#+(or dos winnt)
- (format nil "~a -I~a ~a ~a -c -w ~a -o ~a"
+ (format nil "~a -I~a ~a ~a -c -w ~s -o ~s"
*cc*
(concatenate 'string si::*system-directory* "../h")
(if (and (boundp '*c-debug*) *c-debug*) " -g " "")
@@ -560,7 +560,7 @@
)

#-(or dos winnt)
- (format nil "~a -I~a ~a ~a -c '~a' -o '~a' ~a"
+ (format nil "~a -I~a ~a ~a -c ~s -o ~s ~a"
*cc*
(concatenate 'string si::*system-directory* "../h")
(if (and (boundp '*c-debug*) *c-debug*) " -g " "")
=============================================================================

Fedora Core 3 makes brk added pages non-executable by default. This
patch ensures executable permissions on all x86 Linux flavors.

=============================================================================
Index: h/386-linux.h
===================================================================
RCS file: /cvsroot/gcl/gcl/h/386-linux.h,v
retrieving revision 1.12.6.1
diff -u -r1.12.6.1 386-linux.h
--- h/386-linux.h 4 Apr 2004 19:29:08 -0000 1.12.6.1
+++ h/386-linux.h 13 Jan 2005 22:10:55 -0000
@@ -41,3 +41,18 @@

#define I386
#define SGC
+
+
+#ifdef IN_SFASL
+#include
+#define CLEAR_CACHE {\
+ void *p,*pe; \
+ p=(void *)((unsigned long)memory->cfd.cfd_start & ~(PAGESIZE-1)); \
+ pe=(void *)((unsigned long)(memory->cfd.cfd_start+memory->cfd.cfd_size) & ~(PAGESIZE-1)) + PAGESIZE-1; \
+ if (mprotect(p,pe-p,PROT_READ|PROT_WRITE|PROT_EXEC)) {\
+ fprintf(stderr,"%p %p\n",p,pe);\
+ perror("");\
+ FEerror("Cannot mprotect", 0);\
+ }\
+}
+#endif