[BFD][PR21703]Override the new defined symbol with the old normal symbol when --allow-multiple-definition is provided
Renlin Li
renlin.li@foss.arm.com
Tue Oct 17 13:54:00 GMT 2017
Hi H.J,
Here is the updated patch. Two new test cases are added to test "-r" and "-shared" with
version symbol.
X86, arm, aarch64 are tested Okay with the change and test cases.
By the way, by this change, some warnings about changing symbol size and type are
eliminated. This is because the later defined symbol will be skipped instead of merging
with old definition.
Regards,
Renlin
bfd/ChangeLog:
2017-10-17 Renlin Li <renlin.li@arm.com>
* elflink.c (_bfd_elf_merge_symbol): Handle multiple definition case.
ld/ChangeLog:
2017-10-17 Renlin Li <renlin.li@arm.com>
* testsuite/ld-elf/elf.exp: Run new tests.
* testsuite/ld-elf/pr21703-1.s: New.
* testsuite/ld-elf/pr21703-2.s: New.
* testsuite/ld-elf/pr21703-3.s: New.
* testsuite/ld-elf/pr21703-4.s: New.
* testsuite/ld-elf/pr21703-r.sd: New.
* testsuite/ld-elf/pr21703-shared.sd: New.
* testsuite/ld-elf/pr21703.sd: New.
* testsuite/ld-elf/pr21703.ver: New.
On 12/10/17 21:52, H.J. Lu wrote:
> 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.
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tmp.diff
Type: text/x-patch
Size: 5057 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20171017/0a7a6724/attachment.bin>
More information about the Binutils
mailing list