GNU Binutils with patches for OS216
修訂 | 1134e6ce012575e6d0e99933d0d29cc7978af9af (tree) |
---|---|
時間 | 2016-03-09 22:59:31 |
作者 | H.J. Lu <hjl.tools@gmai...> |
Commiter | H.J. Lu |
Treat common symbol in executable as definition
Common symbol in executable is a definition, which overrides definition
from shared objects. When linker sees a new definition from a shared
object, the new dynamic definition should be overridden by the previous
common symbol in executable.
Backport from master
bfd/
PR ld/19579
* elflink.c (_bfd_elf_merge_symbol): Group common symbol checking
together.
* elflink.c (_bfd_elf_merge_symbol): Treat common symbol in
executable as definition if the new definition comes from a
shared library.
ld/
PR ld/19579
* testsuite/ld-elf/pr19579a.c: New file.
* testsuite/ld-elf/pr19579b.c: Likewise.
* testsuite/ld-elf/shared.exp: Run PR ld/19579 test.
@@ -1,3 +1,18 @@ | ||
1 | +2016-03-09 H.J. Lu <hongjiu.lu@intel.com> | |
2 | + | |
3 | + PR ld/19579 | |
4 | + Backport from master | |
5 | + 2016-03-08 H.J. Lu <hongjiu.lu@intel.com> | |
6 | + | |
7 | + * elflink.c (_bfd_elf_merge_symbol): Group common symbol checking | |
8 | + together. | |
9 | + | |
10 | + 2016-03-04 H.J. Lu <hongjiu.lu@intel.com> | |
11 | + | |
12 | + * elflink.c (_bfd_elf_merge_symbol): Treat common symbol in | |
13 | + executable as definition if the new definition comes from a | |
14 | + shared library. | |
15 | + | |
1 | 16 | 2016-03-09 Nick Clifton <nickc@redhat.com> |
2 | 17 | Alan Modra <amodra@gmail.com> |
3 | 18 |
@@ -1485,13 +1485,16 @@ _bfd_elf_merge_symbol (bfd *abfd, | ||
1485 | 1485 | represent variables; this can cause confusion in principle, but |
1486 | 1486 | any such confusion would seem to indicate an erroneous program or |
1487 | 1487 | shared library. We also permit a common symbol in a regular |
1488 | - object to override a weak symbol in a shared object. */ | |
1488 | + object to override a weak symbol in a shared object. A common | |
1489 | + symbol in executable also overrides a symbol in a shared object. */ | |
1489 | 1490 | |
1490 | 1491 | if (newdyn |
1491 | 1492 | && newdef |
1492 | 1493 | && (olddef |
1493 | 1494 | || (h->root.type == bfd_link_hash_common |
1494 | - && (newweak || newfunc)))) | |
1495 | + && (newweak | |
1496 | + || newfunc | |
1497 | + || (!olddyn && bfd_link_executable (info)))))) | |
1495 | 1498 | { |
1496 | 1499 | *override = TRUE; |
1497 | 1500 | newdef = FALSE; |
@@ -1,3 +1,13 @@ | ||
1 | +2016-03-09 H.J. Lu <hongjiu.lu@intel.com> | |
2 | + | |
3 | + Backport from master | |
4 | + 2016-03-04 H.J. Lu <hongjiu.lu@intel.com> | |
5 | + | |
6 | + PR ld/19579 | |
7 | + * testsuite/ld-elf/pr19579a.c: New file. | |
8 | + * testsuite/ld-elf/pr19579b.c: Likewise. | |
9 | + * testsuite/ld-elf/shared.exp: Run PR ld/19579 test. | |
10 | + | |
1 | 11 | 2016-03-04 H.J. Lu <hongjiu.lu@intel.com> |
2 | 12 | |
3 | 13 | Backport from master |
@@ -0,0 +1,15 @@ | ||
1 | +#include <stdio.h> | |
2 | + | |
3 | +int foo[1]; | |
4 | +int bar[2]; | |
5 | + | |
6 | +extern int *foo_p (void); | |
7 | +extern int *bar_p (void); | |
8 | + | |
9 | +int | |
10 | +main () | |
11 | +{ | |
12 | + if (foo[0] == 0 && foo == foo_p () && bar[0] == 0 && bar == bar_p ()) | |
13 | + printf ("PASS\n"); | |
14 | + return 0; | |
15 | +} |
@@ -0,0 +1,14 @@ | ||
1 | +int foo[2]; | |
2 | +int bar[2] = { -1, -1 }; | |
3 | + | |
4 | +int * | |
5 | +foo_p (void) | |
6 | +{ | |
7 | + return foo; | |
8 | +} | |
9 | + | |
10 | +int * | |
11 | +bar_p (void) | |
12 | +{ | |
13 | + return bar; | |
14 | +} |
@@ -524,6 +524,21 @@ if { [istarget *-*-linux*] | ||
524 | 524 | {} \ |
525 | 525 | "libpr2404b.a" \ |
526 | 526 | ] \ |
527 | + [list \ | |
528 | + "Build pr19579a.o" \ | |
529 | + "" "-fPIE" \ | |
530 | + {pr19579a.c} \ | |
531 | + {} \ | |
532 | + "libpr19579a.a" \ | |
533 | + ] \ | |
534 | + [list \ | |
535 | + "Build libpr19579.so" \ | |
536 | + "-shared" \ | |
537 | + "-fPIC" \ | |
538 | + {pr19579b.c} \ | |
539 | + {} \ | |
540 | + "libpr19579.so" \ | |
541 | + ] \ | |
527 | 542 | ] |
528 | 543 | run_ld_link_exec_tests [] [list \ |
529 | 544 | [list \ |
@@ -580,5 +595,14 @@ if { [istarget *-*-linux*] | ||
580 | 595 | "pass.out" \ |
581 | 596 | "-O2 -fPIC -I../bfd" \ |
582 | 597 | ] \ |
598 | + [list \ | |
599 | + "Run pr19579" \ | |
600 | + "-pie -z text tmpdir/pr19579a.o tmpdir/libpr19579.so" \ | |
601 | + "" \ | |
602 | + {dummy.c} \ | |
603 | + "pr19579" \ | |
604 | + "pass.out" \ | |
605 | + "-fPIE" \ | |
606 | + ] \ | |
583 | 607 | ] |
584 | 608 | } |