* ld --wrap and zcat
@ 2009-08-25 0:15 Shaun Jackman
2009-08-26 9:02 ` Nick Clifton
0 siblings, 1 reply; 3+ messages in thread
From: Shaun Jackman @ 2009-08-25 0:15 UTC (permalink / raw)
To: binutils
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?
Thanks,
Shaun
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ld --wrap and zcat
2009-08-25 0:15 ld --wrap and zcat Shaun Jackman
@ 2009-08-26 9:02 ` Nick Clifton
2009-08-26 19:35 ` Shaun Jackman
0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2009-08-26 9:02 UTC (permalink / raw)
To: Shaun Jackman; +Cc: binutils
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ld --wrap and zcat
2009-08-26 9:02 ` Nick Clifton
@ 2009-08-26 19:35 ` Shaun Jackman
0 siblings, 0 replies; 3+ messages in thread
From: Shaun Jackman @ 2009-08-26 19:35 UTC (permalink / raw)
To: Nick Clifton; +Cc: binutils
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-08-26 17:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-25 0:15 ld --wrap and zcat Shaun Jackman
2009-08-26 9:02 ` Nick Clifton
2009-08-26 19:35 ` Shaun Jackman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).