public inbox for gnu-gabi@sourceware.org
 help / color / mirror / Atom feed
From: Roland McGrath <roland@hack.frob.com>
To: hegdesmailbox@gmail.com
Cc: gnu-gabi@sourceware.org
Subject: Re: Deferred Binding of Function Pointers in SHLIB
Date: Fri, 01 Jan 2016 00:00:00 -0000	[thread overview]
Message-ID: <20160610213649.D8A7B2C39F7@topped-with-meat.com> (raw)
In-Reply-To: Suprateeka R Hegde's message of  Sunday, 5 June 2016 12:58:34 +0530 <36cd44e9-9f62-6784-17d8-22dd3c41e9f6@gmail.com>

I think you are confused about what you're observing.  Lazy binding
happens only for PLT entries, i.e. for direct function calls.  There
is never lazy binding for data initializers like your example uses.

Your use of -Wl,--unresolved-symbols=ignore-all means that the
non-shared case (libmain.c as executable) is simply mis-linked.  (If
you remove that switch, then the link will fail to complete and you
can never get a binary to run.)  After linking it's as if you'd
instead had "void (*func_p)(void) = 0;" in the source.  No kind of
binding at all happens at runtime.  The reason you saw the output
from printf is because there was no kind of symbol resolution
happening at all, and so nothing to fail at startup--your program
starts up fine, does what it does, and only crashes when it tries to
call the function pointer with value 0.

In the shared library case, foo is left undefined in the DSO.  The
same would happen without --unresolved-symbols=ignore-all.  (To see
link-time checking for apparent definedness of referenced symbols,
use -Wl,-z,defs.)  Because the reference to foo is in a data
initializer rather than a PLT entry (i.e., what you'd get if main
had the line "foo();"), it has to be resolved at startup time by the
dynamic linker before any of your code runs at all.  Since that
resolution fails, the dynamic linker bails out before even trying to
start your program.

  reply	other threads:[~2016-06-10 21:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  0:00 Suprateeka R Hegde
2016-01-01  0:00 ` Roland McGrath [this message]
2016-01-01  0:00   ` Suprateeka R Hegde
2016-01-01  0:00     ` Carlos O'Donell
2016-01-01  0:00       ` Suprateeka R Hegde

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=20160610213649.D8A7B2C39F7@topped-with-meat.com \
    --to=roland@hack.frob.com \
    --cc=gnu-gabi@sourceware.org \
    --cc=hegdesmailbox@gmail.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.
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).