[lld] [llvm] [DebugInfo][DwarfDebug] Move emission of globals from beginModule() to endModule() (5/7) (PR #184219)
Vladislav Dzhidzhoev via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 12:15:15 PST 2026
dzhidzhoev wrote:
Built clang on Linux in RelWithDebInfo mode. Comparison results for bin/clang and bin/llc
```
$ bloaty ../on-llvm1/bin/clang -- ../on-llvm0/bin/clang
FILE SIZE VM SIZE
-------------- --------------
+0.1% +77.1Ki [ = ] 0 .debug_line
+0.0% +1 [ = ] 0 .debug_line_str
-0.2% -60.2Ki [ = ] 0 .debug_rnglists
-0.1% -152Ki [ = ] 0 .debug_loclists
-4.8% -384Ki [ = ] 0 .debug_abbrev
-0.1% -728Ki [ = ] 0 .debug_info
-0.1% -1.22Mi [ = ] 0 TOTAL
$ bloaty ../on-llvm1/bin/llc -- ../on-llvm0/bin/llc
FILE SIZE VM SIZE
-------------- --------------
+0.0% +472 [ = ] 0 .debug_line
-0.2% -34.2Ki [ = ] 0 .debug_rnglists
-0.2% -84.8Ki [ = ] 0 .debug_loclists
-5.1% -243Ki [ = ] 0 .debug_abbrev
-0.2% -576Ki [ = ] 0 .debug_info
-0.1% -938Ki [ = ] 0 TOTAL
```
Also, built clang for macOS in RelWithDebInfo, and got more interesting result.
For bin/llc, the total size of debug info sections has decreased:
```
$ bloaty ../on-llvm1/./tools/llc/llc.dSYM/Contents/Resources/DWARF/llc -- ../on-llvm0/tools/llc/llc.dSYM/Contents/Resources/DWARF/llc
FILE SIZE VM SIZE
-------------- --------------
+0.2% +58.4Ki +0.2% +58.4Ki __DWARF,__debug_names
+0.0% +6.10Ki +0.0% +6.10Ki __DWARF,__debug_line
-0.0% -5 -0.0% -5 __DWARF,__debug_rnglists
-0.1% -9 -0.1% -9 __DWARF,__debug_abbrev
[DEL] -2 -9.6% -222 [__DWARF]
-0.5% -1.69Mi -0.5% -1.69Mi __DWARF,__debug_info
-0.3% -1.63Mi -0.3% -1.63Mi TOTAL
```
Whereas the total size of debug info of clang binary has increased:
```
bloaty ../on-llvm1/./tools/clang/tools/driver/clang-23.dSYM/Contents/Resources/DWARF/clang-23 -- ../on-llvm0/./tools/clang/tools/driver/clang-23.dSYM/Contents/Resources/DWARF/clang-23
FILE SIZE VM SIZE
-------------- --------------
+0.5% +3.86Mi +0.5% +3.86Mi __DWARF,__debug_info
+0.4% +358Ki +0.4% +358Ki __DWARF,__debug_names
+0.0% +20.9Ki +0.0% +20.9Ki __DWARF,__debug_line
+0.4% +78 +0.4% +78 __DWARF,__debug_abbrev
+0.0% +41 +0.0% +41 __DWARF,__debug_str
+0.0% +8 +0.0% +8 __DWARF,__debug_rnglists
[ = ] 0 -72.0% -2.53Ki [__DWARF]
+0.3% +4.23Mi +0.3% +4.23Mi TOTAL
```
After looking at some object files where the increase is the highest, I think that we get this increase because:
1. With this patch, the generation of declarations for many functions happens at later stages of the DwarfDebug pipeline, compared to the current mainline. Function definitions are emitted earlier.
2. Therefore, more linkageNames and less unique identifiers are emitted into first 256/65536 entries of debug_str_offsets. Some frequent identifiers have to be encoded with DW_form_strx2 instead of DW_form_strx1, or with DW_form_strx3 instead of DW_form_strx2 => debug_info section size grows.
3. In debug_abbrev, we already have a lot of abbreviations for declaration DW_TAG_subprograms (as we produce different combinations of attributes).
DW_TAG_subprogram has (usually) two string attributes, DW_AT_name and DW_AT_linkage_name. Where we needed to have 2/3/4 abbreviations for them (if some DW_AT_names or DW_AT_linkage_names needed DW_form_strx1/2), we now need to have more abbreviations to account for DW_TAG_subprograms DW_AT_names or DW_AT_linkage_names encoded with DW_form_strx3 => the number of combinations for DW_AT_name+DW_AT_linkage_name forms grows => debug_abbrev section size grows.
For example, before the patch, in the file `X86PreTileConfig.cpp.o`, string like "operator++", "operator--", "operator+", "operator->" are emitted within first 255 entries of debug_str_offset:
```
0x0000013c: 0000071b "operator->"
0x00000140: 00000726 "operator++"
0x00000144: 00000731 "operator--"
0x00000148: 0000073c "operator+"
```
whereas after the patch, they are emitted at higher indices:
```
0x00000434: 00001f83 "operator->"
0x0000043c: 00001fbe "operator++"
0x00000448: 00002029 "operator--"
0x00000454: 00002095 "operator+"
```
Grep over debug_info section dump tells that "operator++" is used 300+ times in this file. So, with the patch, subprogram DIEs for operator++ need at least 300 bytes more only for "operator++"s in debug_info section:
```
$ bloaty ../on-llvm1/lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86PreTileConfig.cpp.o -- ../on-llvm0/lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86PreTileConfig.cpp.o
FILE SIZE VM SIZE
-------------- --------------
+1.9% +24.9Ki +1.9% +24.9Ki ,__debug_info
+0.0% +12 +0.0% +12 ,__debug_line
+100% +5 +11% +1 []
-0.0% -4 [ = ] 0 [Unmapped]
-4.7% -5 -4.7% -5 ,__debug_loclists
-4.2% -5 -4.2% -5 ,__debug_rnglists
-2.0% -266 -2.0% -266 ,__debug_abbrev
+0.4% +24.6Ki +0.4% +24.6Ki TOTAL
```
To verify my thoughts, I tried to build clang with `dwarf-inlined-strings` option, but compilation on macOS in RelWithDebInfo crashed :(. So, I built clang with `-gdwarf=4`, so that debug_str_offset is not used, and string references are encoded with DW_FORM_strp, and got the following result:
```
bloaty ../on-llvm1/./tools/clang/tools/driver/clang-23.dSYM/Contents/Resources/DWARF/clang-23 -- ../on-llvm0/./tools/clang/tools/driver/clang-23.dSYM/Contents/Resources/DWARF/clang-23
FILE SIZE VM SIZE
-------------- --------------
+0.1% +504Ki +0.1% +504Ki __DWARF,__debug_info
+0.1% +58.8Ki +0.1% +58.8Ki __DWARF,__debug_line
[ = ] 0 +145% +2.36Ki [__DWARF]
+2.0% +288 +2.0% +288 __DWARF,__debug_abbrev
+0.0% +43 +0.0% +43 __DWARF,__debug_str
-0.0% -1.91Ki -0.0% -1.91Ki __DWARF,__apple_types
+0.1% +561Ki +0.1% +564Ki TOTAL
```
I think this measurement supports my assumption about why we get debug_info size increase for clang binary.
But currently I don't have specific ideas how to improve the situation, as DwarfStringPool doesn't allow to directly control which indices in debug_str_offsets strings are assigned with.
https://github.com/llvm/llvm-project/pull/184219
More information about the llvm-commits
mailing list