From: vibi <vibi_sreenivasan@cms.com>
To: Steve Graegert <graegerts@gmail.com>
Cc: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: Re: threads and kernel
Date: Tue, 23 Oct 2007 12:40:33 +0530 [thread overview]
Message-ID: <1193123433.2731.29.camel@root> (raw)
In-Reply-To: <6a00c8d50710222358p42e5322btc955990e36580708@mail.gmail.com>
On Tue, 2007-10-23 at 08:58 +0200, Steve Graegert wrote:
> On 10/23/07, vibi <vibi_sreenivasan@cms.com> wrote:
> > On Tue, 2007-10-23 at 07:14 +0200, Steve Graegert wrote:
> > > On 10/23/07, vibi <vibi_sreenivasan@cms.com> wrote:
> > > > > "The init code used to set up the main program doesn't care about threads,
> > > >
> > > > because it assumes that they won't be used anyway."
> > > >
> > > > when is init code linked to the program ,during the compile time or
> > > > during the run time?
> > >
> > > It's being added by the linker at compile time.
> > >
> > > \Steve
> >
> > the application you gave earlier is linked without any knowledge of
> > multi-threading
> > so
> >
> > > cc test.c
> > > ./a.out
> >
> > would fail
> >
> > but you also said
> >
> > > cc test.c
> > > LD_PRELOAD=/usr/lib/libpthread.so ./a.out
> >
> > will not fail
> >
> > in both the cases same init code is added at compile time and you also
> > said that init code determines whether a program is multi-threaded.
> >
> > So i am a little bit confused because how at run time the init code is
> > changed.
>
> Linkage takes place at compile time and run time. When starting a
> program its execution environment is setup properly including loading
> and linking in all libraries (including those specified on the command
> line with LD_PRELOAD and at compile time).
>
> The LD_PRELOAD environment variable allows you to load additional
> shared libraries at program startup. The loader ld.so.1, loads the
> specified shared libraries as if the program had been linked
> explicitly with the shared libraries in LD_PRELOAD before any other
> dependents of the program. At startup time, the loader implicitly
> loads one or more libraries, if found, specified in the LD_PRELOAD
> environment. It uses the same load order and symbol resolution order
> as if the library had been explicitly linked as the first library in
> the link line when building the executable.
>
> As a result, at startup the program is multi-threaded when
> LD_PRELOAD=/usr/lib/libpthread.so is specified, but if libpthread is
> neither specified at compile time nor __before__ startup of the main
> program (i.e. LD_PRELOAD) the execution environment is unchanged (not
> threaded at all).
>
> This is possible because the init code of the libraries is executed at
> before control is transfered to the main program, thus the program is
> multi-threaded although libpthread has no been specified at compile
> time and no thread-related function calls are made during runtime.
>
> \Steve
so init code is just like a stub which is resolved while setting up the
execution environment of the program,ie linkage resolution at load time.
am i understanding correctly.
thanks very much for your help
regards
vibi sreenivasan
>
> --
>
> Steve Grägert
> DigitalEther.de
>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2007-10-23 7:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-21 13:21 threads and kernel Shriramana Sharma
2007-10-21 16:26 ` Irfan Habib
2007-10-21 17:23 ` Steve Graegert
2007-10-22 6:50 ` Benoit Fouet
2007-10-22 13:01 ` Steve Graegert
2007-10-22 13:27 ` Benoit Fouet
2007-10-22 13:31 ` Steve Graegert
2007-10-22 13:38 ` Benoit Fouet
2007-10-22 14:20 ` Steve Graegert
2007-10-22 14:34 ` Benoit Fouet
2007-10-23 4:32 ` vibi
2007-10-23 5:14 ` Steve Graegert
2007-10-23 5:53 ` vibi
2007-10-23 6:58 ` Steve Graegert
2007-10-23 7:10 ` vibi [this message]
2007-10-23 7:30 ` Steve Graegert
2007-10-22 7:55 ` Shriramana Sharma
2007-10-22 13:41 ` Steve Graegert
2007-10-22 17:18 ` Glynn Clements
2007-10-21 17:36 ` Glynn Clements
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=1193123433.2731.29.camel@root \
--to=vibi_sreenivasan@cms.com \
--cc=graegerts@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/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.
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).