Open GwenTheKween opened 2 months ago
@llvm/issue-subscribers-debuginfo
Author: Guinevere Larsen (GwenTheKween)
As with calls to external functions, clang doesn't produce debug info for external entities (well, if we're producing call_site info we will produce function declarations, but not otherwise). This is an intentional choice to reduce debug info size.
It's probably not the most expensive debug info to emit, but generally clang assumes the whole program is built with debug info (as GCC and Clang both do in other ways, though arguably when clang is passed -fstandalone-debug
it could produce global variable declarations in the resulting DWARF)
@llvm/issue-subscribers-clang-codegen
Author: Guinevere Larsen (GwenTheKween)
Here's another example of this issue (slightly different, as it involves header files):
https://godbolt.org/z/5PdExcPKG
main.c
#include <stdio.h> #include "test.h"
int main (int argc, char** argv) { printf("foo = %d\n", g_foo); return 0; }
> lib.c
int g_foo = 15;
> test.h
extern int g_foo;
The primary difference in functionality is that gcc always records the declarations (for each compilation unit):
> main.c
0x00000077: DW_TAG_variable DW_AT_name ("g_foo") DW_AT_decl_file ("/app/test.h") DW_AT_decl_line (1) DW_AT_decl_column (12) DW_AT_type (0x00000058 "int") DW_AT_external (true) DW_AT_declaration (true)
> lib.c
0x00000101: DW_TAG_variable DW_AT_name ("g_foo") DW_AT_decl_file ("/app/test.h") DW_AT_decl_line (1) DW_AT_decl_column (12) DW_AT_type (0x0000010d "int") DW_AT_external (true) DW_AT_declaration (true)
0x00000114: DW_TAG_variable DW_AT_specification (0x00000101 "g_foo") DW_AT_decl_file ("/app/lib.c") DW_AT_decl_line (3) DW_AT_decl_column (5) DW_AT_location (DW_OP_addr 0x404018)
Whereas clang only records the definitions (only for the compilation unit where the definition resides):
0x00000094: DW_TAG_variable DW_AT_name ("g_foo") DW_AT_type (0x0000009f "int") DW_AT_external (true) DW_AT_decl_file ("/app/lib.c") DW_AT_decl_line (3) DW_AT_location (DW_OP_addrx 0x0)
Note that I did try out `-fstandalone-debug` as well (however, this did not produce the declaration info).
Having access to the declarations via the DWARF is rather handy for some debug scenarios (for example, it allows a more precise addr2line implementation which can show you both the definition and declaration point for a given address), so it would be nice to have this working in clang (even if it is something you have to enable via a flag, rather than being turned on by default).
Hello. I am compiling the following code:
With the following command line calls to clang:
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