This is the mail archive of the libc-help@sourceware.org mailing list for the glibc 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: overriding fclose(2)


On Mon, May 12, 2014 at 1:07 PM, OndÅej BÃlka <neleai@seznam.cz> wrote:
> On Mon, May 12, 2014 at 11:50:35AM +0530, vijay nag wrote:
>> Hello glibc,
>>
>> I'm trying to override/wrap fclose(2) libc call the following way.
>>
>> #include <stdio.h>
>>
>> #undef fclose
>> extern int _IO_new_fclose(_IO_FILE *fp);  /* defined in ./libio/iofclose.c */
>>
>> int __attribute__((weak)) fclose(FILE *stream)
>> {
>>      /* extra actions before libc fclose */
>>
>>      return _IO_new_fclose(stream);
>> }
>>

> You could get correct function from dynamic linker like by
> dlsym(RTLD_NEXT, "fclose").
This is a linker error during link time. How can I override fclose(3)
given its run time address ? dlsym will resolve the address via PLT(If
PIC enabled for library) and I don't want  to overwrite PLT entry for
fclose(3) either.  I used _IO_fclose(stream) instead of
_IO_new_fclose(stream) and it seems to be working fine now.


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