Consider below testcases,
$cat shlib.c
int var;
int test()
{ return var++; }
$cat test.c
extern int test();
extern int var;
int main()
{ var++; printf("%d\n",test()); }
$clang -fpic shlib.c -g -shared -o libshared.so
$clang -L`pwd` test.c -lshared -g
$export LD_LIBRARY_PATH=pwd
$ gdb a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x400718: file test.c, line 6.
(gdb) pt var
type = <data variable, no debug info>
As per above debugging ,for global extern variable var type info is missing because variable DebugInfo is not there in executable.
This is the case when sharelib is not yet loaded.
LLVM is not adding debuginfo for externs with -g because this debug_info may increase final binary size.
And Even it fails to do so with -fstandalone-debug option.
As part of this fix
We emit debug info for declaration of global extern variable
with option -fstandalone-debug along with -g.
nit: