Warn when a script redefines a symbol
Note that we don't even warn if scripts adjust a symbol as in ld-elf/var1 and ld-scripts/pr14962. include/ * bfdlink.h (struct bfd_link_info): Add warn_multiple_definition. ld/ * ldexp.c (exp_fold_tree_1): Warn on script defining a symbol defined in an object file. * ldmain.c (multiple_definition): Heed info->warn_multiple_definition. * testsuite/ld-scripts/defined5.d: Expect a warning.
This commit is contained in:
parent
93993f6784
commit
89753bbf81
6 changed files with 32 additions and 11 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2021-02-21 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
|
* bfdlink.h (struct bfd_link_info): Add warn_multiple_definition.
|
||||||
|
|
||||||
2021-02-17 Nick Alcock <nick.alcock@oracle.com>
|
2021-02-17 Nick Alcock <nick.alcock@oracle.com>
|
||||||
|
|
||||||
* ctf-api.h (ctf_arc_lookup_symbol_name): New.
|
* ctf-api.h (ctf_arc_lookup_symbol_name): New.
|
||||||
|
|
|
@ -465,12 +465,16 @@ struct bfd_link_info
|
||||||
statics. */
|
statics. */
|
||||||
unsigned int task_link: 1;
|
unsigned int task_link: 1;
|
||||||
|
|
||||||
/* TRUE if ok to have multiple definition. */
|
/* TRUE if ok to have multiple definitions, without warning. */
|
||||||
unsigned int allow_multiple_definition: 1;
|
unsigned int allow_multiple_definition: 1;
|
||||||
|
|
||||||
/* TRUE if ok to have prohibit multiple definition of absolute symbols. */
|
/* TRUE if multiple definition of absolute symbols (eg. from -R) should
|
||||||
|
be reported. */
|
||||||
unsigned int prohibit_multiple_definition_absolute: 1;
|
unsigned int prohibit_multiple_definition_absolute: 1;
|
||||||
|
|
||||||
|
/* TRUE if multiple definitions should only warn. */
|
||||||
|
unsigned int warn_multiple_definition: 1;
|
||||||
|
|
||||||
/* TRUE if ok to have version with no definition. */
|
/* TRUE if ok to have version with no definition. */
|
||||||
unsigned int allow_undefined_version: 1;
|
unsigned int allow_undefined_version: 1;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
2021-02-21 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
|
* ldexp.c (exp_fold_tree_1): Warn on script defining a symbol
|
||||||
|
defined in an object file.
|
||||||
|
* ldmain.c (multiple_definition): Heed info->warn_multiple_definition.
|
||||||
|
* testsuite/ld-scripts/defined5.d: Expect a warning.
|
||||||
|
|
||||||
2021-02-19 Alan Modra <amodra@gmail.com>
|
2021-02-19 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
* testsuite/lib/ld-lib.exp: Whitespace.
|
* testsuite/lib/ld-lib.exp: Whitespace.
|
||||||
|
|
15
ld/ldexp.c
15
ld/ldexp.c
|
@ -1186,16 +1186,19 @@ exp_fold_tree_1 (etree_type *tree)
|
||||||
{
|
{
|
||||||
if (expld.result.section == NULL)
|
if (expld.result.section == NULL)
|
||||||
expld.result.section = expld.section;
|
expld.result.section = expld.section;
|
||||||
if (!update_definedness (tree->assign.dst, h) && 0)
|
if (!update_definedness (tree->assign.dst, h)
|
||||||
|
&& expld.assign_name != NULL)
|
||||||
{
|
{
|
||||||
/* Symbol was already defined. For now this error
|
/* Symbol was already defined, and the script isn't
|
||||||
is disabled because it causes failures in the ld
|
modifying the symbol value for some reason as in
|
||||||
testsuite: ld-elf/var1, ld-scripts/defined5, and
|
ld-elf/var1 and ld-scripts/pr14962.
|
||||||
ld-scripts/pr14962. Some of these no doubt
|
For now this is only a warning. */
|
||||||
reflect scripts used in the wild. */
|
unsigned int warn = link_info.warn_multiple_definition;
|
||||||
|
link_info.warn_multiple_definition = 1;
|
||||||
(*link_info.callbacks->multiple_definition)
|
(*link_info.callbacks->multiple_definition)
|
||||||
(&link_info, h, link_info.output_bfd,
|
(&link_info, h, link_info.output_bfd,
|
||||||
expld.result.section, expld.result.value);
|
expld.result.section, expld.result.value);
|
||||||
|
link_info.warn_multiple_definition = warn;
|
||||||
}
|
}
|
||||||
if (expld.phase == lang_fixed_phase_enum)
|
if (expld.phase == lang_fixed_phase_enum)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1074,7 +1074,9 @@ multiple_definition (struct bfd_link_info *info,
|
||||||
nval = oval;
|
nval = oval;
|
||||||
obfd = NULL;
|
obfd = NULL;
|
||||||
}
|
}
|
||||||
einfo (_("%X%P: %C: multiple definition of `%pT'"),
|
if (!info->warn_multiple_definition)
|
||||||
|
einfo ("%X");
|
||||||
|
einfo (_("%P: %C: multiple definition of `%pT'"),
|
||||||
nbfd, nsec, nval, name);
|
nbfd, nsec, nval, name);
|
||||||
if (obfd != NULL)
|
if (obfd != NULL)
|
||||||
einfo (_("; %D: first defined here"), obfd, osec, oval);
|
einfo (_("; %D: first defined here"), obfd, osec, oval);
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#ld: -Tdefined5.t
|
#ld: -Tdefined5.t
|
||||||
|
#warning: .*multiple definition of `defined'.*
|
||||||
#nm: -B
|
#nm: -B
|
||||||
#source: defined5.s
|
|
||||||
#xfail: [is_xcoff_format]
|
#xfail: [is_xcoff_format]
|
||||||
# xcoff outputs value of "defined" from the object file
|
# xcoff outputs value of "defined" from the object file
|
||||||
|
|
||||||
# Check that arithmetic on DEFINED works.
|
# Check that a script can override an object file symbol, if multiple
|
||||||
|
# definitions are allowed. See pr12356.
|
||||||
#...
|
#...
|
||||||
0+1000 D defined
|
0+1000 D defined
|
||||||
#pass
|
#pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue