This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: overriding fclose(2)
- From: vijay nag <vijunag at gmail dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Mon, 12 May 2014 15:05:51 +0530
- Subject: Re: overriding fclose(2)
- Authentication-results: sourceware.org; auth=none
- References: <CAKhyrx-5s7jNsYnAu1pJAe==pZsQVkWGKcH-L8yhQw1+Z5bwMw at mail dot gmail dot com> <20140512073711 dot GA10828 at domone dot podge>
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.