This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: --as-needed change wrt undefined weak symbols
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Thu, 4 Apr 2013 16:11:54 -0700
- Subject: Re: --as-needed change wrt undefined weak symbols
- References: <20130114035805 dot GF3244 at bubble dot grove dot modra dot org> <CAMe9rOr9pmgn=ARZn_kEcJvAm4yHpyDmgxq=7_XHRVs7pzOopQ at mail dot gmail dot com> <20130115022340 dot GO3244 at bubble dot grove dot modra dot org> <CAMe9rOrOBPOHkQpPzYjC=OBgwq4bF29zDTTWidW20RJ5Y-F3tA at mail dot gmail dot com> <20130115052328 dot GQ3244 at bubble dot grove dot modra dot org> <CAMe9rOqcu7_-aAkkF=im56KsQ9Ypb6YkmmogcZDoswkNsaPPqg at mail dot gmail dot com> <20130318024130 dot GA18331 at bubble dot grove dot modra dot org> <CAMe9rOqy-OCgK44rPHK8BsiGpQcf1vzbXnsjcioNO7tFDSADTA at mail dot gmail dot com> <20130404223932 dot GH27605 at bubble dot grove dot modra dot org>
On Thu, Apr 4, 2013 at 3:39 PM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Apr 04, 2013 at 10:15:58AM -0700, H.J. Lu wrote:
>> On Sun, Mar 17, 2013 at 7:41 PM, Alan Modra <amodra@gmail.com> wrote:
>> > PR ld/12549
>> > elflink.c (elf_link_add_object_symbols): Exclude weak refs when
>> > considering whether an --as-needed library is needed.
>>
>> Just for the record, this patch may change the behavior of
>> the resulting executables for
>>
>> extern void bar () __attribute__((weak));
>>
>> if (bar)
>> bar ();
>>
>> if bar is defined in the DT_NEEDED library. Binutils 2.22
>> will resolve bar and add a DT_NEEDED entry. The new
>> linker will resolve bar to 0. We will see if it causes any
>> problems.
>
> Your testcase in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56431
> shows that gold resolves bar to zero, but on powerpc and powerpc64 ld
> keeps bar dynamic.
>
> Hmm, I see x86_64 ld resolves bar to 0. Isn't this just an x86_64
> backend ld bug?
For executable:
0000000000000000 <main>:
0: b8 00 00 00 00 mov $0x0,%eax 1: R_X86_64_32 bar
5: 48 85 c0 test %rax,%rax
8: 74 18 je 22 <main+0x22>
a: 48 83 ec 08 sub $0x8,%rsp
e: b8 00 00 00 00 mov $0x0,%eax
13: e8 00 00 00 00 callq 18 <main+0x18> 14: R_X86_64_PC32 bar-0x4
18: b8 00 00 00 00 mov $0x0,%eax
1d: 48 83 c4 08 add $0x8,%rsp
21: c3 retq
22: b8 00 00 00 00 mov $0x0,%eax
27: c3 retq
It is resolved to either 0, if it is undefined, or its PLT entry, if
it is defined. Once it is resolved to 0 at link-time, change to
defined at run-time won't affect executable. If it is resolved
to defined at link-time, change it to undefined at run-time
will lead to seg-fault.
If the executable is compiled with PIC/PIE, it works
fine.
--
H.J.