diff options
author | Alan Modra <amodra@gmail.com> | 2021-02-20 15:45:44 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-02-21 14:28:16 +1030 |
commit | 89753bbf8102edc2aa4262a4d43f1a71a10e34f3 (patch) | |
tree | 3afa35082bf7898409aa8e8ff507e8431b32c99d /ld/ldexp.c | |
parent | 93993f67849234cff651542c3d4d9f0f3d2fa651 (diff) | |
download | binutils-89753bbf8102edc2aa4262a4d43f1a71a10e34f3.zip binutils-89753bbf8102edc2aa4262a4d43f1a71a10e34f3.tar.gz binutils-89753bbf8102edc2aa4262a4d43f1a71a10e34f3.tar.bz2 |
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.
Diffstat (limited to 'ld/ldexp.c')
-rw-r--r-- | ld/ldexp.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -1186,16 +1186,19 @@ exp_fold_tree_1 (etree_type *tree) { if (expld.result.section == NULL) 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 - is disabled because it causes failures in the ld - testsuite: ld-elf/var1, ld-scripts/defined5, and - ld-scripts/pr14962. Some of these no doubt - reflect scripts used in the wild. */ + /* Symbol was already defined, and the script isn't + modifying the symbol value for some reason as in + ld-elf/var1 and ld-scripts/pr14962. + For now this is only a warning. */ + unsigned int warn = link_info.warn_multiple_definition; + link_info.warn_multiple_definition = 1; (*link_info.callbacks->multiple_definition) (&link_info, h, link_info.output_bfd, expld.result.section, expld.result.value); + link_info.warn_multiple_definition = warn; } if (expld.phase == lang_fixed_phase_enum) { |