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

    <tr>
        <th>Summary</th>
        <td>
            No DWARF information for external global variable in shared object
        </td>
    </tr>

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

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

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

<pre>
    Hello. I am compiling the following code:
```
extern int gdb_dlmopen_glob;

__attribute__((visibility ("default")))
int
inc (int n)
{
  int amount = gdb_dlmopen_glob;
  return n + amount;  /* bp.inc. */
}
```

With the following command line calls to clang:

```
clang -fdiagnostics-color=never -Wno-unknown-warning-option -fpic -c -g -o /home/gwenthekween/Documents/upstream-build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib-dep.c.o /home/gwenthekween/Documents/upstream-build/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/dlmopen-lib-dep.c
clang /home/gwenthekween/Documents/upstream-build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib.c.o /home/gwenthekween/Documents/upstream-build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib-dep.so -fdiagnostics-color=never -Wno-unknown-warning-option -shared -g -Wl,-soname,dlmopen-lib.1.so -Wl,-rpath,$ORIGIN -ldl -lm -o /home/gwenthekween/Documents/upstream-build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib.1.so
```

Looking at the debug information in the resulting shared object, there is no references to gdb_dlmopen_glob. I believe there should be a declaration of the external variable in the resulting output, which is in line with the debug information generated by GCC.

For convenience, here's a compiler explorer page that is setup to compile the code and compare the debug info from gcc and clang: https://godbolt.org/z/7x3r8TPEv
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVU1v4zYQ_TX0ZSBBpuzYPuiQ2FUatNgWiwVyNEhxJLGhOAI_7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