From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Making a shared library that intercepts call to main work with musl compiled binary
Date: Mon, 6 Jul 2015 15:06:51 -0400 [thread overview]
Message-ID: <20150706190651.GY1173@brightrain.aerifal.cx> (raw)
In-Reply-To: <alpine.LNX.2.11.1507062147180.2485@monopod.intra.ispras.ru>
On Mon, Jul 06, 2015 at 10:00:41PM +0300, Alexander Monakov wrote:
> On Mon, 6 Jul 2015, Rich Felker wrote:
> > On Mon, Jul 06, 2015 at 01:00:52PM -0400, Riyad Parvez wrote:
> > > Hi All,
> > >
> > > I've shared library [1] which intercepts loading of a binary and does some
> > > pre-processing with the command-line arguments via "LD_PRELOAD" technique.
> > > The shared library works fine with glibc compiled binary i.e., it can
> > > intercept the call to main and does some preprocessing. But it can't
> > > intercept call to "main" in musl-compiled binary. I've compiled my binary
> > > in static mode with musl "CC=/musl-gcc -static". How can I make the shared
> > > library work with musl-compiled binary?
> > >
> > > Thanks
> > > Riyad
> > >
> > > [1]: https://github.com/dslab-epfl/s2e/blob/master/guest/init_env/init_env.c
> >
> > I haven't read this code in detail, so I don't have any advice on
> > whether there are other problems, but the basic issue seems to be that
> > you're static linking. The same would happen if you use glibc and
> > static link. If you want the ability to use LD_PRELOAD you need to
> > link dynamically.
>
> Furthermore, even with dynamic linking you cannot interpose 'main' in the
> executable via LD_PRELOAD. Even more baffling is that the linked code
> interposes __libc_start_main; I'm lost for words that it happens to work with
> glibc.
Presumably it interposes __libc_start_main because it can't interpose
main. As far as I can tell the only reason it does this is to inject
fake argv. I'm skeptical as to whether it works correctly.
> I think a cleaner solution can be obtained by converting __s2e_init_env in the
> linked code to a constructor that examines environment variables, and moving
> the command line processing to an separate wrapper executable.
Certainly.
Rich
next prev parent reply other threads:[~2015-07-06 19:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-06 17:00 Riyad Parvez
2015-07-06 17:32 ` Rich Felker
2015-07-06 19:00 ` Alexander Monakov
2015-07-06 19:06 ` Rich Felker [this message]
2015-07-06 20:34 ` Alexander Monakov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150706190651.GY1173@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).