aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-02-20 15:45:44 +1030
committerAlan Modra <amodra@gmail.com>2021-02-21 14:28:16 +1030
commit89753bbf8102edc2aa4262a4d43f1a71a10e34f3 (patch)
tree3afa35082bf7898409aa8e8ff507e8431b32c99d /ld
parent93993f67849234cff651542c3d4d9f0f3d2fa651 (diff)
downloadgdb-89753bbf8102edc2aa4262a4d43f1a71a10e34f3.zip
gdb-89753bbf8102edc2aa4262a4d43f1a71a10e34f3.tar.gz
gdb-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')
-rw-r--r--ld/ChangeLog7
-rw-r--r--ld/ldexp.c15
-rw-r--r--ld/ldmain.c4
-rw-r--r--ld/testsuite/ld-scripts/defined5.d5
4 files changed, 22 insertions, 9 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 9d16c30..2339a40 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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>
* testsuite/lib/ld-lib.exp: Whitespace.
diff --git a/ld/ldexp.c b/ld/ldexp.c
index 084bb17..0167845 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -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)
{
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 863df02..5c88ee7 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -1074,7 +1074,9 @@ multiple_definition (struct bfd_link_info *info,
nval = oval;
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);
if (obfd != NULL)
einfo (_("; %D: first defined here"), obfd, osec, oval);
diff --git a/ld/testsuite/ld-scripts/defined5.d b/ld/testsuite/ld-scripts/defined5.d
index 2530c0e..7aa680b 100644
--- a/ld/testsuite/ld-scripts/defined5.d
+++ b/ld/testsuite/ld-scripts/defined5.d
@@ -1,10 +1,11 @@
#ld: -Tdefined5.t
+#warning: .*multiple definition of `defined'.*
#nm: -B
-#source: defined5.s
#xfail: [is_xcoff_format]
# 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
#pass