Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release build generates ~30% fewer debug symbol entries than debug build #6992

Open
JoshuaBatty opened this issue Mar 5, 2025 · 0 comments
Labels
compiler:debug-info Debug Info support in the compiler compiler General compiler. Should eventually become more specific as the issue is triaged team:compiler Compiler Team

Comments

@JoshuaBatty
Copy link
Member

JoshuaBatty commented Mar 5, 2025

Description

When comparing debug symbols generated with -g in debug vs release mode, the release build produces significantly fewer symbol entries (~30% less). Both builds include all DWARF debug sections, but release mode maps fewer positions in the source code.

Expected Behaviour

If -g is specified, debug symbols should be complete in both debug and release builds, or the difference in coverage should be documented.

Steps to Reproduce

  1. Create a simple Sway program:
script;
use std::logging::log;
fn factorial(n: u64) -> u64 {
    let mut result = 1;
    let mut counter = 0;
    while counter < n {
        counter = counter + 1;
        result = result * counter;
    }
    return result;
}
fn main() {
    log::<u64>(factorial(5)); // 120
}
  1. Build with debug symbols in debug mode:
forc build -g symbols_debug.json
  1. Build with debug symbols in release mode:
forc build --release -g symbols_release.json
  1. Compare the resulting JSON files

Observations

Debug map has 39 entries, release map has 28 entries
Debug has 33 entries mapping to main.sw, release has 23

We can also notive a difference if we generate the dwarf files and inspect them using llvm-dwarfdump

DWARF line table differences:

  • Debug build has 38 address-to-line mappings
  • Release build has 29 address-to-line mappings

Full DWARF dump comparison provided below:

# Debug build
❯ llvm-dwarfdump --debug-line out/debug/debug_symbols.obj
out/debug/debug_symbls.obj:     file format elf64-x86-64

.debug_line contents:
debug_line[0x00000000]
Line table prologue:
    total_length: 0x0000000000000188
          format: DWARF64
         version: 5
    address_size: 8
 seg_select_size: 0
 prologue_length: 0x0000000000000124
 min_inst_length: 1
max_ops_per_inst: 1
 default_is_stmt: 1
       line_base: -5
      line_range: 14
     opcode_base: 13
standard_opcode_lengths[DW_LNS_copy] = 0
standard_opcode_lengths[DW_LNS_advance_pc] = 1
standard_opcode_lengths[DW_LNS_advance_line] = 1
standard_opcode_lengths[DW_LNS_set_file] = 1
standard_opcode_lengths[DW_LNS_set_column] = 1
standard_opcode_lengths[DW_LNS_negate_stmt] = 0
standard_opcode_lengths[DW_LNS_set_basic_block] = 0
standard_opcode_lengths[DW_LNS_const_add_pc] = 0
standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1
standard_opcode_lengths[DW_LNS_set_prologue_end] = 0
standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0
standard_opcode_lengths[DW_LNS_set_isa] = 1
include_directories[  0] = "/Users/josh/Documents/rust/fuel/test_projects/dbg_example"
include_directories[  1] = "/Users/josh/.forc/git/checkouts/std-77214b14e13f9b04/986aee2c1e34c9cd958c81e7fd6b84638b26619b/sway-lib-core/src"
include_directories[  2] = "/Users/josh/Documents/rust/fuel/test_projects/dbg_example/src"
file_names[  0]:
           name: "src/main.sw"
      dir_index: 0
file_names[  1]:
           name: "codec.sw"
      dir_index: 1
file_names[  2]:
           name: "main.sw"
      dir_index: 2

Address            Line   Column File   ISA Discriminator Flags
------------------ ------ ------ ------ --- ------------- -------------
0x0000000000000000      1      0      1   0             0  is_stmt
0x0000000000000019   2507      5      1   0             0  is_stmt
0x000000000000002d     15      1      2   0             0  is_stmt
0x000000000000002e     15      1      2   0             0  is_stmt
0x0000000000000032     16     16      2   0             0  is_stmt
0x0000000000000033     16     16      2   0             0  is_stmt
0x0000000000000034     16     16      2   0             0  is_stmt
0x0000000000000036     16     16      2   0             0  is_stmt
0x0000000000000038     16     16      2   0             0  is_stmt
0x0000000000000045     16      5      2   0             0  is_stmt
0x0000000000000047     16      5      2   0             0  is_stmt
0x0000000000000048     16      5      2   0             0  is_stmt
0x0000000000000049     16      5      2   0             0  is_stmt
0x000000000000004b     16      5      2   0             0  is_stmt
0x000000000000004c     16      5      2   0             0  is_stmt
0x0000000000000050     16      5      2   0             0  is_stmt
0x0000000000000052     16      5      2   0             0  is_stmt
0x0000000000000055     16      5      2   0             0  is_stmt
0x0000000000000056     16      5      2   0             0  is_stmt
0x0000000000000057     16      5      2   0             0  is_stmt
0x0000000000000059     16      5      2   0             0  is_stmt
0x000000000000005a     16      5      2   0             0  is_stmt
0x000000000000005b     16      5      2   0             0  is_stmt
0x000000000000005c     16      5      2   0             0  is_stmt
0x000000000000005d     16      5      2   0             0  is_stmt
0x0000000000000060     16      5      2   0             0  is_stmt
0x0000000000000064     16      5      2   0             0  is_stmt
0x0000000000000066     16      5      2   0             0  is_stmt
0x000000000000007d     16     16      2   0             0  is_stmt
0x000000000000007e     16     16      2   0             0  is_stmt
0x000000000000007f     16     16      2   0             0  is_stmt
0x0000000000000080     16     16      2   0             0  is_stmt
0x0000000000000081     16     16      2   0             0  is_stmt
0x0000000000000082     16     16      2   0             0  is_stmt
0x0000000000000083     16     16      2   0             0  is_stmt
0x000000000000008a     10      5      1   0             0  is_stmt
0x000000000000008b     10      5      1   0             0  is_stmt
0x0000000000000099     11      9      1   0             0  is_stmt
0x00000000000000a2     29      5      1   0             0  is_stmt
0x00000000000000a4     29      5      1   0             0  is_stmt end_sequence

