This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [BFD][PR21703]Override the new defined symbol with the old normal symbol when --allow-multiple-definition is provided


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]