COFF: Check for symbols defined in discarded section
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 15 Mar 2019 14:19:01 +0000 (22:19 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 15 Mar 2019 14:19:20 +0000 (22:19 +0800)
For LTO, a symbol may defined in discarded section.  We should mark it
as undefined so that LTO plugin will make IR definition available.

PR ld/24267
* coffgen.c (_bfd_coff_section_already_linked): Skip discarded
section.
* cofflink.c (coff_link_add_symbols): Check for symbols defined
in discarded section.

bfd/ChangeLog
bfd/coffgen.c
bfd/cofflink.c

index b044fad..b019ca6 100644 (file)
@@ -1,3 +1,11 @@
+2019-03-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/24267
+       * coffgen.c (_bfd_coff_section_already_linked): Skip discarded
+       section.
+       * cofflink.c (coff_link_add_symbols): Check for symbols defined
+       in discarded section.
+
 2019-03-15  Alan Modra  <amodra@gmail.com>
 
        PR 24339
index 5db35c7..ccf4b43 100644 (file)
@@ -2652,6 +2652,9 @@ _bfd_coff_section_already_linked (bfd *abfd,
   struct bfd_section_already_linked_hash_entry *already_linked_list;
   struct coff_comdat_info *s_comdat;
 
+  if (sec->output_section == bfd_abs_section_ptr)
+    return FALSE;
+
   flags = sec->flags;
   if ((flags & SEC_LINK_ONCE) == 0)
     return FALSE;
index e4031b9..ac07d05 100644 (file)
@@ -310,7 +310,9 @@ coff_link_add_symbols (bfd *abfd,
            case COFF_SYMBOL_GLOBAL:
              flags = BSF_EXPORT | BSF_GLOBAL;
              section = coff_section_from_bfd_index (abfd, sym.n_scnum);
-             if (! obj_pe (abfd))
+             if (discarded_section (section))
+               section = bfd_und_section_ptr;
+             else if (! obj_pe (abfd))
                value -= section->vma;
              break;
 
@@ -327,6 +329,8 @@ coff_link_add_symbols (bfd *abfd,
            case COFF_SYMBOL_PE_SECTION:
              flags = BSF_SECTION_SYM | BSF_GLOBAL;
              section = coff_section_from_bfd_index (abfd, sym.n_scnum);
+             if (discarded_section (section))
+               section = bfd_und_section_ptr;
              break;
            }