<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58641>58641</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            llvm-symbolizer fails to find the line info when there are garbage DWARF units.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          liudangyi
      </td>
    </tr>
</table>

<pre>
    Ways to reproduce:

```
$ cat test.cc
#include <vector>

static std::vector<int> unused;  // This ensures the compile unit contains DW_AT_ranges.

int main() {
    return 0;
}

$ cat lib.cc 
#include <vector>

static std::vector<int> unused;  // This ensures the compile unit contains DW_AT_ranges.

// A large function.
void f() {
    asm(".fill 0x2000, 1, 0xCC");
}

$ clang++ test.cc lib.cc -o test -Wl,--gc-sections -g

$ nm test | grep main
00000000000011f0 T main

$ llvm-symbolizer --obj test 0x11f0
main
??:0:0
```

If we remove `-Wl,--gc-sections` then it works. The problem is because function `f` is garbage collected, but its DWARF info is kept and in `llvm-dwarfdump test`, there are

```
0x000010a0: DW_TAG_compile_unit
              DW_AT_producer    ("Debian clang version 14.0.6-2")
              DW_AT_language    (DW_LANG_C_plus_plus_14)
              DW_AT_name        ("lib.cc")
...
              DW_AT_ranges      (indexed (0x0) rangelist = 0x00000062
...
                 [0x0000000000000000, 0x0000000000002006)
...
```

So `llvm-symbolizer` incorrectly find the wrong compile unit and the wrong line table.

Clang version: 

```
Debian clang version 14.0.6-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVcmO4zYQ_Rr5UpBAUbZsH3xw2_EgQJBD0kAfDUqiZM5QpMHFS74-RUpeetLjcwg2G2JVPdbyqlzp5rr6YFcLToPhR6MbX_OkWCdkm5DbWZJxD590CjVz4Lh1WV3fLguhaukbDkmx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