This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Dynamically wrap non dynamic symbol


On 21 September 2017 at 13:54, R0b0t1 <r030t1@gmail.com> wrote:
> Hello Chris,
>
> On Wed, Sep 20, 2017 at 7:28 PM, Christian Gagneraud <chgans@gmail.com> wrote:
>> Hi there,
>>
>> I am trying to wrap function calls, at runtime, in a dynamic way and
>> without having to modify the original binary.
>>
>
> That makes me think of dyncall: http://www.dyncall.org/.
>
>> Basically i have a function "void *install_hook(const char
>> *symbol_name, void *replacement)" that replace the function associated
>> with the symbol "symbol_name" with the function pointer "replacement",
>> and returns the original function pointer.
>>
>
> But this makes me think you want something else, i.e. you want to
> intercept calls made to a library. Is this right?

Yes, I can already intercept any calls to any dynamic libraries, by
looking up the symbol name in the PT_DYNAMIC segment, and modifying
the jmprel table.
But i want to do the same for private symbol of the executable.

>
>> Using dl_iterate_phdr it is possible to install wrapper around dynamic
>> symbols, but i would like to do the same for symbols that are local to
>> the executable.
>>
>> Objects are compiled with "gcc -fPIC" and executable is generate with "ld -pie".
>>
>> I thought that "ld -pie" will make all the local symbols show up in
>> the dynamic program section header, but it doesn't.
>>
>
> I think I understand the above but could personally use some
> explanation of it if you have the time.

Basically, what i'm trying to do is to force the linker to treat
private symbols as position independent exported symbol, so that my
trick above works on private symbols too.

Actually, --export-dynamic will add all the private executable symbols
to the PT_DYNAMIC dynsym tables, but won't generate relocation for
them, so i cannot intercept them.

Currently the executable code contains eg "callq 0xc15" when calling
one of this private symbol. I would prefer to have a call into the
PLT.

Some context: I'm working on a Qt/C++ profiling tool, and the idea is
that the user can at any moment requires traces for known overrides of
a particular object of a given class.
Since Qt provides introspection i can then deduce the list of symbols
that i need to intercept in order to profile these calls along the
class hierarchy (if virtual).

Chris


>
>> Is this even possible to install wrapper around local symbols?
>> If so would you have any information to share?
>>
>
> The most straightforward way I know of is to generate a fake library
> that calls the real one. I'm not sure how to adapt this to private
> symbols.
>
> Cheers,
>      R0b0t1.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]