This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ld --wrap and zcat
- From: Shaun Jackman <sjackman at bcgsc dot ca>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Wed, 26 Aug 2009 10:22:41 -0700
- Subject: Re: ld --wrap and zcat
- References: <4A931CE1.8090307@bcgsc.ca> <4A94E33C.7010107@redhat.com>
Neat, I didn't think of that. Thanks, Nick.
The solution I settled didn't require LD_PRELOAD, which I'm happy
about, but did use -ldl and dlsym. I created a function `fopen' in my
application, which -- and I don't entirely understand why this is --
libstdc++ does call. Within my fopen, I used dlsym(RTLD_NEXT, "fopen")
to call the fopen of libc.
Cheers,
Shaun
Nick Clifton wrote:
Hi Shaun,
fstream::open in libstdc++ calls fopen in libc. I'd like to use ld
--wrap to hook the fopen call to call popen to decompress a .gz file
using zcat. Is this possible with ld --wrap? From my experimentation, it
seems not. Is this possible using LD_PRELOAD and dlsym?
Do you have access to the linker command line used to build your
executable ? If so you can just create your own custom library that
contains its own implementation of fopen (which calls popen as you
desire) and then insert the name of this library in between the
libstdc++-v3 library and the libc library on the linker command line.
Cheers
Nick