From 1f98a7df0a1637a1565e336bd3cd31b8fe030f48 Mon Sep 17 00:00:00 2001 From: hjl Date: Wed, 30 Jun 2004 16:19:16 +0000 Subject: [PATCH] bfd/ 2004-06-30 H.J. Lu PR 233 * elflink.c (elf_link_input_bfd): Issue an error for non-debug local references to discarded sections and report their locations. ld/testsuite/ 2004-06-30 H.J. Lu PR 233 * ld-discard/extern.d: Updated. * ld-discard/start.d: Likewise. * ld-discard/static.d: Likewise. --- bfd/ChangeLog | 7 +++++++ bfd/elflink.c | 34 +++++++++++++++++++--------------- ld/testsuite/ChangeLog | 7 +++++++ ld/testsuite/ld-discard/extern.d | 2 +- ld/testsuite/ld-discard/start.d | 2 +- ld/testsuite/ld-discard/static.d | 2 +- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 20f0c227ac..464821dfec 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2004-06-30 H.J. Lu + + PR 233 + * elflink.c (elf_link_input_bfd): Issue an error for non-debug + local references to discarded sections and report their + locations. + 2004-06-30 Alan Modra * elflink.c (elf_section_ignore_discarded_relocs): Don't test diff --git a/bfd/elflink.c b/bfd/elflink.c index 354cfbbe5a..e682758728 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -6581,8 +6581,7 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd) { BFD_ASSERT (r_symndx != 0); /* Try to preserve debug information. */ - if ((o->flags & SEC_DEBUGGING) != 0 - && sec->kept_section != NULL + if (sec->kept_section != NULL && sec->size == sec->kept_section->size) h->root.u.def.section = sec->kept_section; @@ -6590,13 +6589,20 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd) memset (rel, 0, sizeof (*rel)); } else - finfo->info->callbacks->error_handler - (LD_DEFINITION_IN_DISCARDED_SECTION, - _("%T: discarded in section `%s' from %s\n"), - h->root.root.string, - h->root.root.string, - h->root.u.def.section->name, - bfd_archive_filename (h->root.u.def.section->owner)); + { + char *r_name + = xstrdup (bfd_archive_filename (o->owner)); + finfo->info->callbacks->error_handler + (LD_DEFINITION_IN_DISCARDED_SECTION, + _("`%T' referenced in section `%s' from %s: discarded in section `%s' from %s\n"), + h->root.root.string, + h->root.root.string, + o->name, r_name, + h->root.u.def.section->name, + bfd_archive_filename (h->root.u.def.section->owner)); + if (r_name) + free (r_name); + } } } else @@ -6605,13 +6611,11 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd) if (sec != NULL && elf_discarded_section (sec)) { - if ((o->flags & SEC_DEBUGGING) != 0 - || (sec->flags & SEC_LINK_ONCE) != 0) + if ((o->flags & SEC_DEBUGGING) != 0) { BFD_ASSERT (r_symndx != 0); /* Try to preserve debug information. */ - if ((o->flags & SEC_DEBUGGING) != 0 - && sec->kept_section != NULL + if (sec->kept_section != NULL && sec->size == sec->kept_section->size) finfo->sections[r_symndx] = sec->kept_section; @@ -6633,8 +6637,8 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd) buf = (char *) "local symbol"; finfo->info->callbacks->error_handler (LD_DEFINITION_IN_DISCARDED_SECTION, - _("%T: discarded in section `%s' from %s\n"), - buf, buf, sec->name, + _("`%T' referenced in section `%s': discarded in section `%s' from %s\n"), + buf, buf, o->name, sec->name, bfd_archive_filename (input_bfd)); if (ok != -1) free (buf); diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index e129ab527f..3dacd1c710 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2004-06-30 H.J. Lu + + PR 233 + * ld-discard/extern.d: Updated. + * ld-discard/start.d: Likewise. + * ld-discard/static.d: Likewise. + 2004-06-29 J"orn Rennecke Actually add these files: diff --git a/ld/testsuite/ld-discard/extern.d b/ld/testsuite/ld-discard/extern.d index 10fa0f756f..df4c7d1cea 100644 --- a/ld/testsuite/ld-discard/extern.d +++ b/ld/testsuite/ld-discard/extern.d @@ -1,3 +1,3 @@ #source: extern.s #ld: -T discard.ld -#error: data: discarded in section `\.data\.exit' from tmpdir/dump0.o +#error: `data' referenced in section `\.text' from tmpdir/dump0.o: discarded in section `\.data\.exit' from tmpdir/dump0.o diff --git a/ld/testsuite/ld-discard/start.d b/ld/testsuite/ld-discard/start.d index b8f46ae786..f9885d40f7 100644 --- a/ld/testsuite/ld-discard/start.d +++ b/ld/testsuite/ld-discard/start.d @@ -1,4 +1,4 @@ #source: start.s #source: exit.s #ld: -T discard.ld -#error: data: discarded in section `\.data\.exit' from tmpdir/dump1.o +#error: `data' referenced in section `\.text' from tmpdir/dump0.o: discarded in section `\.data\.exit' from tmpdir/dump1.o diff --git a/ld/testsuite/ld-discard/static.d b/ld/testsuite/ld-discard/static.d index 78b89b0313..1aa44cdd1e 100644 --- a/ld/testsuite/ld-discard/static.d +++ b/ld/testsuite/ld-discard/static.d @@ -1,3 +1,3 @@ #source: static.s #ld: -T discard.ld -#error: local symbol 0: discarded in section `\.data\.exit' from tmpdir/dump0.o +#error: `local symbol 0' referenced in section `\.text': discarded in section `\.data\.exit' from tmpdir/dump0.o -- 2.11.0