From 70993db314dc42194478d2c47b67d89f285c054a Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 7 May 2021 11:24:10 +0930 Subject: [PATCH] multiple definition warnings from script symbols In commit 89753bbf81 I enabled a warning for scripts redefining symbols. The idea was to not warn for symbols defined by shared libraries (the h->u.def.section->output_section != NULL test), but the test failed to take into account absolute symbols. Absolute symbols defined in shared libraries are currently indistinguishable from absolute symbols defined in relocatable objects, at least when only looking at struct bfd_link_hash_entry. So, don't warn for any absolute symbols. * ldexp.c (update_definedness): Don't return false for absolute symbols. * ldmain.c (multiple_definition): Print "warning: " in message when not a hard error. --- ld/ChangeLog | 7 +++++++ ld/ldexp.c | 1 + ld/ldmain.c | 10 ++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 80247c53682..fa367d3e69c 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2021-05-07 Alan Modra + + * ldexp.c (update_definedness): Don't return false for absolute + symbols. + * ldmain.c (multiple_definition): Print "warning: " in message + when not a hard error. + 2021-05-07 Alan Modra * testsuite/ld-elf/pr27825-1.d: Correct xfail. diff --git a/ld/ldexp.c b/ld/ldexp.c index 2efbec658be..02c76f8b33c 100644 --- a/ld/ldexp.c +++ b/ld/ldexp.c @@ -325,6 +325,7 @@ update_definedness (const char *name, struct bfd_link_hash_entry *h) defentry->by_object = 1; if (h->type == bfd_link_hash_defined && h->u.def.section->output_section != NULL + && !bfd_is_abs_section (h->u.def.section) && !h->linker_def) ret = false; } diff --git a/ld/ldmain.c b/ld/ldmain.c index be33b6943c6..42660eb9a3c 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -1073,10 +1073,12 @@ multiple_definition (struct bfd_link_info *info, nval = oval; obfd = NULL; } - if (!info->warn_multiple_definition) - einfo ("%X"); - einfo (_("%P: %C: multiple definition of `%pT'"), - nbfd, nsec, nval, name); + if (info->warn_multiple_definition) + einfo (_("%P: %C: warning: multiple definition of `%pT'"), + nbfd, nsec, nval, name); + else + einfo (_("%X%P: %C: multiple definition of `%pT'"), + nbfd, nsec, nval, name); if (obfd != NULL) einfo (_("; %D: first defined here"), obfd, osec, oval); einfo ("\n"); -- 2.30.2