tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Re: Multiple compilation states parallel in memory


From: Kalle Kataja
Subject: [Tinycc-devel] Re: Multiple compilation states parallel in memory
Date: Tue, 30 Nov 2010 01:24:47 +0200 (EET)

P.S. I just noticed this will probably not work as a generic solution - the way I use it is that I have another routine that copies the data into a different data structure.

Specifically my line:

          space [ret*2] = s->link->data + sym->st_name;

Will most probably not work as it's obviously a pointer to something that may get overwritten, unless that is further memcopied by you after obtaining the list.

My apologies for missing that.


On Tue, 30 Nov 2010, Kalle Kataja wrote:

Dear all,

I hope this finds you well, in good spirit and having a good day.

Firstly I would like to thank everyone who has contributed to TinyCC.

I think it's a great project, and I hope there will be people keeping it alive.

I integrated it into my project at http://gd.meizo.com/

One of my needs was/is that I need to compile and access multiple objects.

I found out this was not fully possible, apparently because some global variables get overwritten including symbol tables, though the compiled code can be called even after creating new compiler instances.

Being a complete novice at compiler issues, I don't know if this will help anyone else, or if there's a better way, but what I did was to add a function that I for my own use named tcc_get_symbols(), so that I can after compiling an object read all the symbols into another array, and that way look function pointers up from that and maintain multiple compiled objects in memory.

== 8< tccelf.c ==
/* read global ELF symbols into space that can contain max_syms */
int tcc_get_symbols(TCCState *s1, void **space, int max_syms)
{
 Section *s = symtab_section;
   ElfW(Sym) *sym;
   Section *hs;
   int nbuckets, sym_index, h, ret;

   hs = s->hash;
   if (!hs || max_syms < 1)
       return 0;
   ret = 0;
   nbuckets = ((int *)hs->data)[0];

   for (h = 0; h < nbuckets; h++)
     {
        sym_index = ((int *)hs->data)[2 + h];

        while (sym_index != 0) {
          sym = &((ElfW(Sym) *)s->data)[sym_index];
          space [ret*2] = s->link->data + sym->st_name;
          space [ret*2+1] = (void *)(long)sym->st_value;
          if (++ret >= max_syms)
            return ret;
          sym_index = ((int *)hs->data)[2 + nbuckets + sym_index];
        }
     }

   return ret;
}
== 8< ==

== 8< libtcc.h ==
/* read global ELF symbols into space that can contain max_syms */
LIBTCCAPI int tcc_get_symbols(TCCState *s, void **space, int max_syms);
== 8< ==

Keep up the good work!

With best wishes,

Kalle.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]