This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [BFD][PR21703]Override the new defined symbol with the old normal symbol when --allow-multiple-definition is provided
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Renlin Li <renlin dot li at foss dot arm dot com>
- Cc: Alan Modra <amodra at gmail dot com>, "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Thu, 12 Oct 2017 13:52:04 -0700
- Subject: Re: [BFD][PR21703]Override the new defined symbol with the old normal symbol when --allow-multiple-definition is provided
- Authentication-results: sourceware.org; auth=none
- References: <595BF19A.6040000@foss.arm.com> <20170706054331.GD14520@bubble.grove.modra.org> <595FB9A0.9080508@foss.arm.com> <20170708021129.GL14520@bubble.grove.modra.org> <59650B69.3030806@foss.arm.com> <CAMe9rOoYeqs91xnwEj9tcDUZ_PUQGrmKtLb9kcO4gvp0R5t2_g@mail.gmail.com> <59662F7C.7030705@foss.arm.com> <59663072.8070900@foss.arm.com> <59DE41D9.1030505@foss.arm.com> <CAMe9rOogAHhA0oRTXaY9jq-CfXpLmEjPoCQ5W9vLHgFyT7dzsg@mail.gmail.com> <59DF6B01.7090004@foss.arm.com>
On 10/12/17, Renlin Li <renlin.li@foss.arm.com> wrote:
> Hi H.J.
>
> According to the logic, if there are versioned symbols with the same symbol
> name and
> version, e.g. sym_name@VERSION. It will treated as multiple definition of
> symbol.
> Until now, the behavior is the same as before. The linker will throw
> multiple definition
> error.
>
> With the change here, and with "--allow-multiple-definition" option
> provided,
> the first defined one will fully override a later definition.
>
> For default version symbol, it's slightly different.
> You can only declare one version of a symbol as the default in this manner;
> otherwise you
> would effectively have multiple definitions of the same symbol.
>
> For sym_name@@VERSION, two symbols will be added. One is sym_name@@VERSION.
> As above, you
> cannot define sym_name@@VERSION twice.
> what's more, _bfd_elf_add_default_symbol will add one "sym_name" indirect
> symbol. The
> check for this symbol definition is exclude explicitly in this patch as the
> condition
> indicates.
>
> pr21703-3.s
> .text
> .global foo
> .symver foo, foo@FOO
> .type foo, %function
> foo:
> .space 4
> .size foo, 4
>
> pr21703-4.s
> .text
> .global bar
> .symver bar, foo@FOO
> .type bar, %function
> bar:
> .space 16
> .size bar, 16
>
> With the following command line:
>
> as-new pr21703-3.o pr21703-3.s
> as-new pr21703-4.o pr21703-4.s
> ld-new -o pr21703 -z norelro pr21703-3.o pr21703-4.o
> --allow-multiple-definition
>
> without the patch,
> The symbol table of final object is:
> Num: Value Size Type Bind Vis Ndx Name
> 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
> 1: 0000000000400078 0 SECTION LOCAL DEFAULT 1
> 2: 0000000000600090 0 OBJECT LOCAL DEFAULT 1
> _GLOBAL_OFFSET_TABLE_
> 3: 0000000000400078 16 FUNC GLOBAL DEFAULT 1 foo@FOO
> 4: 000000000060008c 0 NOTYPE GLOBAL DEFAULT 1 __bss_start
> 5: 000000000060008c 0 NOTYPE GLOBAL DEFAULT 1 _edata
> 6: 0000000000600090 0 NOTYPE GLOBAL DEFAULT 1 _end
> 7: 000000000040007c 16 FUNC GLOBAL DEFAULT 1 bar
>
> foo@FOO is mapped to foo (the value) in pr21703-3.o with size from bar in
> pr21703-4.o.
> with the patch:
>
> Num: Value Size Type Bind Vis Ndx Name
> 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
> 1: 0000000000400078 0 SECTION LOCAL DEFAULT 1
> 2: 0000000000600090 0 OBJECT LOCAL DEFAULT 1
> _GLOBAL_OFFSET_TABLE_
> 3: 0000000000400078 4 FUNC GLOBAL DEFAULT 1 foo@FOO
> 4: 000000000060008c 0 NOTYPE GLOBAL DEFAULT 1 __bss_start
> 5: 000000000060008c 0 NOTYPE GLOBAL DEFAULT 1 _edata
> 6: 0000000000600090 0 NOTYPE GLOBAL DEFAULT 1 _end
> 7: 000000000040007c 16 FUNC GLOBAL DEFAULT 1 bar
>
> foo@FOO is fully mapped to foo.
>
> The above behavior is observed both on x64 and arm.
>
> Is this the kind of test you are suggesting?
Yes, test both foo@FOO1 and foo@@OFOO2 with -r and -shared.
--
H.J.