<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 - llvm-symbolizer shows incorrect source line info if --gc-sections used"
   href="https://bugs.llvm.org/show_bug.cgi?id=41124">41124</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-symbolizer shows incorrect source line info if --gc-sections used
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>llvm-symbolizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>a.v.lapshin@mail.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>llvm-symbolizer shows incorrect source line info if --gc-sections used:

$ cat not_used.cpp
void foo () {
    __asm__(".rept 3300000; nop; .endr");
}
$ cat main.cpp
int main(void) {
   return 0;
}
$ clang++ -gdwarf-5 -O not_used.cpp -c
$ clang++ -gdwarf-5 -O main.cpp -c
$ clang++ -gdwarf-5 -O not_used.o main.o -fuse-ld=lld -Wl,--gc-sections -o
res.out
$ llvm-symbolizer -obj=res.out 0x2010f0
main
/home/avl/bugs/gc_debuginfo/not_used.cpp:2:5

Note: llvm-symbolizer reported wrong source file - not_used.cpp !!!

The reason for the failure is that linker while removing not used
sections(-Wl,--gc-sections) keeps debug info for not used code :

llvm-dwarfdump -a res.out

0x0000000c: DW_TAG_compile_unit
              DW_AT_producer    ("clang version 9.0.0) 
              DW_AT_language    (DW_LANG_C_plus_plus)
              DW_AT_name        ("not_used.cpp")
              DW_AT_str_offsets_base    (0x00000008)
              DW_AT_stmt_list   (0x00000000)
              DW_AT_addr_base   (0x00000008)
              DW_AT_low_pc      (0x0000000000000000)   <<<<<<<<<<<<<<<<<<<<<<
              DW_AT_high_pc     (0x0000000000325aa1)   <<<<<<<<<<<<<<<<<<<<<<

0x0000003c: DW_TAG_compile_unit
              DW_AT_producer    ("clang version 9.0.0)
              DW_AT_language    (DW_LANG_C_plus_plus)
              DW_AT_name        ("main.cpp")
              DW_AT_str_offsets_base    (0x00000024)
              DW_AT_stmt_list   (0x00000075)
              DW_AT_addr_base   (0x00000018)
              DW_AT_low_pc      (0x00000000002010f0)   <<<<<<<<<<<<<<<<<<<<<<
              DW_AT_high_pc     (0x00000000002010f3)   <<<<<<<<<<<<<<<<<<<<<<

Note compilation units from debug info have overlapping address ranges. 

I have a fix for that problem.</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>