This is the mail archive of the
mailing list for the binutils project.
Re: Dynamically wrap non dynamic symbol
- From: Christian Gagneraud <chgans at gmail dot com>
- To: R0b0t1 <r030t1 at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Thu, 21 Sep 2017 14:32:34 +1200
- Subject: Re: Dynamically wrap non dynamic symbol
- Authentication-results: sourceware.org; auth=none
- References: <CABxGUTgHuVTjnWnMBPcodA5ninrGA+D23tMT+_4ZyS3aH2D7Zg@mail.gmail.com> <CAAD4mYiYe_SA3PO2LyGha77HZketm0NX8jjqAY=FTedaH6aRKA@mail.gmail.com>
On 21 September 2017 at 13:54, R0b0t1 <email@example.com> wrote:
> Hello Chris,
> On Wed, Sep 20, 2017 at 7:28 PM, Christian Gagneraud <firstname.lastname@example.org> 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
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).
>> 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