tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Patching symbols after tcc_relocate


From: grischka
Subject: Re: [Tinycc-devel] Patching symbols after tcc_relocate
Date: Sun, 10 Feb 2013 01:33:03 +0100
User-agent: Thunderbird 2.0.0.18 (X11/20081125)

Henry Weller wrote:
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);

That is not part of tcc_add_symbol, Instead you need an additional
selective relocation for just one symbol, such as:

        tcc_relocate_symbol(s, "add", add1Ptr, add2Ptr);

(not part of tinycc)

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?

You could change the linker to generate function pointers automatically,
Basically you'd link the program to itself as if it were in an external
DLL.  Non-trivial, also.

--- grischka


Thanks

Henry




reply via email to

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