mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-07-20 22:14:23 +08:00
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. bfd/ PR ld/19579 * 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.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2016-03-04 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
PR ld/19579
|
||||||
|
* elflink.c (_bfd_elf_merge_symbol): Treat common symbol in
|
||||||
|
executable as definition if the new definition comes from a
|
||||||
|
shared library.
|
||||||
|
|
||||||
2016-03-02 Alan Modra <amodra@gmail.com>
|
2016-03-02 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
* Makefile.in: Regenerate.
|
* Makefile.in: Regenerate.
|
||||||
|
@ -1172,9 +1172,12 @@ _bfd_elf_merge_symbol (bfd *abfd,
|
|||||||
|
|
||||||
newdef = !bfd_is_und_section (sec) && !bfd_is_com_section (sec);
|
newdef = !bfd_is_und_section (sec) && !bfd_is_com_section (sec);
|
||||||
|
|
||||||
|
/* The old common symbol in executable is a definition if the new
|
||||||
|
definition comes from a shared library. */
|
||||||
olddef = (h->root.type != bfd_link_hash_undefined
|
olddef = (h->root.type != bfd_link_hash_undefined
|
||||||
&& h->root.type != bfd_link_hash_undefweak
|
&& h->root.type != bfd_link_hash_undefweak
|
||||||
&& h->root.type != bfd_link_hash_common);
|
&& (h->root.type != bfd_link_hash_common
|
||||||
|
|| (!olddyn && newdyn && bfd_link_executable (info))));
|
||||||
|
|
||||||
/* NEWFUNC and OLDFUNC indicate whether the new or old symbol,
|
/* NEWFUNC and OLDFUNC indicate whether the new or old symbol,
|
||||||
respectively, appear to be a function. */
|
respectively, appear to be a function. */
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
2016-03-04 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
2016-03-02 H.J. Lu <hongjiu.lu@intel.com>
|
2016-03-02 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* testsuite/ld-elf/pr19162.d: Skip hppa-*-*.
|
* testsuite/ld-elf/pr19162.d: Skip hppa-*-*.
|
||||||
|
15
ld/testsuite/ld-elf/pr19579a.c
Normal file
15
ld/testsuite/ld-elf/pr19579a.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int foo[1];
|
||||||
|
int bar[2];
|
||||||
|
|
||||||
|
extern int *foo_p (void);
|
||||||
|
extern int *bar_p (void);
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
if (foo[0] == 0 && foo == foo_p () && bar[0] == 0 && bar == bar_p ())
|
||||||
|
printf ("PASS\n");
|
||||||
|
return 0;
|
||||||
|
}
|
14
ld/testsuite/ld-elf/pr19579b.c
Normal file
14
ld/testsuite/ld-elf/pr19579b.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
int foo[2];
|
||||||
|
int bar[2] = { -1, -1 };
|
||||||
|
|
||||||
|
int *
|
||||||
|
foo_p (void)
|
||||||
|
{
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
int *
|
||||||
|
bar_p (void)
|
||||||
|
{
|
||||||
|
return bar;
|
||||||
|
}
|
@ -524,6 +524,21 @@ if { [istarget *-*-linux*]
|
|||||||
{} \
|
{} \
|
||||||
"libpr2404b.a" \
|
"libpr2404b.a" \
|
||||||
] \
|
] \
|
||||||
|
[list \
|
||||||
|
"Build pr19579a.o" \
|
||||||
|
"" "-fPIE" \
|
||||||
|
{pr19579a.c} \
|
||||||
|
{} \
|
||||||
|
"libpr19579a.a" \
|
||||||
|
] \
|
||||||
|
[list \
|
||||||
|
"Build libpr19579.so" \
|
||||||
|
"-shared" \
|
||||||
|
"-fPIC" \
|
||||||
|
{pr19579b.c} \
|
||||||
|
{} \
|
||||||
|
"libpr19579.so" \
|
||||||
|
] \
|
||||||
]
|
]
|
||||||
run_ld_link_exec_tests [] [list \
|
run_ld_link_exec_tests [] [list \
|
||||||
[list \
|
[list \
|
||||||
@ -580,6 +595,15 @@ if { [istarget *-*-linux*]
|
|||||||
"pass.out" \
|
"pass.out" \
|
||||||
"-O2 -fPIC -I../bfd" \
|
"-O2 -fPIC -I../bfd" \
|
||||||
] \
|
] \
|
||||||
|
[list \
|
||||||
|
"Run pr19579" \
|
||||||
|
"-pie -z text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
|
||||||
|
"" \
|
||||||
|
{dummy.c} \
|
||||||
|
"pr19579" \
|
||||||
|
"pass.out" \
|
||||||
|
"-fPIE" \
|
||||||
|
] \
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user