From: Michael Matz <matz@suse.de>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: Martin McClure <martin.mcclure@gemtalksystems.com>,
Binutils <binutils@sourceware.org>
Subject: Re: Behavior change, PLT entries for R_X86_64_PLT32 relocations with undefined symbol
Date: Mon, 25 Mar 2019 19:28:00 -0000 [thread overview]
Message-ID: <alpine.LSU.2.21.1903251914400.20370@wotan.suse.de> (raw)
In-Reply-To: <CAMe9rOoypUmK-yS1wxfAEJQ8PBadYBGGVXoqkp1BnGrSQ27hPA@mail.gmail.com>
Hi,
On Tue, 19 Mar 2019, H.J. Lu wrote:
> > library.c
> >
> > int answer() {
> > return 42;
> > }
> >
> > ----
> >
> > executable.c
> >
> > #include <dlfcn.h>
> >
> > int answer();
> >
> > int main()
> > {
> > void *lib = dlopen("./library.so", RTLD_LAZY | RTLD_GLOBAL);
> > if (!lib) {
> > printf("dlopen failed");
> > }
> > printf("The answer is %d\n", answer());
> > return 0;
> > }
>
> Since answer is undefined, its behavior is undefined.
You're making this sound more clear-cut than it is, and I disagree with
it. Clearly, at runtime, the symbol 'answer' is resolvable just fine, the
loaded library contains a global definition. So with lazy resolution it'd
work. Note that the user explicitely requested the acceptance of
unresolved symbols with --unresolved-symbols=ignore-all (and did not
request non-lazy loading), so I would fully expect that unresolved global
symbols will be made dynamic symbols even for executables.
Martin: there is a work around for you for now: declare the functions in
question as weak in the objects making use of them:
------
int answer() __attribute__((weak));
...
printf("The answer is %d\n", answer());
...
------
You might or might not have to use the '-z dynamic-undefined-weak' link
editor option for this to work.
Ciao,
Michael.
next prev parent reply other threads:[~2019-03-25 19:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-19 2:07 Martin McClure
2019-03-19 6:30 ` H.J. Lu
2019-03-19 21:44 ` Martin McClure
2019-03-25 19:28 ` Michael Matz [this message]
2019-03-25 19:33 ` Martin McClure
2019-03-25 21:14 ` Martin McClure
2019-03-26 15:31 ` Michael Matz
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=alpine.LSU.2.21.1903251914400.20370@wotan.suse.de \
--to=matz@suse.de \
--cc=binutils@sourceware.org \
--cc=hjl.tools@gmail.com \
--cc=martin.mcclure@gemtalksystems.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).