Bug 28009 - mark .gnu.debuglto_.debug_* as SHT_MIPS_DWARF
Summary: mark .gnu.debuglto_.debug_* as SHT_MIPS_DWARF
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.37
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-24 08:10 UTC by YunQiang Su
Modified: 2021-06-30 16:17 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description YunQiang Su 2021-06-24 08:10:26 UTC
See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99488


When LTO is enabled, debug sections have names like 
   .gnu.debuglto_.debug_*
and which type is marked as PROGBITS.

While normal debug info for MIPS is marked as SHT_MIPS_DWARF.
So linker fails to merge the two sections, which make the output has
2 section with the same name:

root@mipsel:/build/innoextract/innoextract-1.8# readelf -Wa debian/innoextract/usr/bin/innoextract | grep debug_info
  [32] .debug_info       MIPS_DWARF      00000000 09a8c0 1b77ef 00      0   0  1
  [40] .debug_info       PROGBITS        00000000 4ff4b4 50302b 00      0   0  1

Let's just mark .gnu.debuglto_.debug_* as SHT_MIPS_DWARF.

Index: binutils-2.36.50.20210618/bfd/elfxx-mips.c
===================================================================
--- binutils-2.36.50.20210618.orig/bfd/elfxx-mips.c
+++ binutils-2.36.50.20210618/bfd/elfxx-mips.c
@@ -7448,7 +7448,9 @@ _bfd_mips_elf_section_from_shdr (bfd *ab
       break;
     case SHT_MIPS_DWARF:
       if (! startswith (name, ".debug_")
-         && ! startswith (name, ".zdebug_"))
+         && ! startswith (name, ".gnu.debuglto_.debug_")
+         && ! startswith (name, ".zdebug_")
+         && ! startswith (name, ".gnu.debuglto_.zdebug_"))
        return false;
       break;
     case SHT_MIPS_SYMBOL_LIB:
@@ -7669,7 +7671,9 @@ _bfd_mips_elf_fake_sections (bfd *abfd,
       hdr->sh_entsize = sizeof (Elf_External_ABIFlags_v0);
     }
   else if (startswith (name, ".debug_")
-          || startswith (name, ".zdebug_"))
+          || startswith (name, ".gnu.debuglto_.debug_")
+          || startswith (name, ".zdebug_")
+          || startswith (name, ".gnu.debuglto_.zdebug_"))
     {
       hdr->sh_type = SHT_MIPS_DWARF;
Comment 1 Sourceware Commits 2021-06-30 16:17:02 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9a39f7389d8971dc754e45a73128616a5346008c

commit 9a39f7389d8971dc754e45a73128616a5346008c
Author: YunQiang Su <yunqiang.su@cipunited.com>
Date:   Wed Jun 30 17:16:22 2021 +0100

    Mark .gnu.debuglto_.debug_* as SHT_MIPS_DWARF
    
            PR mips/28009
            * bfd/elfxx-mips.c (_bfd_mips_elf_section_from_shdr,
            _bfd_mips_elf_fake_sections): Mark LTO debug info as
            SHT_MIPS_DWARF.
Comment 2 Nick Clifton 2021-06-30 16:17:54 UTC
Hi YunQiang,

  Thanks for the bug report and patch.  

  I have now applied your patch.

Cheers
  Nick