Unused global UNDEFs can have side-effects in some circumstances so
the following patch avoids them by treating them the same as other
to be discarded DEFs - make them local.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk.

2020-08-03  Richard Biener  <rguent...@suse.de>

        PR lto/96385
        * simple-object-elf.c
        (simple_object_elf_copy_lto_debug_sections): Localize global
        UNDEFs and reuse the prevailing name.
---
 libiberty/simple-object-elf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index c62d5bba551..7c9d492f6a4 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -1467,6 +1467,11 @@ simple_object_elf_copy_lto_debug_sections 
(simple_object_read *sobj,
                       && st_shndx < shnum
                       && pfnret[st_shndx - 1] == -1)
                discard = 1;
+             /* We also need to remove global UNDEFs which can
+                cause link fails later.  */
+             else if (st_shndx == SHN_UNDEF
+                      && ELF_ST_BIND (*st_info) == STB_GLOBAL)
+               discard = 1;
 
              if (discard)
                {
-- 
2.26.2

Reply via email to