<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Corrupt debug info when using lld with gcc 9.1"
   href="https://bugs.llvm.org/show_bug.cgi?id=42401">42401</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Corrupt debug info when using lld with gcc 9.1
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sichert@in.tum.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have the following program:

foo.cpp:

int foo() {
    return 1;
}


main.cpp:

int main() {
    return 0;
}



If I compile it with gcc 9.1 like this:

gcc -g -fuse-ld=lld -o main foo.cpp main.cpp

I get corrupted debug info. gdb says:

Reading symbols from main...
Dwarf Error: wrong version in compilation unit header (is 1024, should be 2, 3,
4 or 5) [in module <...>/main]
(No debugging symbols found in main)


This is the output of "readelf --debug-dump=info main":

Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0x53 (32-bit)
   Version:       4
   Abbrev Offset: 0x0
   Pointer Size:  8
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_producer    : (indirect string, offset: 0x31): GNU C++14 9.1.0
-mtune=generic -march=x86-64 -g -fuse-ld=lld
    <10>   DW_AT_language    : 4        (C++)
    <11>   DW_AT_name        : (indirect string, offset: 0x6e): foo.cpp
    <15>   DW_AT_comp_dir    : (indirect string, offset: 0x0): <...>
    <19>   DW_AT_low_pc      : 0x10f9
    <21>   DW_AT_high_pc     : 0xb
    <29>   DW_AT_stmt_list   : 0x0
 <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
    <2e>   DW_AT_external    : 1
    <2e>   DW_AT_name        : foo
    <32>   DW_AT_decl_file   : 1
    <33>   DW_AT_decl_line   : 1
    <34>   DW_AT_decl_column : 5
    <35>   DW_AT_linkage_name: (indirect string, offset: 0x24): _Z3foov
    <39>   DW_AT_type        : <0x4f>
    <3d>   DW_AT_low_pc      : 0x10f9
    <45>   DW_AT_high_pc     : 0xb
    <4d>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
    <4f>   DW_AT_GNU_all_call_sites: 1
 <1><4f>: Abbrev Number: 3 (DW_TAG_base_type)
    <50>   DW_AT_byte_size   : 4
    <51>   DW_AT_encoding    : 5        (signed)
    <52>   DW_AT_name        : int
 <1><56>: Abbrev Number: 0
readelf: Warning: Invalid pointer size (59) in compunit header, using 4 instead
  Compilation Unit @ offset 0x57:
   Length:        0x4f00 (32-bit)
   Version:       1024
   Abbrev Offset: 0x8000000
   Pointer Size:  4
readelf: Warning: Debug info is corrupted, .debug_info header at 0x57 has
length 4f00



This problem does not occur when using ld or gold. Also, it doesn't happen when
using gcc < 9.1 or clang.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>