kolibrios/programs/develop/libraries/menuetlibc/src/libmcoff/symtab.c
right-hearted 6496d04506 Adding menuetlibc back to its place in /programs/develop/libraries
This version of menuetlibc was taken from revision 4743, right before I made any changes

git-svn-id: svn://kolibrios.org@4973 a494cfbc-eb01-0410-851d-a64ba20cac60
2014-06-12 10:43:21 +00:00

49 lines
1.2 KiB
C

#include"mcoff.h"
#include<stdlib.h>
#include"string.h"
/* static inline void nprintf(char * s,int n)
{
printf("nprintf(%u, '",n);
for(;n;n--)
putch(*s++);
printf("')");
} */
SYMENT * find_coff_symbol(coffobj_t * obj,char * objname)
{
int namelen;
int symno;
int xlen;
SYMENT * symtab;
char * symnamep,symnamelen;
symtab=obj->co_symtab;
namelen=strlen(objname);
for(symno=0;symno<obj->co_filehdr->f_nsyms;symno++,symtab++)
{
if(symtab->e.e.e_zeroes==0)
{
symnamep=(char *)(((long)obj->co_strtab)+symtab->e.e.e_offset);
symnamelen=strlen(symnamep);
/* printf("strtab=%u %x %u ",symtab->e.e.e_offset,symnamep,symnamelen); */
} else {
symnamep=(char *)symtab->e.e_name;
symnamelen=strlen(symnamep);
if(symnamelen>E_SYMNMLEN)
symnamelen=E_SYMNMLEN;
}
/* nprintf(symnamep,symnamelen);
printf("\n"); */
if(symtab->e_scnum!=0 && namelen==symnamelen && !strncmp(objname,symnamep,namelen))
return symtab;
}
return NULL;
}
unsigned long mcoff_get_ref(coffobj_t * obj,char * symname)
{
SYMENT * sym=find_coff_symbol(obj,symname);
if(!sym) return 0;
return sym->e_value+obj->co_sections[sym->e_scnum-1].s_scnptr+obj->co_loadaddr;
}