public inbox for gnu-gabi@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: gnu-gabi@sourceware.org
Subject: Re: Specify how undefined weak symbol should be resolved in executable
Date: Fri, 01 Jan 2016 00:00:00 -0000	[thread overview]
Message-ID: <CAMe9rOoJkeBS1_=DaEUY8Ts+=b7A=83_0wgVfCa3g+dd3me4wg@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOqQ-RUhBo3NATttc1VEGhtx4D0Z9aRWfw5APfDVuBPqWQ@mail.gmail.com>

On Mon, Feb 22, 2016 at 8:25 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> Currently when building executable, undefined weak symbol is resolved
> differently, depending on if the relocatable input is compiled with PIC or
> not:
>
> hjl@gnu-tools-1 weak-1]$ cat x.c
> extern void __attribute__ ((weak)) fun (void);
> int main (void)
> {
>   if (&fun != 0)
>     fun ();
>   return 0;
> }
> [hjl@gnu-tools-1 weak-1]$ make
> gcc -B./ -O2 -o x x.c
> gcc -B./ -O2 -o y x.c -fPIC
> readelf -r x
>
> Relocation section '.rela.dyn' at offset 0x328 contains 1 entries:
>   Offset          Info           Type           Sym. Value    Sym. Name + Addend
> 000000600870  000200000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
>
> Relocation section '.rela.plt' at offset 0x340 contains 1 entries:
>   Offset          Info           Type           Sym. Value    Sym. Name + Addend
> 000000600890  000100000007 R_X86_64_JUMP_SLO 0000000000000000
> __libc_start_main@GLIBC_2.2.5 + 0
>
> There is no dynamic relocation against fun, whose value is
> resolved to zero at link-time.
>
> readelf -r y
>
> Relocation section '.rela.dyn' at offset 0x348 contains 2 entries:
>   Offset          Info           Type           Sym. Value    Sym. Name + Addend
> 0000006008a0  000100000006 R_X86_64_GLOB_DAT 0000000000000000 fun + 0
> 0000006008a8  000300000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
>
> Relocation section '.rela.plt' at offset 0x378 contains 1 entries:
>   Offset          Info           Type           Sym. Value    Sym. Name + Addend
> 0000006008c8  000200000007 R_X86_64_JUMP_SLO 0000000000000000
> __libc_start_main@GLIBC_2.2.5 + 0
> [hjl@gnu-tools-1 weak-1]$
>
> There is dynamic relocation against fun, whose value is resolved
> at runt-time. We should make it consistent, regardless if input
> relocatable file is compiled with PIC or not.
>
> I raised the issue at gABI:
>
> https://groups.google.com/d/msg/generic-abi/Ckq19PfLxyk/eCbXPofkAQAJ
>
> But if gABI change is incompatible with other OSes, we need to
> specify it in GNU ABI.

We should extend GNU ABI to:

When creating executable, if dynamic relocation is available at
run-time, the link
editor should generate dynamic relocations against unresolved weak symbols so
that their values will be resolved at run-time.

-- 
H.J.

  reply	other threads:[~2016-02-22 17:45 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  0:00 H.J. Lu
2016-01-01  0:00 ` H.J. Lu [this message]
2016-01-01  0:00   ` H.J. Lu
2016-01-01  0:00   ` Michael Matz
2016-01-01  0:00     ` H.J. Lu
2016-01-01  0:00       ` Michael Matz
2016-01-01  0:00         ` H.J. Lu
2016-01-01  0:00           ` H.J. Lu
2016-01-01  0:00             ` H.J. Lu
2016-01-01  0:00               ` H.J. Lu
2016-01-01  0:00             ` Alan Modra
2016-01-01  0:00               ` H.J. Lu
2016-01-01  0:00                 ` Michael Matz
2016-01-01  0:00                   ` H.J. Lu
2016-01-01  0:00                     ` Michael Matz
2016-01-01  0:00                       ` Szabolcs Nagy
2016-01-01  0:00                         ` Michael Matz
2016-01-01  0:00               ` H.J. Lu
2016-01-01  0:00                 ` Michael Matz
2016-01-01  0:00                   ` H.J. Lu
2016-01-01  0:00                     ` Michael Matz
2016-01-01  0:00                       ` H.J. Lu
2016-01-01  0:00                         ` H.J. Lu
2016-01-01  0:00                         ` Alan Modra
2016-01-01  0:00                           ` H.J. Lu
2016-01-01  0:00                             ` Alan Modra
2016-01-01  0:00                               ` Carlos O'Donell
2016-01-01  0:00                                 ` H.J. Lu
2016-01-01  0:00                                   ` Michael Matz
2016-01-01  0:00                                     ` H.J. Lu
2016-01-01  0:00                                       ` Michael Matz
2016-01-01  0:00                                         ` H.J. Lu
2016-01-01  0:00                                           ` Michael Matz
2016-01-01  0:00                                             ` H.J. Lu

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='CAMe9rOoJkeBS1_=DaEUY8Ts+=b7A=83_0wgVfCa3g+dd3me4wg@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=gnu-gabi@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).