Example #1
0
/* add symbols in object file to local symbol map */
void readsymbols(section* symtab, section* strtab, jt_map** symbolmap)
{
  int i;
  Elf32_Sym* thissym;
  
  for (i=1; i<symtab->content->length/sizeof(Elf32_Sym); i++)
  {
    mapentry* mentry = jt_new(mapentry);

    thissym = buffer_IDX(symtab->content, Elf32_Sym, i);

    mentry->name = symbolname(thissym, strtab);
    mentry->binding = ELF32_ST_BIND(thissym->st_info);
    mentry->symtabentry = i;
    mentry->backpatches = 0;

#ifdef DEBUG
/*    fprintf(stderr, "Read symbol %s\n", mentry->name);*/
#endif
    jt_map_insert(symbolmap, mentry->name, mentry);
  }
}
Example #2
0
File: print.c Project: jaw0/jlisp
void prnobj(Obj a, Obj stream, int how){
	int typ = TYPEOFX(a);
	int (*printfnc)(Obj,Obj,int);
	char buf[8];
	char *foo;
	Obj radix;
	int base;
	
	switch( typ ){
	  case TPVF_IMMED:
		if( INUMP( a )){
			/* int */
			radix = getvalue( sym_oradix);
			if(DEFINEDP(radix)&& INUMP(radix))
				base = CINT(radix);
			else
				base = 10;
			if(how) base = 10;
			printnum(stream, CINT(a), base, 0,0);
		} else if( ICHARP( a )){
			/* char */
			foo = 0;
			if(how){
				writestr(stream, "#\\");
				foo = spec_repr( CCHAR(a), 0 );
			}
			if(foo)
				writestr(stream, foo);
			else
				writechar(stream, CCHAR(a));
		} else if( ICONSTP( a )){
			/* const sym */
			switch( a ){

			  case IC_NIL:
				writestr(stream, "()");
				break;

			  case IC_TRUE:
				writestr(stream, "#t");
				break;

			  case IC_FALSE:
				writestr(stream, "#f");
				break;

			  case IC_UNDEF:
				writestr(stream, "#<undefined>");
				break;

			  case IC_UNSPEC:
				writestr(stream, "#<unspecified>");
				break;

			  case IC_EOF:
				writestr(stream, "#<EOF>");
				break;

			  default:
				writestr(stream, "#<<send in bug report> IC_0x");
				printnum(stream, a, 16,0,0);
				writestr(stream, "?>");
				break;
			}
		} else if ( SYMBOLP( a )){
			writestr(stream, symbolname(a) );
		} else {
			writestr(stream, "#<<send in bug report> IMM_0x");
			printnum(stream, a, 16,0,0);
			writestr(stream, "?>");
		}
		break;
#if 0
	  case TPV_SYMBOL:
		writestr(stream, CCHARS(a));
		break;
#endif
	  case TPV_SYM_BOX:
		if(how)
			writestr(stream, symbolname( MAKSYM(CSYM_BOX(a)->id )));
		else{
			writestr(stream, "#<[");
			writestr(stream, symbolname( MAKSYM(CSYM_BOX(a)->id )));
			writestr(stream, "]>");
		}
		break;

	  default:
		printfnc = jlisp_vtbl[ typ ].print;

		if( !printfnc || ! printfnc(a, stream, how) ){
			writestr(stream, "#<_");
			printnum(stream, typ, 10,0,0);
			writestr(stream, "_0x");
			printnum(stream, a, 16, 0,0);
			writestr(stream, ">");
		}
		break;
	}
}
Example #3
0
/* find global symbols defined in an object file, add to global symbol map.
   Overrides weak symbols with global symbols.
*/
void findglobals(image* in, jt_map** global)
{
  uint5 i;
  
  for (i=1; i<in->symtab.content->length/sizeof(Elf32_Sym); i++)
  {
    Elf32_Sym* sym = buffer_IDX(in->symtab.content, Elf32_Sym, i);
    char* name = symbolname(sym, &in->strtab);
    mapentry* oldmsym = jt_map_find(*global, name);
    uint5 newbinding = ELF32_ST_BIND(sym->st_info);
    
    if ((newbinding!=STB_GLOBAL && newbinding!=STB_WEAK) || 
        sym->st_shndx==SHN_UNDEF) continue;
    
    if (oldmsym)
    {
      if (!in->library)
      {
        /* We have a symbol with this name already */
        switch (oldmsym->binding)
        {
          case STB_GLOBAL:
          if (newbinding==STB_GLOBAL)
          {
            fprintf(stderr, "Multiply-defined global symbol %s\n", name);
            exit(1);
          }
          /* Else new symbol is weak, we can ignore it */
          break;

          case STB_WEAK:
          if (newbinding==STB_WEAK)
          {
            #ifdef DEBUG2
            fprintf(stderr, "Warning: multiply-defined weak symbol %s\n", name);
            #endif
          }
          else
          {
            /* Override old weak symbol */
            oldmsym->binding = STB_GLOBAL;
            oldmsym->symtabentry = i;
            oldmsym->in_image = in;
          }
          break;

          default:
          fprintf(stderr, "Non-global symbol in global symbol map? (%s)\n",
                  name);
          exit(1);
        }
      }
    }
    else
    {
      /* Generate a new global map entry */
      mapentry* msym = jt_new(mapentry);
      
      msym->name = name;
      msym->binding = newbinding;
      msym->symtabentry = i;
      msym->in_image = in;
      msym->index = -1u;
      msym->backpatches = 0;
      
      jt_map_insert(global, name, msym);
    }
  }
}