# Release build
❯ llvm-dwarfdump --debug-line out/release/debug_symbols.obj
out/release/debug_symbls.obj:   file format elf64-x86-64
.debug_line contents:
debug_line[0x00000000]
Line table prologue:
    total_length: 0x0000000000000175
          format: DWARF64
         version: 5
    address_size: 8
 seg_select_size: 0
 prologue_length: 0x0000000000000124
 min_inst_length: 1
max_ops_per_inst: 1
 default_is_stmt: 1
       line_base: -5
      line_range: 14
     opcode_base: 13
standard_opcode_lengths[DW_LNS_copy] = 0
standard_opcode_lengths[DW_LNS_advance_pc] = 1
standard_opcode_lengths[DW_LNS_advance_line] = 1
standard_opcode_lengths[DW_LNS_set_file] = 1
standard_opcode_lengths[DW_LNS_set_column] = 1
standard_opcode_lengths[DW_LNS_negate_stmt] = 0
standard_opcode_lengths[DW_LNS_set_basic_block] = 0
standard_opcode_lengths[DW_LNS_const_add_pc] = 0
standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1
standard_opcode_lengths[DW_LNS_set_prologue_end] = 0
standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0
standard_opcode_lengths[DW_LNS_set_isa] = 1
include_directories[  0] = "/Users/josh/Documents/rust/fuel/test_projects/dbg_example"
include_directories[  1] = "/Users/josh/Documents/rust/fuel/test_projects/dbg_example/src"
include_directories[  2] = "/Users/josh/.forc/git/checkouts/std-77214b14e13f9b04/986aee2c1e34c9cd958c81e7fd6b84638b26619b/sway-lib-core/src"
file_names[  0]:
           name: "src/main.sw"
      dir_index: 0
file_names[  1]:
           name: "main.sw"
      dir_index: 1
file_names[  2]:
           name: "codec.sw"
      dir_index: 2
Address            Line   Column File   ISA Discriminator Flags
------------------ ------ ------ ------ --- ------------- -------------
0x0000000000000000      1      0      1   0             0  is_stmt
0x0000000000000029     15      1      1   0             0  is_stmt
0x000000000000002a     15      1      1   0             0  is_stmt
0x0000000000000031     16     16      1   0             0  is_stmt
0x000000000000003f     16      5      1   0             0  is_stmt
0x0000000000000041     16      5      1   0             0  is_stmt
0x0000000000000042     16      5      1   0             0  is_stmt
0x0000000000000043     16      5      1   0             0  is_stmt
0x0000000000000045     16      5      1   0             0  is_stmt
0x0000000000000046     16      5      1   0             0  is_stmt
0x000000000000004a     16      5      1   0             0  is_stmt
0x000000000000004c     16      5      1   0             0  is_stmt
0x000000000000004f     16      5      1   0             0  is_stmt
0x0000000000000050     16      5      1   0             0  is_stmt
0x0000000000000051     16      5      1   0             0  is_stmt
0x0000000000000052     16      5      1   0             0  is_stmt
0x0000000000000053     16      5      1   0             0  is_stmt
0x0000000000000054     16      5      1   0             0  is_stmt
0x0000000000000055     16      5      1   0             0  is_stmt
0x0000000000000058     16      5      1   0             0  is_stmt
0x000000000000005a     16      5      1   0             0  is_stmt
0x000000000000005c     16      5      1   0             0  is_stmt
0x0000000000000071     16     16      1   0             0  is_stmt
0x0000000000000072     16     16      1   0             0  is_stmt
0x0000000000000079     10      5      2   0             0  is_stmt
0x000000000000007a     10      5      2   0             0  is_stmt
0x0000000000000088     11      9      2   0             0  is_stmt
0x0000000000000091     29      5      2   0             0  is_stmt
0x0000000000000093     29      5      2   0             0  is_stmt end_sequence
@JoshuaBatty JoshuaBatty added compiler General compiler. Should eventually become more specific as the issue is triaged compiler:debug-info Debug Info support in the compiler team:compiler Compiler Team labels Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:debug-info Debug Info support in the compiler compiler General compiler. Should eventually become more specific as the issue is triaged team:compiler Compiler Team
Projects
None yet
Development

No branches or pull requests

1 participant