From: Camm Maguire
Subject: GCL 2.6.5 Solaris errata
Date: 
Message-ID: <54zn4l4ezu.fsf@intech19.enhanced.com>
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_info<file_h->e_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);
=============================================================================

Take care,

-- 
Camm Maguire			     			ยทยทยทยท@enhanced.com
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah