I am interested in using libtcc to implement a REPL for a statically typed
language I am working.  Ideally I would like to be able to patch a symbol after
initial relocation following the re-definition of a function for example e.g.
.
.
.
    TCCState *s = compile(my_program);

    tcc_add_symbol(s, "add", add1Ptr);

    if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
        return 1;

    tcc_add_symbol(s, "add", add2Ptr);
.
.
.

The first problem I hit was that tcc_add_symbol does not allow re-definition so
I hacked add_elf_sym to allow it but the above still does not work although

    TCCState *s = compile(my_program);

    tcc_add_symbol(s, "add", add1Ptr);
    tcc_add_symbol(s, "add", add2Ptr);
    
    if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
        return 1;

does but isn't very useful.

Another option is to use ELF-Hook:

http://www.codeproject.com/Articles/70302/Redirecting-functions-in-shared-ELF-libraries
https://github.com/shoumikhin/ELF-Hook

which is possible if I use tcc to write out DLs, dlopen them and then patch them
with ELF-Hook but it would be much cleaner to be able to manipulate the symbols
directly after tcc_relocate.  Does anyone know if this is this already possible
with libtcc or how difficult it would be to add?

Thanks

Henry

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to