/[gcl]/gcl/o/sfaslelf.c
ViewVC logotype

Diff of /gcl/o/sfaslelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by camm, Wed Jun 12 23:56:59 2002 UTC revision 1.8 by camm, Wed Jul 24 19:05:53 2002 UTC
# Line 30  License for more details. Line 30  License for more details.
30  /* #include "include.h" */  /* #include "include.h" */
31  #include "ext_sym.h"  #include "ext_sym.h"
32  #include <stdio.h>  #include <stdio.h>
33    #include <stdlib.h>
34  #include <sys/types.h>  #include <sys/types.h>
35  #include <sys/mman.h>  #include <sys/mman.h>
36  #include <sys/stat.h>  #include <sys/stat.h>
# Line 140  round_up(address,n) Line 141  round_up(address,n)
141    
142  int use_mmap;  int use_mmap;
143    
144    int
145    get_section_number(name)
146         char *name;
147        
148    {int k ;
149     for (k = 1; k < file_h->e_shnum;
150          k++)
151       {
152         if (!strcmp (section_names + SECTION_H(k).sh_name,
153                      name))
154           return k;
155       }
156    /* fprintf(stderr,"could not find section %s\n", name); */
157     return 0;
158    }
159    
160    int
161  fasload(faslfile)  fasload(faslfile)
162       object faslfile;       object faslfile;
163  {  FILE *fp;  {  FILE *fp;
# Line 289  fasload(faslfile) Line 306  fasload(faslfile)
306       { FEerror(0,"Init address not found ");       { FEerror(0,"Init address not found ");
307       }       }
308    
309     { int rel_stab_index = -1;     {
310       int j=0;       int j=0;
311       for (j=1 ; j <  file_h->e_shnum ; j++)       for (j=1 ; j <  file_h->e_shnum ; j++)
312         {         {
# Line 367  fasload(faslfile) Line 384  fasload(faslfile)
384     vs_top = old_vs_top;     vs_top = old_vs_top;
385    
386     if(symbol_value(sLAload_verboseA)!=Cnil)     if(symbol_value(sLAload_verboseA)!=Cnil)
387       printf("start address -T %x ",memory->cfd.cfd_start);       printf("start address -T %p ",memory->cfd.cfd_start);
388     return(memory->cfd.cfd_size);     return(memory->cfd.cfd_size);
389    
390  #endif /* STAND */  #endif /* STAND */
# Line 375  fasload(faslfile) Line 392  fasload(faslfile)
392   }   }
393    
394    
 get_section_number(name)  
      char *name;  
       
 {int k ;  
  for (k = 1; k < file_h->e_shnum;  
       k++)  
    {  
      if (!strcmp (section_names + SECTION_H(k).sh_name,  
                   name))  
        return k;  
    }  
 /* fprintf(stderr,"could not find section %s\n", name); */  
  return 0;  
 }  
   
 static void  
 relocate_symbols(sym,nsyms,nscns,init_address_ptr)  
  Elf32_Sym *sym;  
  int nsyms;  
  int nscns;  
  int *init_address_ptr; /* offset of init_address */  
 {  int siz = symsize;  
   while (--nsyms >= 0)  
     { switch(ELF32_ST_BIND(sym->st_info))  
         { case STB_LOCAL:  
             if (sym->st_shndx == SHN_ABS || sym->st_shndx >= nscns) break;  
           
             if ((SECTION_H(sym->st_shndx).sh_flags & SHF_ALLOC) == 0)  
               {  
                 switch (SECTION_H(sym->st_shndx).sh_type)  
                   {  
                   case SHT_NULL:  
                   case SHT_PROGBITS:  
                   case SHT_NOTE:  
                   case SHT_STRTAB:  
                     /* These occur in Linux.  
                        Ignore symbols for such sections. */  
                     break;  
                   default:  
                     printf("[unknown rel secn %d type=%d]",  
                            sym->st_shndx,  
                            SECTION_H(sym->st_shndx).sh_type);  
                   }  
               }  
             else  
               sym->st_value += (int) (start_address + section[sym->st_shndx].start);  
             break;  
           case STB_GLOBAL:  
          if (sym->st_shndx == SHN_UNDEF  
              || sym->st_shndx == SHN_COMMON  
              )  
            {  set_symbol_address(sym,string_table + sym->st_name);  
             }  
             else  
               if (sym->st_shndx == text_index &&  
                   bcmp("init_",string_table + sym->st_name,4) == 0)  
                 {  
                   *init_address_ptr = sym->st_value;  
   
                   }  
             else          
               {printf("[unknown global sym %s]",string_table + sym->st_name);}  
             break;  
           default:  
             {printf("[unknown bind type %s]",ELF32_ST_BIND(sym->st_info));}  
           }  
       sym = (void *)sym + siz;  
     }  
 }  
   
   
395  /*  #ifdef HAVE_LIBBFD */  /*  #ifdef HAVE_LIBBFD */
396    
397  /*  typedef struct { */  /*  typedef struct { */
# Line 567  Elf32_Word sh_type; Line 513  Elf32_Word sh_type;
513  {  {
514    char *where ;    char *where ;
515    {    {
     unsigned int new_value;  
516      unsigned int a,b,p,s,val;      unsigned int a,b,p,s,val;
517    
518      if (sh_type == SHT_RELA)      if (sh_type == SHT_RELA)
519        a = reloc_info->r_addend;        a = reloc_info->r_addend;
520      else if (sh_type == SHT_REL)      else if (sh_type == SHT_REL)
521        a = 0;        a = 0;
522      else      else {
523        FEerror("relocate() error: unknown sh_type in ELF object");        FEerror("relocate() error: unknown sh_type in ELF object");
524          a=0;
525        }
526      b = (unsigned int) the_start;      b = (unsigned int) the_start;
527      s = symbol_table[ELF32_R_SYM(reloc_info->r_info)].st_value;      s = symbol_table[ELF32_R_SYM(reloc_info->r_info)].st_value;
528  /*      printf("Doing %s\n",string_table + symbol_table[ELF32_R_SYM(reloc_info->r_info)].st_name); */  /*      printf("Doing %s\n",string_table + symbol_table[ELF32_R_SYM(reloc_info->r_info)].st_name); */
# Line 689  Elf32_Word sh_type; Line 636  Elf32_Word sh_type;
636    
637  #include "sfasli.c"  #include "sfasli.c"
638    
639    void
640  set_symbol_address(sym,string)  set_symbol_address(sym,string)
641  Elf32_Sym *sym;  Elf32_Sym *sym;
642  char *string;  char *string;
# Line 712  char *string; Line 660  char *string;
660    else{FEerror("symbol table not loaded",0,0);}    else{FEerror("symbol table not loaded",0,0);}
661  }  }
662    
663    static void
664    relocate_symbols(sym,nsyms,nscns,init_address_ptr)
665     Elf32_Sym *sym;
666     int nsyms;
667     int nscns;
668     int *init_address_ptr; /* offset of init_address */
669    {  int siz = symsize;
670      while (--nsyms >= 0)
671        { switch(ELF32_ST_BIND(sym->st_info))
672            { case STB_LOCAL:
673                if (sym->st_shndx == SHN_ABS || sym->st_shndx >= nscns) break;
674            
675                if ((SECTION_H(sym->st_shndx).sh_flags & SHF_ALLOC) == 0)
676                  {
677                    switch (SECTION_H(sym->st_shndx).sh_type)
678                      {
679                      case SHT_NULL:
680                      case SHT_PROGBITS:
681                      case SHT_NOTE:
682                      case SHT_STRTAB:
683                        /* These occur in Linux.
684                           Ignore symbols for such sections. */
685                        break;
686                      default:
687                        printf("[unknown rel secn %d type=%d]",
688                               sym->st_shndx,
689                               SECTION_H(sym->st_shndx).sh_type);
690                      }
691                  }
692                else
693                  sym->st_value += (int) (start_address + section[sym->st_shndx].start);
694                break;
695              case STB_GLOBAL:
696             if (sym->st_shndx == SHN_UNDEF
697                 || sym->st_shndx == SHN_COMMON
698                 )
699               {  set_symbol_address(sym,string_table + sym->st_name);
700                }
701                else
702                  if (sym->st_shndx == text_index &&
703                      bcmp("init_",string_table + sym->st_name,4) == 0)
704                    {
705                      *init_address_ptr = sym->st_value;
706    
707                      }
708                else        
709                  {printf("[unknown global sym %s]",string_table + sym->st_name);}
710                break;
711              default:
712                {printf("[unknown bind type %d]",ELF32_ST_BIND(sym->st_info));}
713              }
714          sym = (void *)sym + siz;
715        }
716    }
717    
718  #define STRUCT_SYMENT Elf32_Sym  #define STRUCT_SYMENT Elf32_Sym
719    
720  /* dont try to add extra bss stuff here.   It is not really  /* dont try to add extra bss stuff here.   It is not really
# Line 719  common so other files can't reference it Line 722  common so other files can't reference it
722  should use static.  should use static.
723  */  */
724    
725    int
726  get_extra_bss(symbol_table,length,start,ptr,bsssize)  get_extra_bss(symbol_table,length,start,ptr,bsssize)
727  int length,bsssize,start;  int length,bsssize,start;
728  STRUCT_SYMENT *symbol_table;  STRUCT_SYMENT *symbol_table;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26