tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] Patching symbols after tcc_relocate


From: Henry Weller
Subject: [Tinycc-devel] Patching symbols after tcc_relocate
Date: Sat, 09 Feb 2013 22:59:59 +0000
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.8 Emacs/24.2 (x86_64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO)

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



reply via email to

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